Files
SupplierSystem/server/tests/inspectionReviewAssistant.test.ts
T
雨天 1956e13ef2
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
feat(验收照片复核): 新增「出库照片」Tab
只读展示分拣出库时逐商品行拍的照片(picking_items.outbound_photos),与「配送补拍」独立、不排除加菜行。后端 listPickingOutboundPhotoReviews + Web 路由/MCP 分流 + Tab 计数增至四项;前端第 4 个 Tab、列与 Copilot 动作;三语 6 键。无迁移、无写路径。
2026-10-13 10:22:05 +08:00

104 lines
3.7 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest';
import type { TenantContext } from '../src/services/tenantScope';
vi.mock('../src/services/inspectionReviewOps', () => ({
listInspectionReviews: vi.fn(async () => ({
rows: [{ id: 'r1', order_code: 'ORD1', item_name: '土豆', source_type: 'purchase' }],
total: 1,
})),
listLoadingPhotoReviews: vi.fn(async () => ({ rows: [], total: 0 })),
listDeliverySignPhotoReviews: vi.fn(async () => ({ rows: [], total: 0 })),
listPickingOutboundPhotoReviews: vi.fn(async () => ({ rows: [], total: 0 })),
}));
import { listInspectionReviews } from '../src/services/inspectionReviewOps';
import { executeCapability } from '../src/capabilities/registry';
import { registerBuiltinCapabilities } from '../src/capabilities/registerBuiltins';
import { routeModules } from '../src/capabilities/routeModules';
registerBuiltinCapabilities();
const superAdmin: TenantContext = {
userId: 'u1',
roles: ['super_admin'],
permissions: [],
branchCode: 'BR001',
supplierCode: null,
purchaserCode: null,
isSuperAdmin: true,
isBranchAdmin: false,
isInternalStaff: true,
isSupplierAccount: false,
};
describe('list_inspection_reviews', () => {
beforeEach(() => {
vi.mocked(listInspectionReviews).mockClear();
});
it('asks for date_from instead of defaulting to today', async () => {
const result = await executeCapability('list_inspection_reviews', {
userId: 'u1',
ctx: superAdmin,
args: {},
surface: 'web',
});
expect(result.ok).toBe(false);
if (!result.ok) {
expect(result.code).toBe('need_input');
expect(result.missing).toContain('date_from');
}
expect(listInspectionReviews).not.toHaveBeenCalled();
});
it('defaults date_field to delivery_date and navigates menu path', async () => {
const result = await executeCapability('list_inspection_reviews', {
userId: 'u1',
ctx: superAdmin,
args: { date_from: '2026-09-06', search: '土豆', sync_page: true },
surface: 'web',
visiblePages: [{ path: '/inspection/review', label: '验收照片复核' }],
});
expect(result.ok).toBe(true);
if (result.ok) {
const data = result.data as {
count: number;
date_field: string;
items: Array<{ item_name: string }>;
ui: Array<{ type: string; path?: string; patches?: Array<{ name: string; value: unknown }> }>;
};
expect(data.count).toBe(1);
expect(data.date_field).toBe('delivery_date');
expect(data.items[0].item_name).toBe('土豆');
const nav = data.ui.find((row) => row.type === 'navigate');
expect(nav?.path).toBe('/inspection/review');
const fields = data.ui.find((row) => row.type === 'set_fields');
expect(fields?.patches?.some((p) => p.name === 'status_tab' && p.value === 'inspections')).toBe(true);
}
expect(listInspectionReviews).toHaveBeenCalledWith(
expect.objectContaining({
query: '土豆',
dateField: 'delivery_date',
dateFrom: '2026-09-06',
dateTo: '2026-09-06',
})
);
});
it('routes 照片复核 to inspection-review, 待验收 to inbound-list', () => {
const review = routeModules({
text: '验收照片复核入库照片多少张',
visibleModuleIds: ['navigate', 'order-entry', 'inbound-list', 'inspection-review'],
});
expect(review.modules).toContain('inspection-review');
expect(review.modules).not.toContain('order-entry');
const inbound = routeModules({
text: '入库列表待验收多少条',
visibleModuleIds: ['navigate', 'order-entry', 'inbound-list', 'inspection-review'],
});
expect(inbound.modules).toContain('inbound-list');
expect(inbound.modules).not.toContain('inspection-review');
});
});