feat(edit): 编辑上报细节优化
This commit is contained in:
@@ -654,4 +654,72 @@ describe('SKU 试算与原子确认 HTTP / PostgreSQL', () => {
|
||||
assert.equal(rateCard.rows[0].status, 'draft');
|
||||
assert.equal(rateCard.rows[0].reviewed_at, null);
|
||||
});
|
||||
it('已上架 SKU 可确认本地新价格,保留首次导入身份且不触发平台任务', async () => {
|
||||
const otherStore = randomUUID();
|
||||
await db.workspaceTransaction(workspace, async (tx) => {
|
||||
await tx.query('UPDATE atlas.products SET model=$2 WHERE id=$1', [product, 'LOCAL-RECORD-MODEL']);
|
||||
await tx.query(
|
||||
`UPDATE atlas.product_variant_platform_listings SET status='imported',offer_id='LOCAL-RECORD-SKU',platform_product_id='123456',first_imported_at=now() WHERE profile_id=$1 AND product_variant_id=$2`,
|
||||
[profile, variant],
|
||||
);
|
||||
await tx.query(
|
||||
`INSERT INTO atlas.stores(id,workspace_id,platform_id,name,platform_client_id,currency_code,status,credential_status) VALUES($1,$2,$3,'未来目标店铺',$4,'RUB','active','valid')`,
|
||||
[otherStore, workspace, platform, randomUUID()],
|
||||
);
|
||||
await tx.query('UPDATE atlas.product_platform_profiles SET target_store_id=$2 WHERE id=$1', [profile, otherStore]);
|
||||
});
|
||||
const facts = () => db.workspaceTransaction(workspace, async (tx) => ({
|
||||
listing: (await tx.query(
|
||||
'SELECT status,store_id,offer_id,platform_product_id,first_imported_at,selling_price::text,list_price::text,pricing_quote_id FROM atlas.product_variant_platform_listings WHERE profile_id=$1 AND product_variant_id=$2',
|
||||
[profile, variant],
|
||||
)).rows[0],
|
||||
publishJobs: (await tx.query('SELECT id FROM atlas.product_publish_jobs WHERE product_id=$1', [product])).rows.length,
|
||||
events: (await tx.query('SELECT id FROM atlas.outbox_events')).rows.length,
|
||||
}));
|
||||
const before = await facts();
|
||||
const state = await read();
|
||||
assert.equal(state.variants.find((v) => v.id === variant)?.listing.store_id, store);
|
||||
const input = quote();
|
||||
input.pricing.mode = 'fixed_sale';
|
||||
input.pricing.selling_price = '100';
|
||||
input.pricing.list_price_discount_rate = '0.5';
|
||||
const wrongStore = await request('/pricing/quote-previews', 'POST', { ...input, store_id: otherStore });
|
||||
assert.equal(wrongStore.status, 422);
|
||||
assert.equal(wrongStore.error.code, 'PRICING_VARIANT_STORE_MISMATCH');
|
||||
const preview = await request('/pricing/quote-previews', 'POST', input);
|
||||
assert.equal(preview.status, 201, JSON.stringify(preview));
|
||||
const payload = draft(state);
|
||||
payload.profile.target_store_id = otherStore;
|
||||
const changed = payload.variants.find((v) => v.id === variant)!;
|
||||
changed.pricing_draft = input.pricing;
|
||||
changed.pricing_selection = {
|
||||
preview_id: preview.data.preview_id,
|
||||
option_id: preview.data.recommended_option_id,
|
||||
input_hash: preview.data.input_hash,
|
||||
};
|
||||
changed.purchase_cost_cny = '29.00';
|
||||
assert.equal((await save(state, payload)).status, 409);
|
||||
assert.deepEqual(await facts(), before);
|
||||
changed.purchase_cost_cny = '28.00';
|
||||
const key = randomUUID();
|
||||
const saved = await save(state, payload, key);
|
||||
assert.equal(saved.status, 200, JSON.stringify(saved));
|
||||
assert.deepEqual((await save(state, payload, key)).data, saved.data);
|
||||
const after = await facts();
|
||||
assert.equal(after.listing.selling_price, '100.0000');
|
||||
assert.equal(after.listing.list_price, '200.0000');
|
||||
assert.notEqual(after.listing.pricing_quote_id, before.listing.pricing_quote_id);
|
||||
for (const field of ['status', 'store_id', 'offer_id', 'platform_product_id', 'first_imported_at'])
|
||||
assert.deepEqual(after.listing[field], before.listing[field]);
|
||||
assert.equal(after.publishJobs, before.publishJobs);
|
||||
assert.equal(after.events, before.events);
|
||||
const reread = await read();
|
||||
const listing = reread.variants.find((v) => v.id === variant)!.listing;
|
||||
assert.equal(listing.status, 'imported');
|
||||
assert.equal(listing.pricing_result?.selling_price, '100.00');
|
||||
const ordinary = draft(reread);
|
||||
ordinary.profile.target_store_id = otherStore;
|
||||
assert.equal((await save(reread, ordinary)).status, 200);
|
||||
assert.deepEqual((await facts()).listing, after.listing);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user