Files
SupplierSystem/server/tests/deliveryLoadingExtraDishVisibility.test.ts
T
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库:jxc/ai-fresh-delivery
来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d
快照树:  09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件)

按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据
(生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、
deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

95 lines
4.1 KiB
TypeScript

import { readFileSync } from 'fs';
import { describe, expect, it } from 'vitest';
import {
extraDishPhotosSatisfied,
loadingPhotosSatisfied,
} from '../src/services/deliveryLoadingService';
const src = readFileSync(new URL('../src/services/deliveryLoadingService.ts', import.meta.url), 'utf8');
function sliceFn(name: string, nextExport: string) {
const start = src.indexOf(name);
const end = src.indexOf(nextExport);
expect(start).toBeGreaterThan(0);
expect(end).toBeGreaterThan(start);
return src.slice(start, end);
}
describe('配送核货收容加菜(司机自买仍须核)', () => {
it('分拣快照与漏行均不排除加菜;跨拣货单按订单合并', () => {
const loadingSql = sliceFn('const LOADING_ITEMS_SQL', 'function mapLoadingItem');
expect(loadingSql).not.toContain('COALESCE(oi.is_extra_dish, false) = false');
expect(loadingSql).toContain('COALESCE(oi.is_extra_dish, false) AS is_extra_dish');
expect(loadingSql).toContain('pi.order_code = $1');
expect(loadingSql).not.toContain('pi.pick_code = $1');
const missingSql = sliceFn('const MISSING_NON_EXTRA_LOADING_SQL', 'async function listLoadingItems');
expect(missingSql).not.toContain('COALESCE(oi.is_extra_dish, false) = false');
expect(missingSql).toContain('COALESCE(oi.is_extra_dish, false) AS is_extra_dish');
expect(missingSql).toContain('SELECT 1 FROM picking_items pi WHERE pi.order_item_id = oi.id');
expect(missingSql).toContain('oi.order_code = $1');
const listFn = sliceFn('async function listLoadingItems', 'async function markLoadingCompleteIfReady');
expect(listFn).toContain('MISSING_NON_EXTRA_LOADING_SQL');
expect(listFn).not.toContain('INSERT INTO picking_items');
expect(src).toContain('displayPickedMeasureForUnit');
expect(loadingSql).toContain('pi.picked_qty');
});
it('跳过分拣补建仍不把加菜写入仓内拣货单', () => {
const ensure = sliceFn(
'async function ensureDeliveryLoadingPickTask',
'const LOADING_ITEMS_SQL'
);
expect(ensure).toContain('listExtraDishOrderItemIds');
expect(ensure).toContain('!extraIds.has(String(item.id))');
expect(ensure).toContain('WHERE pi.order_code = $1');
});
it('点有货可为加菜漏行 INSERT,不再拒绝加菜确认', () => {
expect(src).toContain('async function resolveOrCreatePickingItemForLoading');
expect(src).not.toContain("code: 'extra_dish'");
expect(src).not.toContain('加菜商品无需配送员核货');
const resolve = sliceFn(
'async function resolveOrCreatePickingItemForLoading',
'export async function confirmDeliveryLoadingItem'
);
expect(resolve).toContain('INSERT INTO picking_items');
expect(resolve).not.toContain('isExtraDishFlag(row.is_extra_dish)');
});
it('扫码走确认同一套显隐,不直接 UPDATE 漏行', () => {
const scan = sliceFn(
'export async function scanDeliveryLoadingBarcode',
'export async function assertDeliveryLoadingComplete'
);
expect(scan).toContain('confirmDeliveryLoadingItem');
expect(scan).toContain('listLoadingItems');
expect(scan).not.toMatch(/UPDATE picking_items SET loaded_qty/);
});
it('空列表不视为核货完成(避免全加菜假完成发车)', () => {
expect(src).toContain('const allLoaded = items.length > 0 && items.every((item) => item.loaded_done)');
expect(src).toContain('const allLoaded = loadedCount === items.length && items.length > 0');
});
it('加菜必须核货照;未拍不能算送达就绪', () => {
expect(
loadingPhotosSatisfied(
[{ needs_loading_photo: true, loading_photo_count: 0, is_extra_dish: true }],
false
)
).toBe(false);
expect(
extraDishPhotosSatisfied([
{ is_extra_dish: true, loaded_done: true, loading_photo_count: 0 },
])
).toBe(false);
expect(
extraDishPhotosSatisfied([
{ is_extra_dish: true, loaded_done: true, loading_photo_count: 1 },
])
).toBe(true);
expect(src).toContain('task_status) >= 20 && !isExtraDishFlag(item.is_extra_dish)');
expect(src).toContain('export async function assertExtraDishLoadingPhotos');
});
});