fix(edit): 类目问题修改

This commit is contained in:
R524809
2026-09-11 10:36:25 +08:00
parent 05a00d46b9
commit 2c4e94ab3d
11 changed files with 869 additions and 79 deletions
+101 -1
View File
@@ -126,6 +126,10 @@ describe('商品编辑 M3.0–M3.3 HTTP 集成测试', () => {
'DELETE FROM atlas.product_attributes WHERE workspace_id = $1',
[workspaceId],
);
await tx.query(
'DELETE FROM atlas.product_variant_listing_media WHERE workspace_id = $1',
[workspaceId],
);
await tx.query(
'DELETE FROM atlas.product_variant_platform_listings WHERE workspace_id = $1',
[workspaceId],
@@ -157,6 +161,9 @@ describe('商品编辑 M3.0–M3.3 HTTP 集成测试', () => {
await tx.query('DELETE FROM atlas.stores WHERE workspace_id = $1', [
workspaceId,
]);
await tx.query('DELETE FROM atlas.media_assets WHERE workspace_id = $1', [
workspaceId,
]);
});
await database.query(
'DELETE FROM atlas.workspace_memberships WHERE user_id = $1',
@@ -1058,7 +1065,7 @@ describe('商品编辑 M3.0–M3.3 HTTP 集成测试', () => {
await database.workspaceTransaction(workspaceId, async (tx) => {
await tx.query(
`UPDATE atlas.collection_items
SET source_platform_id = $1,
SET source_kind = 'platform', source_platform_id = $1,
normalized_payload = $2::jsonb
WHERE id = $3`,
[
@@ -1193,4 +1200,97 @@ describe('商品编辑 M3.0–M3.3 HTTP 集成测试', () => {
);
});
});
it('M3.6 仅允许当前 SKU 已转存候选作为有序正式素材', async () => {
const before = await request(`/api/products/${first.productId}/editor`, {
headers: headers({ 'X-Atlas-Platform-Id': platformId }),
});
const variant = before.body.data.variants[0];
const asset = await database.workspaceTransaction(workspaceId, async (tx) => {
const created = await tx.query<{ id: string }>(
`INSERT INTO atlas.media_assets
(workspace_id, storage_provider, bucket, object_key, content_type,
byte_size, checksum_sha256, width_px, height_px)
VALUES (current_setting('app.workspace_id')::uuid, 'test', 'test', $1,
'image/jpeg', 1024, $2, 1200, 900)
RETURNING id`,
[`m36/${randomUUID()}.jpg`, randomUUID().replaceAll('-', '')],
);
const snapshot = await tx.query<{ source_snapshot_revision: string }>(
`SELECT source_snapshot_revision::text FROM atlas.collection_items WHERE id = $1`,
[first.collectionItemId],
);
await tx.query(
`INSERT INTO atlas.collection_asset_transfers
(workspace_id, collection_item_id, product_id, source_variant_id, role,
source_url, status, asset_id, source_snapshot_revision, completed_at)
VALUES (current_setting('app.workspace_id')::uuid, $1, $2, $3,
'source_sku', 'https://example.test/m36.jpg', 'succeeded', $4, $5, now())`,
[
first.collectionItemId,
first.productId,
variant.id,
created.rows[0].id,
snapshot.rows[0].source_snapshot_revision,
],
);
return created.rows[0].id;
});
const payload = {
ai_source_material: before.body.data.source_material,
ai_source_overridden_fields:
before.body.data.source_material_state.overridden_fields,
common: {
...before.body.data.product.common,
default_physical_spec: before.body.data.product.default_physical_spec,
default_package_spec: before.body.data.product.default_package_spec,
},
profile: {
target_store_id: before.body.data.profile.target_store.id,
fulfillment: before.body.data.profile.fulfillment,
title: before.body.data.profile.title,
description: before.body.data.profile.description,
tags: before.body.data.profile.tags,
store_product_category_id: before.body.data.profile.category.id,
category_source: before.body.data.profile.category.source,
},
attributes: before.body.data.attributes.map((attribute: any) => ({
scope: attribute.scope,
variant_id: attribute.variant_id,
platform_attribute_id: attribute.platform_attribute_id,
complex_id: attribute.complex_id,
values: attribute.values,
language_code: attribute.language_code,
source: attribute.source,
confirmation_status: attribute.confirmation_status,
})),
variants: before.body.data.variants.map((item: any) => ({
id: item.id,
client_key: null,
copy_from_variant_id: null,
display_name: item.display_name,
source_sku: item.source_sku,
specification_values: item.specification_values,
purchase_cost_cny: item.purchase_cost_cny,
physical_spec: item.physical_spec,
package_spec: item.package_spec,
offer_id: item.listing.offer_id,
media_asset_ids: item.id === variant.id ? [asset] : [],
})),
};
const saved = await request(`/api/products/${first.productId}/editor-draft`, {
method: 'PUT',
headers: headers({
'X-Atlas-Platform-Id': platformId,
'Idempotency-Key': randomUUID(),
'If-Match': `"${before.body.data.product.revision}:${before.body.data.profile.revision}"`,
}),
body: JSON.stringify(payload),
});
assert.equal(saved.response.status, 200);
const after = await request(`/api/products/${first.productId}/editor`, {
headers: headers({ 'X-Atlas-Platform-Id': platformId }),
});
assert.deepEqual(after.body.data.variants[0].media.map((item: any) => item.asset_id), [asset]);
});
});