feat(edit): 商品编辑页开发
This commit is contained in:
@@ -59,6 +59,17 @@ describe('扩展授权与采集 HTTP 集成测试', () => {
|
||||
'DELETE FROM atlas.collection_asset_transfers WHERE workspace_id = $1',
|
||||
[workspaceId],
|
||||
);
|
||||
await tx.query(
|
||||
'DELETE FROM atlas.product_variant_platform_listings WHERE workspace_id = $1',
|
||||
[workspaceId],
|
||||
);
|
||||
await tx.query(
|
||||
'DELETE FROM atlas.product_platform_profiles WHERE workspace_id = $1',
|
||||
[workspaceId],
|
||||
);
|
||||
await tx.query('DELETE FROM atlas.stores WHERE workspace_id = $1', [
|
||||
workspaceId,
|
||||
]);
|
||||
await tx.query(
|
||||
'DELETE FROM atlas.product_variants WHERE workspace_id = $1',
|
||||
[workspaceId],
|
||||
@@ -168,6 +179,62 @@ describe('扩展授权与采集 HTTP 集成测试', () => {
|
||||
assert.equal(first.body.data.collection_item.status, 'ready_for_edit');
|
||||
assert.equal(first.body.data.materialization.pending_selection, 1);
|
||||
assert.equal(first.body.data.materialization.queued, 0);
|
||||
const platforms = await request('/api/platforms', {
|
||||
headers: { Authorization: `Bearer ${webAccessToken}` },
|
||||
});
|
||||
const targetPlatform = platforms.body.data.find(
|
||||
(platform: { code: string }) => platform.code === 'OZON',
|
||||
);
|
||||
assert.ok(targetPlatform);
|
||||
await database.workspaceTransaction(workspaceId, async (tx) => {
|
||||
await tx.query(
|
||||
`INSERT INTO atlas.stores
|
||||
(workspace_id, platform_id, name, platform_client_id, currency_code,
|
||||
is_default, status, credential_status)
|
||||
VALUES (current_setting('app.workspace_id')::uuid, $1, '复采测试店铺',
|
||||
$2, 'RUB', true, 'active', 'valid')`,
|
||||
[targetPlatform.id, `refresh-${randomUUID()}`],
|
||||
);
|
||||
});
|
||||
const editorContext = await request(
|
||||
`/api/collection-items/${first.body.data.collection_item.id}/editor-contexts`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${webAccessToken}`,
|
||||
'X-Atlas-Platform-Id': targetPlatform.id,
|
||||
'Idempotency-Key': randomUUID(),
|
||||
},
|
||||
},
|
||||
);
|
||||
assert.equal(editorContext.response.status, 201);
|
||||
// Simulate real draft work before the source page is collected again.
|
||||
// Re-collection must neither delete this SKU nor overwrite its Atlas
|
||||
// fields / platform mapping just because a newer source snapshot arrives.
|
||||
await database.workspaceTransaction(workspaceId, async (tx) => {
|
||||
const variant = await tx.query<{ id: string }>(
|
||||
`SELECT id FROM atlas.product_variants
|
||||
WHERE product_id = $1 AND source_variant_key = '123456789'`,
|
||||
[first.body.data.product_id],
|
||||
);
|
||||
await tx.query(
|
||||
`UPDATE atlas.products SET source_title = '人工确认商品名'
|
||||
WHERE id = $1`,
|
||||
[first.body.data.product_id],
|
||||
);
|
||||
await tx.query(
|
||||
`UPDATE atlas.product_variants
|
||||
SET display_name = '人工确认 SKU', purchase_cost_cny = '88.80'
|
||||
WHERE id = $1`,
|
||||
[variant.rows[0].id],
|
||||
);
|
||||
await tx.query(
|
||||
`UPDATE atlas.product_variant_platform_listings
|
||||
SET offer_id = 'manual-offer-001'
|
||||
WHERE product_variant_id = $1`,
|
||||
[variant.rows[0].id],
|
||||
);
|
||||
});
|
||||
// A sibling Ozon URL has a different entered SKU. It must still reuse
|
||||
// the item because the submitted real-SKU sets overlap at 123456789.
|
||||
const refreshedPayload = {
|
||||
@@ -216,7 +283,8 @@ describe('扩展授权与采集 HTTP 集成测试', () => {
|
||||
{
|
||||
url: 'https://videos.example.test/refreshed-product.mp4',
|
||||
mediaType: 'video',
|
||||
posterUrl: 'https://images.example.test/refreshed-video-poster.jpg',
|
||||
posterUrl:
|
||||
'https://images.example.test/refreshed-video-poster.jpg',
|
||||
role: 'source_main',
|
||||
relation: 'product_candidate',
|
||||
sortOrder: 1,
|
||||
@@ -241,6 +309,33 @@ describe('扩展授权与采集 HTTP 集成测试', () => {
|
||||
);
|
||||
assert.equal(second.body.data.materialization.pending_selection, 2);
|
||||
assert.equal(second.body.data.materialization.queued, 0);
|
||||
const editorAfterRefresh = await request(
|
||||
`/api/products/${first.body.data.product_id}/editor`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${webAccessToken}`,
|
||||
'X-Atlas-Platform-Id': targetPlatform.id,
|
||||
},
|
||||
},
|
||||
);
|
||||
assert.equal(editorAfterRefresh.response.status, 200);
|
||||
assert.equal(
|
||||
editorAfterRefresh.body.data.product.common.source_title,
|
||||
'人工确认商品名',
|
||||
);
|
||||
const originalVariant = editorAfterRefresh.body.data.variants.find(
|
||||
(variant: { source_variant_key: string }) =>
|
||||
variant.source_variant_key === '123456789',
|
||||
);
|
||||
assert.equal(originalVariant.display_name, '人工确认 SKU');
|
||||
assert.equal(originalVariant.purchase_cost_cny, '88.8000');
|
||||
assert.equal(originalVariant.listing.offer_id, 'manual-offer-001');
|
||||
const discoveredVariant = editorAfterRefresh.body.data.variants.find(
|
||||
(variant: { source_variant_key: string }) =>
|
||||
variant.source_variant_key === '987654321',
|
||||
);
|
||||
assert.ok(discoveredVariant);
|
||||
assert.equal(discoveredVariant.listing.status, 'not_listed');
|
||||
const inspection = await request(
|
||||
`/api/collection-items/${first.body.data.collection_item.id}`,
|
||||
{ headers: { Authorization: `Bearer ${webAccessToken}` } },
|
||||
@@ -269,10 +364,17 @@ describe('扩展授权与采集 HTTP 集成测试', () => {
|
||||
'pending_selection',
|
||||
);
|
||||
const videoTransfer = inspection.body.data.asset_transfers.find(
|
||||
(transfer: { media_type: string }) => transfer.media_type === 'video',
|
||||
(transfer: { media_type: string }) =>
|
||||
transfer.media_type === 'video',
|
||||
);
|
||||
assert.equal(
|
||||
videoTransfer?.source_url,
|
||||
'https://videos.example.test/refreshed-product.mp4',
|
||||
);
|
||||
assert.equal(
|
||||
videoTransfer?.poster_url,
|
||||
'https://images.example.test/refreshed-video-poster.jpg',
|
||||
);
|
||||
assert.equal(videoTransfer?.source_url, 'https://videos.example.test/refreshed-product.mp4');
|
||||
assert.equal(videoTransfer?.poster_url, 'https://images.example.test/refreshed-video-poster.jpg');
|
||||
const eventsBeforeSelection = await database.workspaceTransaction(
|
||||
workspaceId,
|
||||
async (tx) =>
|
||||
|
||||
Reference in New Issue
Block a user