feat(edit): 编辑上报细节优化
This commit is contained in:
@@ -1933,18 +1933,18 @@ describe('商品编辑 M3.0–M3.3 HTTP 集成测试', () => {
|
||||
`INSERT INTO atlas.media_upload_intents
|
||||
(workspace_id, purpose, storage_provider, bucket, object_key,
|
||||
expected_content_type, expected_byte_size, expected_checksum_sha256,
|
||||
status, asset_id, expires_at, completed_at)
|
||||
status, asset_id, expires_at, completed_at, product_id)
|
||||
VALUES (current_setting('app.workspace_id')::uuid, 'product_image',
|
||||
'test', 'test', $1, 'image/png', 1024, $2,
|
||||
'ready', $3, now() + interval '1 hour', now())`,
|
||||
[objectKey, checksum, assetId],
|
||||
'ready', $3, now() + interval '1 hour', now(), $4)`,
|
||||
[objectKey, checksum, assetId, first.productId],
|
||||
);
|
||||
} else {
|
||||
await tx.query(
|
||||
`INSERT INTO atlas.product_image_imports
|
||||
(workspace_id, source_url, asset_id)
|
||||
VALUES (current_setting('app.workspace_id')::uuid, $1, $2)`,
|
||||
[`https://example.test/${randomUUID()}.png`, assetId],
|
||||
(workspace_id, source_url, asset_id, product_id)
|
||||
VALUES (current_setting('app.workspace_id')::uuid, $1, $2, $3)`,
|
||||
[`https://example.test/${randomUUID()}.png`, assetId, first.productId],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1971,20 +1971,38 @@ describe('商品编辑 M3.0–M3.3 HTTP 集成测试', () => {
|
||||
headers: headers({ 'X-Atlas-Platform-Id': platformId }),
|
||||
});
|
||||
assert.equal(expandedSnapshot.body.data.variants[0].media.length, 30);
|
||||
const uploaded = await request('/api/media-assets/product-uploads', {
|
||||
const uploaded = await request(`/api/media-assets/product-uploads?product_id=${first.productId}`, {
|
||||
headers: headers(),
|
||||
});
|
||||
assert.equal(uploaded.response.status, 200);
|
||||
assert.ok(uploaded.body.data.some((item: any) => item.id === additionalAssets[0]));
|
||||
const imported = await request('/api/media-assets/product-imports', {
|
||||
const usedDeletion = await request(`/api/products/${first.productId}/image-deletions`, {
|
||||
method: 'POST', headers: headers({ 'Idempotency-Key': randomUUID() }),
|
||||
body: JSON.stringify({ asset_id: additionalAssets[0] }),
|
||||
});
|
||||
assert.equal(usedDeletion.response.status, 409);
|
||||
assert.equal(usedDeletion.body.error.code, 'MEDIA_ASSET_IN_USE');
|
||||
const invalidDeletion = await request(`/api/products/${first.productId}/image-deletions`, {
|
||||
method: 'POST', headers: headers({ 'Idempotency-Key': randomUUID() }), body: '{}',
|
||||
});
|
||||
assert.equal(invalidDeletion.response.status, 422);
|
||||
|
||||
const imported = await request(`/api/media-assets/product-imports?product_id=${first.productId}`, {
|
||||
headers: headers(),
|
||||
});
|
||||
assert.equal(imported.response.status, 200);
|
||||
assert.ok(imported.body.data.some((item: any) => item.id === additionalAssets[1]));
|
||||
const unscoped = await request('/api/media-assets/product-uploads', { headers: headers() });
|
||||
assert.equal(unscoped.response.status, 422);
|
||||
for (const kind of ['product-uploads', 'product-imports']) {
|
||||
const unrelated = await request(`/api/media-assets/${kind}?product_id=${randomUUID()}`, { headers: headers() });
|
||||
assert.equal(unrelated.response.status, 200);
|
||||
assert.deepEqual(unrelated.body.data, []);
|
||||
}
|
||||
const privateImport = await request('/api/media-assets/product-imports', {
|
||||
method: 'POST',
|
||||
headers: headers({ 'Idempotency-Key': randomUUID() }),
|
||||
body: JSON.stringify({ url: 'https://127.0.0.1/private.png' }),
|
||||
body: JSON.stringify({ product_id: first.productId, url: 'https://127.0.0.1/private.png' }),
|
||||
});
|
||||
assert.equal(privateImport.response.status, 422);
|
||||
assert.equal(privateImport.body.error.code, 'PRODUCT_IMAGE_IMPORT_INVALID');
|
||||
|
||||
Reference in New Issue
Block a user