feat(ai-image): AI生图开发
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import {
|
||||
mapOzonProduct,
|
||||
parseOzonInfoItems,
|
||||
parseOzonListPage,
|
||||
} from '../src/online-product-mapper.ts';
|
||||
|
||||
test('列表游标与商品标识按平台响应读取,缺失标识时拒绝继续同步', () => {
|
||||
const page = parseOzonListPage({
|
||||
result: {
|
||||
items: [{ product_id: 123, offer_id: 'offer-1' }],
|
||||
last_id: 'next-page',
|
||||
},
|
||||
});
|
||||
assert.deepEqual(page, {
|
||||
items: [{ product_id: '123', offer_id: 'offer-1' }],
|
||||
lastId: 'next-page',
|
||||
});
|
||||
assert.throws(
|
||||
() => parseOzonListPage({ result: { items: [{ product_id: 123 }] } }),
|
||||
/缺少商品标识/,
|
||||
);
|
||||
assert.throws(() => parseOzonInfoItems({ result: {} }), /响应格式异常/);
|
||||
});
|
||||
|
||||
test('可见性未知、库存零和审核错误保留各自语义', () => {
|
||||
const product = mapOzonProduct(
|
||||
{
|
||||
id: 123,
|
||||
offer_id: 'offer-1',
|
||||
name: '商品',
|
||||
price: '999.00',
|
||||
old_price: '1110.00',
|
||||
stocks: { present: 0 },
|
||||
status: {
|
||||
moderate_status: 'declined',
|
||||
validation_state: 'failed',
|
||||
decline_reasons: [{ message: '图片不符合要求' }],
|
||||
},
|
||||
images: [{ file_name: 'https://example.com/product.jpg' }],
|
||||
sources: [{ sku: 456 }],
|
||||
},
|
||||
{ product_id: '123', offer_id: 'offer-1' },
|
||||
);
|
||||
assert.equal(product.visible, null);
|
||||
assert.deepEqual(product.stock_summary, { total: 0, has_data: true });
|
||||
assert.equal(product.moderation_status, 'declined');
|
||||
assert.equal(product.remote_sku, '456');
|
||||
assert.equal(product.image_summary.url, 'https://example.com/product.jpg');
|
||||
assert.equal(product.error_payload[0].message, '图片不符合要求');
|
||||
assert.equal(product.selling_price, '999.00');
|
||||
});
|
||||
|
||||
test('不存在库存数据和非 HTTPS 图片不能伪装成有效平台数据', () => {
|
||||
const product = mapOzonProduct(
|
||||
{ id: 123, price: 'abc', primary_image: 'http://example.com/a.jpg' },
|
||||
{ product_id: '123', offer_id: 'offer-1' },
|
||||
);
|
||||
assert.deepEqual(product.stock_summary, { total: 0, has_data: false });
|
||||
assert.equal(product.image_summary.url, null);
|
||||
assert.equal(product.selling_price, null);
|
||||
});
|
||||
Reference in New Issue
Block a user