修复四项新版开单和恢复差异,核验三项已确认行为
This commit is contained in:
1 parent
fdaa6afad5
commit
c29ea45ec4
25 files changed
+617
-171
No files matched your search
@@ -109,11 +109,9 @@ async function recoverTeamTransfer(context, owner, path) {
|
||||
export async function teamTransfers(context, owner) {
|
||||
const feedback = {};
|
||||
for (const path of ['transfer', 'transfers']) feedback[path] = await recoverTeamTransfer(context, owner, path);
|
||||
if (context.version === 'old')
|
||||
assert.deepEqual(
|
||||
feedback,
|
||||
{
|
||||
transfer: {
|
||||
const singular =
|
||||
context.version === 'old'
|
||||
? {
|
||||
heading: '订单',
|
||||
toast: '订单不存在',
|
||||
orderReads: [
|
||||
@@ -122,11 +120,18 @@ export async function teamTransfers(context, owner) {
|
||||
['/change', 404],
|
||||
['/ownership', 404],
|
||||
],
|
||||
},
|
||||
transfers: { heading: '团队账目', toast: '实际转账已保存,待转金额已重新核对', orderReads: [] },
|
||||
},
|
||||
'历史团队转账两个兼容地址的恢复反馈',
|
||||
);
|
||||
}
|
||||
: { heading: '订单', toast: '原操作已确认', orderReads: [] };
|
||||
assert.deepEqual(feedback.transfer, singular, '旧单数地址应显示本版本确认的反馈');
|
||||
assert.deepEqual(
|
||||
feedback.transfers,
|
||||
{
|
||||
heading: '团队账目',
|
||||
toast: '实际转账已保存,待转金额已重新核对',
|
||||
orderReads: [],
|
||||
},
|
||||
'复数地址恢复后应返回团队账目并确认实际转账',
|
||||
);
|
||||
return { 历史团队转账反馈: feedback };
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
// 已确认的 D2 / D7 只生成预期请求副本。实际抓包和每个时点的原始账本均由 runner 保留。
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
const poolStep = '撤销退回现货选择并切换日期后按料池实际开单';
|
||||
const cancelStockStep = '取消退回现货选择后按原输入开单';
|
||||
const issueSteps = {
|
||||
issue: new Set(['多件公式识别后实际开单', '毫克克重与含前导零的分位金额实际开单', cancelStockStep, '整批退回现货沿用原工费再次销售']),
|
||||
'issue-reopen': new Set(['首笔普通两件商品完成销售', '新标签页从首页录入第二笔销售']),
|
||||
'issue-pool-date': new Set([poolStep]),
|
||||
};
|
||||
|
||||
// 固定旧页面把部分可见控件值额外平铺在行上。每项须能从同一个请求的业务字段还原。
|
||||
function duplicateInputs(line) {
|
||||
const pool = line.costMaterial.mode === 'pool';
|
||||
const inputs = {
|
||||
'cost-materialSource': pool ? 'pool' : 'manual',
|
||||
'cost-materialPoolId': line.materialPoolDraft.poolId,
|
||||
'cost-materialMode': pool ? 'total' : line.costMaterial.mode,
|
||||
'cost-materialRate': pool ? (line.materialPool.averageRate / 100).toFixed(2) : line.costMaterial.rate,
|
||||
'cost-material': line.costParts.material,
|
||||
'cost-materialPayer': line.costPayers.material,
|
||||
'cost-laborMode': line.costLabor.mode,
|
||||
'cost-laborRate': line.costLabor.rate ?? '',
|
||||
'cost-labor': line.costParts.labor,
|
||||
'cost-laborPayer': line.costPayers.labor,
|
||||
'cost-accessories': line.costParts.accessories,
|
||||
'cost-other': line.costParts.other,
|
||||
};
|
||||
if (pool) {
|
||||
assert.equal(line.costPayers.material, 'owner', '本组两个单料池样本由麦麦垫付');
|
||||
inputs['cost-materialPoolPayer'] = '麦麦';
|
||||
}
|
||||
if (!line.returnedStockId) inputs.returnedStockId = '';
|
||||
return inputs;
|
||||
}
|
||||
|
||||
export function assertIssueInputs(version, payload) {
|
||||
for (const line of payload.lines) {
|
||||
for (const [key, expected] of Object.entries(duplicateInputs(line))) {
|
||||
if (version === 'old') assert.equal(line[key], expected, '旧页面控件须与实际业务输入一致 ' + key);
|
||||
else assert.ok(!Object.hasOwn(line, key), '新版应仅提交业务输入 ' + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function expectedIssueResult(group, oldResult, explicitPoolResult) {
|
||||
if (!Object.hasOwn(issueSteps, group)) return oldResult;
|
||||
let reference = oldResult;
|
||||
if (group === 'issue-pool-date') {
|
||||
// 使用同一固定旧版本、相同初始账本的另一笔真实 UI 写入,仅将用户选中的料池改为订单日期。
|
||||
// 该请求的写后数据库、步骤后数据库及终态均是完整的旧版账本,不能屏蔽其金额、版本或流水字段。
|
||||
assert.ok(explicitPoolResult, '缺少旧版实际选用订单日期的账本');
|
||||
assert.deepEqual(Object.keys(explicitPoolResult.steps), [poolStep]);
|
||||
assert.deepEqual(explicitPoolResult.steps[poolStep].before, oldResult.steps[poolStep].before, '两个独立旧账本起点不一致');
|
||||
reference = explicitPoolResult;
|
||||
}
|
||||
const expected = structuredClone(reference);
|
||||
for (const label of issueSteps[group]) {
|
||||
const capture = expected.steps[label];
|
||||
if (!capture) continue; // 未执行的用例由 runner 的 failures 和步骤比较报告。
|
||||
assert.equal(capture.requests.length, 1, label);
|
||||
const [request] = capture.requests;
|
||||
assert.equal(request.endpoint, '/api/orders/issue', label);
|
||||
assert.equal(request.status, 200, label);
|
||||
assertIssueInputs('old', request.payload);
|
||||
for (const line of request.payload.lines) {
|
||||
for (const key of Object.keys(duplicateInputs(line))) delete line[key];
|
||||
}
|
||||
if (label === cancelStockStep || label === poolStep) {
|
||||
assert.equal(request.payload.lines.length, 1, label);
|
||||
const draft = request.payload.lines[0].materialPoolDraft;
|
||||
assert.equal(draft.defaultDate, false, label);
|
||||
assert.equal(draft.poolId, request.payload.date, label);
|
||||
draft.defaultDate = true;
|
||||
}
|
||||
}
|
||||
return expected;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { newUi, oldUi } from '../parity-create-order.mjs';
|
||||
import { assertIssueInputs } from './issue-contract.mjs';
|
||||
|
||||
async function seedReturnedLot(session, day) {
|
||||
const post = async (path, params) => {
|
||||
@@ -93,6 +94,7 @@ export default async function issue({ version, base, day, pageFor, session, step
|
||||
assert.equal(response.status(), 200, await response.text());
|
||||
assert.ok(shown.paper);
|
||||
const saved = await response.json();
|
||||
assertIssueInputs(version, response.request().postDataJSON());
|
||||
result = {
|
||||
payload: response.request().postDataJSON(),
|
||||
order: await session.get('owner', '/api/orders/' + saved.id),
|
||||
@@ -185,6 +187,7 @@ export default async function issue({ version, base, day, pageFor, session, step
|
||||
assert.equal(await control('cost-labor').inputValue(), '3.25');
|
||||
const ordinarySale = await issueSale('取消退回现货选择后按原输入开单');
|
||||
assert.ok(!ordinarySale.order.lines[0].returnedStockId);
|
||||
assert.equal(ordinarySale.payload.lines[0].materialPoolDraft.defaultDate, version === 'new');
|
||||
assert.equal(ordinarySale.order.lines[0].costParts.labor, 325);
|
||||
assert.equal((await lots()).lots[0].id, lot.id);
|
||||
await start('完好退回现货再次销售');
|
||||
@@ -229,6 +232,7 @@ export async function exerciseIssueReopen({ version, base, day, session, pageFor
|
||||
ui.submit(page),
|
||||
]);
|
||||
assert.equal(response.status(), 200);
|
||||
assertIssueInputs(version, response.request().postDataJSON());
|
||||
const { id } = await response.json(),
|
||||
saved = await session.get('owner', '/api/orders/' + id);
|
||||
assert.equal(saved.paper_number, shown.paper);
|
||||
@@ -400,11 +404,17 @@ export async function exerciseIssuePoolDate({
|
||||
ui.submit(page),
|
||||
]);
|
||||
assert.equal(response.status(), 200);
|
||||
assertIssueInputs(version, response.request().postDataJSON());
|
||||
const { id } = await response.json(),
|
||||
order = await session.get('owner', '/api/orders/' + id);
|
||||
assert.equal(order.paper_number, shown.paper);
|
||||
await page.waitForLoadState('networkidle');
|
||||
const requestLine = response.request().postDataJSON().lines[0];
|
||||
assert.equal(requestLine.costMaterial.poolId, order.lines[0].costMaterial.poolId);
|
||||
assert.equal(order.lines[0].quantity, 1250);
|
||||
assert.equal(order.lines[0].costParts.labor, 325);
|
||||
return {
|
||||
defaultDate: requestLine.materialPoolDraft.defaultDate,
|
||||
poolId: order.lines[0].costMaterial?.poolId,
|
||||
sale: order.total,
|
||||
material: order.lines[0].costParts.material,
|
||||
@@ -425,24 +435,25 @@ export async function exerciseIssuePoolDate({
|
||||
await ui.step(page, ['line', 0, 'materialSource', 'pool']);
|
||||
await toggleDate();
|
||||
assert.equal(await selectedPoolDate(), day, version + ' 未经退回现货时料价日期应跟随业务日期');
|
||||
await page.evaluate(() => {
|
||||
for (const key of Object.keys(localStorage))
|
||||
if (key.startsWith('mm-draft-') || key.startsWith('mm-next-draft-')) localStorage.removeItem(key);
|
||||
});
|
||||
await ui.step(page, ['line', 0, 'materialSource', 'manual']);
|
||||
|
||||
// 1.250g × 当日加权料价 814.29 元/克 = 1,017.86 元;前一天料池为 500 元/克,即 625.00 元。
|
||||
await ui.open(page, base);
|
||||
await fillSale('退回现货切换日期');
|
||||
const select = ui.line(page, 0).locator('[name=returnedStockId]');
|
||||
await select.selectOption(lot.id);
|
||||
await select.selectOption('');
|
||||
await ui.step(page, ['line', 0, 'materialSource', 'pool']);
|
||||
await toggleDate();
|
||||
if (selectOrderDatePool) {
|
||||
assert.equal(version, 'old');
|
||||
await ui.line(page, 0).locator('[name="cost-materialPoolId"]').selectOption(day);
|
||||
}
|
||||
await step('撤销退回现货选择并切换日期后按料池实际开单', async () => {
|
||||
const result = await issue(),
|
||||
evidence = JSON.stringify(result);
|
||||
assert.equal(result.sale, 122500, evidence);
|
||||
if (version === 'old') {
|
||||
assert.equal(result.defaultDate, version === 'new', evidence);
|
||||
if (version === 'old' && !selectOrderDatePool) {
|
||||
// 登记的旧版缺陷仍可复现:仅因选过又取消退回现货,订单被钉在前一天料池。
|
||||
assert.equal(result.poolId, yesterday, '旧版缺陷 D2 未复现:' + evidence);
|
||||
assert.equal(result.material, 62500, evidence);
|
||||
|
||||
@@ -82,6 +82,7 @@ export async function exerciseOrderConflicts({
|
||||
assert.deepEqual(attempts[1], attempts[0]);
|
||||
assert.deepEqual(attempts[2], attempts[0]);
|
||||
assert.equal(await field(form, 'amount').inputValue(), '2.50');
|
||||
assert.equal(await field(form, 'verified').isChecked(), true, '待恢复时保留原来的核对勾选');
|
||||
assert.equal(await form.locator('button.primary').isDisabled(), true, '结果待确认时仍可再次保存');
|
||||
});
|
||||
} finally {
|
||||
|
||||
@@ -28,6 +28,12 @@ export default async function recoveryQuote(ctx) {
|
||||
await owner.locator('[data-action=recovery-mode][data-mode=exchange]').click();
|
||||
const form = owner.locator('#recovery-form');
|
||||
const field = name => form.locator('[name="' + name + '"]');
|
||||
let original;
|
||||
function captureQuote(request) {
|
||||
if (new URL(request.url()).pathname === '/api/recoveries/quote' && request.method() === 'POST')
|
||||
original = request.postDataJSON();
|
||||
}
|
||||
owner.on('request', captureQuote);
|
||||
await ctx.step('置换试算列出个人和公共料各自的用量、成本与前后余额', async () => {
|
||||
await field('customer').fill('核对两种扣料来源');
|
||||
await form.locator('[name=customer_type][value=new]').check();
|
||||
@@ -55,4 +61,65 @@ export default async function recoveryQuote(ctx) {
|
||||
'实际置换料池试算:' + shown,
|
||||
);
|
||||
});
|
||||
owner.off('request', captureQuote);
|
||||
const status = owner.locator('#recovery-quote-status');
|
||||
const note = owner.locator('#recovery-material-note');
|
||||
await ctx.step('余额读取失败时继续展示扣料来源和已核对的结算', async () => {
|
||||
const balanceUrl = ctx.base + '/api/material-pools/quote';
|
||||
const unavailable = route => route.fulfill({ status: 503, json: { error: '对照余额暂不可用' } });
|
||||
await owner.route(balanceUrl, unavailable);
|
||||
try {
|
||||
await field('new_quantity').fill('3.200');
|
||||
await note.getByText(/个人与公共余量暂未读到,请刷新核对/).waitFor();
|
||||
await status.getByText(/结算已核对/).waitFor();
|
||||
const shown = await note.innerText();
|
||||
assert.ok(shown.includes('个人回收料 0.400g · ¥320.00') && shown.includes('公共料 0.800g · ¥720.00'), shown);
|
||||
} finally {
|
||||
await owner.unroute(balanceUrl, unavailable);
|
||||
}
|
||||
});
|
||||
await ctx.step('分来源成本合计与服务端总额不符时提示重新核对', async () => {
|
||||
const quoteUrl = ctx.base + '/api/recoveries/quote';
|
||||
const inconsistent = async route => {
|
||||
const res = await route.fetch();
|
||||
try {
|
||||
const reply = await res.json();
|
||||
assert.ok(Number.isSafeInteger(reply.materialCost));
|
||||
await route.fulfill({ json: { ...reply, materialCost: reply.materialCost + 1 } });
|
||||
} finally {
|
||||
await res.dispose();
|
||||
}
|
||||
};
|
||||
await owner.route(quoteUrl, inconsistent);
|
||||
try {
|
||||
await field('new_quantity').fill('3.500');
|
||||
await status.getByText(/置换用料来源与当前归属不一致,请重新核对/).waitFor();
|
||||
} finally {
|
||||
await owner.unroute(quoteUrl, inconsistent);
|
||||
}
|
||||
});
|
||||
await session.post('owner', '/api/stock', {
|
||||
date: day,
|
||||
kind: 'increase',
|
||||
grams: '3',
|
||||
pocket: '现货',
|
||||
note: '原置换的出货库存',
|
||||
});
|
||||
const historical = await session.post('owner', '/api/recoveries', { ...original, verified: true });
|
||||
assert.deepEqual(session.problems, []);
|
||||
await section(owner, ctx, 'recoveries');
|
||||
await owner
|
||||
.locator('[data-action=recovery-open][data-id="' + historical.id + '"]')
|
||||
.first()
|
||||
.click();
|
||||
await owner.locator('#recovery-dialog[open] [data-action=recovery-edit-open]').click();
|
||||
await ctx.step('修改已有置换单时排除原单耗用并列出扣料前后结余', async () => {
|
||||
await field('change_reason').fill('复核原料池');
|
||||
await field('new_quantity').fill('3.200');
|
||||
await note.getByText(/原单耗用已排除/).waitFor();
|
||||
const shown = await note.innerText();
|
||||
assert.ok(shown.includes('个人回收料 0.400g · ¥320.00') && shown.includes('公共料 0.800g · ¥720.00'), shown);
|
||||
assert.ok(shown.includes('本次前可用:个人 0.400g,公共 8.000g'), shown);
|
||||
assert.ok(shown.includes('本次后余:个人回收料 0.000g,公共料 7.200g'), shown);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user