优化(订单服务): 固定提交按钮并完善未成年提示滚动

This commit is contained in:
2026-11-27 16:20:12 +08:00
parent c3a13c5f36
commit 77371728c0
4 changed files with 352 additions and 5 deletions
@@ -130,3 +130,210 @@ test(
}
},
)
test(
'子分类无配置时继承父级,发布子配置后待补资料工单切换到子配置',
{ skip: !TEST_DATABASE_URL ? '未设置 ORDER_SERVICE_CONTENT_TEST_DATABASE_URL' : false },
async () => {
process.env.DATABASE_URL = TEST_DATABASE_URL
process.env.ENABLE_DEV_MOCK = '1'
const { closeDb, query, withTransaction } = await import('../../db/client.js')
const { publishAdminOrderServiceProfile, saveAdminOrderServiceProfile } =
await import('./order-service-profile-service.js')
const { createAdminMockWorkOrder } = await import('./admin-mock-work-order-service.js')
const { getOrderServiceByPlatformOrderId } = await import('./order-service-public-service.js')
const suffix = `${Date.now()}-${Math.floor(Math.random() * 1_000_000)}`
let parentCategoryId = 0
let childCategoryId = 0
let workOrderId = 0
try {
const parent = await query<{ id: number }>(
`INSERT INTO work_categories
(category_key, name, sort_order, status, created_at, updated_at)
VALUES ($1, $2, 1, 'active', NOW(), NOW())
RETURNING id`,
[`order-service-parent-test-${suffix}`, '订单服务父级测试分类'],
)
parentCategoryId = Number(parent.rows[0]?.id || 0)
const child = await query<{ id: number }>(
`INSERT INTO work_categories
(category_key, name, parent_id, sort_order, status, created_at, updated_at)
VALUES ($1, $2, $3, 1, 'active', NOW(), NOW())
RETURNING id`,
[`order-service-child-test-${suffix}`, '订单服务子级测试分类', parentCategoryId],
)
childCategoryId = Number(child.rows[0]?.id || 0)
const savedParent = await saveAdminOrderServiceProfile({
categoryId: parentCategoryId,
name: '父级订单服务',
title: '父级资料',
fields: [
{
key: 'gameId',
label: '游戏编号',
type: 'text',
validation: 'none',
required: true,
placeholder: '',
helpText: '',
options: [],
sortOrder: 10,
},
],
screenshots: { enabled: false, required: false, minCount: 0, maxCount: 5 },
autoPublish: { enabled: false, requireVoucherConsume: true, retryMax: 3 },
ageGate: {
enabled: true,
title: '父级未成年提示',
warningText: '父级警示',
content: '父级正文',
importantNotice: '父级重要提示',
adultButtonText: '我已成年',
minorButtonText: '我是未成年',
minorBlockedTitle: '不能购买',
minorBlockedContent: '流程停止',
},
bottomGuideImage: {
enabled: true,
image: {
objectKey: 'order-service-guide/integration/parent.png',
contentType: 'image/png',
},
},
})
await publishAdminOrderServiceProfile(Number(savedParent.profile?.id || 0))
const platformOrderId = `IT-ORDER-SERVICE-INHERIT-${suffix}`
const created = await createAdminMockWorkOrder({
platformOrderId,
productName: `订单服务继承测试-${suffix}`,
sellerId: '订单服务集成测试店铺',
categoryId: childCategoryId,
rewardAmount: 10,
paymentAmount: 12,
materialComplete: false,
})
workOrderId = Number(created.order.workOrderId)
assert.ok(workOrderId > 0)
const inheritedOrder = await getOrderServiceByPlatformOrderId(platformOrderId)
const inheritedItem = inheritedOrder.items[0]
assert.equal(inheritedItem?.ageGate?.title, '父级未成年提示')
assert.equal(
inheritedItem?.bottomGuideImage?.image.objectKey,
'order-service-guide/integration/parent.png',
)
const inheritedSnapshot = await query<{
service_profile_snapshot_json: {
inherited: boolean
sourceCategoryId: number
config: { ageGate: { title: string } }
}
}>(
`SELECT service_profile_snapshot_json
FROM work_orders
WHERE id = $1`,
[workOrderId],
)
assert.equal(inheritedSnapshot.rows[0]?.service_profile_snapshot_json.inherited, true)
assert.equal(
inheritedSnapshot.rows[0]?.service_profile_snapshot_json.sourceCategoryId,
parentCategoryId,
)
const savedChild = await saveAdminOrderServiceProfile({
categoryId: childCategoryId,
name: '子级订单服务',
title: '子级资料',
fields: [
{
key: 'gameId',
label: '游戏编号',
type: 'text',
validation: 'none',
required: true,
placeholder: '',
helpText: '',
options: [],
sortOrder: 10,
},
],
screenshots: { enabled: false, required: false, minCount: 0, maxCount: 5 },
autoPublish: { enabled: false, requireVoucherConsume: true, retryMax: 3 },
ageGate: {
enabled: true,
title: '子级未成年提示',
warningText: '子级警示',
content: '子级正文',
importantNotice: '子级重要提示',
adultButtonText: '我已成年',
minorButtonText: '我是未成年',
minorBlockedTitle: '不能购买',
minorBlockedContent: '流程停止',
},
bottomGuideImage: {
enabled: true,
image: {
objectKey: 'order-service-guide/integration/child.png',
contentType: 'image/png',
},
},
})
await publishAdminOrderServiceProfile(Number(savedChild.profile?.id || 0))
const overriddenOrder = await getOrderServiceByPlatformOrderId(platformOrderId)
const overriddenItem = overriddenOrder.items[0]
assert.equal(overriddenItem?.ageGate?.title, '子级未成年提示')
assert.equal(
overriddenItem?.bottomGuideImage?.image.objectKey,
'order-service-guide/integration/child.png',
)
const overriddenSnapshot = await query<{
service_profile_snapshot_json: {
inherited: boolean
sourceCategoryId: number
config: { ageGate: { title: string } }
}
}>(
`SELECT service_profile_snapshot_json
FROM work_orders
WHERE id = $1`,
[workOrderId],
)
assert.equal(overriddenSnapshot.rows[0]?.service_profile_snapshot_json.inherited, false)
assert.equal(
overriddenSnapshot.rows[0]?.service_profile_snapshot_json.sourceCategoryId,
childCategoryId,
)
assert.equal(
overriddenSnapshot.rows[0]?.service_profile_snapshot_json.config.ageGate.title,
'子级未成年提示',
)
} finally {
if (workOrderId > 0) {
await withTransaction(async (client) => {
await client.query("SET LOCAL session_replication_role = 'replica'")
await client.query('DELETE FROM work_order_events WHERE work_order_id = $1', [
workOrderId,
])
await client.query('DELETE FROM work_orders WHERE id = $1', [workOrderId])
})
}
if (childCategoryId > 0) {
await query('DELETE FROM order_service_profiles WHERE category_id = $1', [childCategoryId])
await query('DELETE FROM work_categories WHERE id = $1', [childCategoryId])
}
if (parentCategoryId > 0) {
await query('DELETE FROM order_service_profiles WHERE category_id = $1', [parentCategoryId])
await query('DELETE FROM work_categories WHERE id = $1', [parentCategoryId])
}
delete process.env.ENABLE_DEV_MOCK
await closeDb()
}
},
)