feat(edit): 编辑上报细节优化
This commit is contained in:
@@ -20,10 +20,15 @@ vi.mock('../src/media/product-image-download.js', async (importOriginal) => {
|
||||
|
||||
describe('网络商品图片导入', () => {
|
||||
it('复用同工作空间素材并返回正式 ID 与短时预览地址', async () => {
|
||||
const productId = '733d0d73-3d39-4a98-ac0a-5c0e521d8998';
|
||||
const assetId = '7c910684-7070-4f36-8a7b-b10bd91acd79';
|
||||
const bytes = Buffer.from('validated-image');
|
||||
const checksum = createHash('sha256').update(bytes).digest('hex');
|
||||
const query = vi.fn(async (sql: string, args?: unknown[]) => {
|
||||
if (sql.includes('FROM atlas.products')) {
|
||||
expect(args).toEqual([productId]);
|
||||
return { rows: [{ id: productId }] };
|
||||
}
|
||||
if (sql.includes('WHERE checksum_sha256 = $1')) {
|
||||
expect(args).toEqual([checksum]);
|
||||
return { rows: [{ id: assetId }] };
|
||||
@@ -31,6 +36,8 @@ describe('网络商品图片导入', () => {
|
||||
if (sql.includes('INSERT INTO atlas.product_image_imports')) {
|
||||
expect(args?.[0]).toBe('https://example.com/photo.png');
|
||||
expect(args?.[1]).toBe(assetId);
|
||||
expect(args?.[3]).toBe(productId);
|
||||
expect(sql).toContain('ON CONFLICT (workspace_id, product_id, source_url)');
|
||||
return { rows: [] };
|
||||
}
|
||||
if (sql.includes('SELECT id, content_type')) {
|
||||
@@ -86,7 +93,7 @@ describe('网络商品图片导入', () => {
|
||||
'workspace-id',
|
||||
'user-id',
|
||||
'idempotency-key',
|
||||
{ url: 'https://example.com/photo.png' },
|
||||
{ url: 'https://example.com/photo.png', product_id: productId },
|
||||
);
|
||||
const body = result.body as {
|
||||
data: { id: string; source_url: string; preview_url: string };
|
||||
@@ -97,6 +104,6 @@ describe('网络商品图片导入', () => {
|
||||
source_url: 'https://example.com/photo.png',
|
||||
});
|
||||
expect(body.data.preview_url).toContain('product-imports/existing.png');
|
||||
expect(query).toHaveBeenCalledTimes(4);
|
||||
expect(query).toHaveBeenCalledTimes(5);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user