import { vi } from "vitest"; // Manual mock for the API layer. Every endpoint resolves with the standard // `{ code: 0, data }` envelope so pages can render without a live backend. // Object envelope covering the shapes pages read: `data.list` for paginated // tables plus the nested arrays detail pages iterate (`details`, etc.). All // default to empty so `.map`/`.length` access never throws. function makeData() { return { list: [], total: 0, records: [], nodes: [], edges: [], details: [], payments: [], receipts: [], items: [], children: [], bolts: [], pans: [], colors: [], }; } const ok = () => Promise.resolve({ code: 0, msg: "ok", success: true, data: makeData() }); export const login = vi.fn(() => Promise.resolve({ code: 0, msg: "ok", data: { token: "test-token", userInfo: { tenantId: "t1", name: "tester" } } }), ); export const getUserInfo = vi.fn(() => Promise.resolve({ code: 0, msg: "ok", data: { name: "tester", menuPaths: [], roles: [] } }), ); export const logout = vi.fn(ok); export const changePassword = vi.fn(ok); export const listUsers = vi.fn(ok); export const getUser = vi.fn(ok); export const createUser = vi.fn(ok); export const updateUser = vi.fn(ok); export const deleteUser = vi.fn(ok); export const updateUserStatus = vi.fn(ok); export const listRoles = vi.fn(ok); export const createRole = vi.fn(ok); export const updateRole = vi.fn(ok); export const deleteRole = vi.fn(ok); export const setRolePermissions = vi.fn(ok); export const listMenus = vi.fn(ok); export const createMenu = vi.fn(ok); export const updateMenu = vi.fn(ok); export const deleteMenu = vi.fn(ok); export const listLogs = vi.fn(ok); export const listConfigs = vi.fn(ok); export const updateConfig = vi.fn(ok); export const listProducts = vi.fn(ok); export const getProduct = vi.fn(ok); export const createProduct = vi.fn(ok); export const updateProduct = vi.fn(ok); export const deleteProduct = vi.fn(ok); export const exportProducts = vi.fn(ok); export const getProductSummary = vi.fn(ok); export const getColorDetail = vi.fn(ok); export const getProductTree = vi.fn(ok); export const listYarns = vi.fn(ok); export const createYarn = vi.fn(ok); export const updateYarn = vi.fn(ok); export const deleteYarn = vi.fn(ok); export const listProductBatches = vi.fn(ok); export const createProductBatch = vi.fn(ok); export const updateProductBatch = vi.fn(ok); export const deleteProductBatch = vi.fn(ok); export const listPans = vi.fn(ok); export const savePans = vi.fn(ok); export const listBolts = vi.fn(ok); export const saveBolts = vi.fn(ok); export const listPanView = vi.fn(ok); export const listBoltView = vi.fn(ok); export const getStockSummary = vi.fn(ok); export const getStockByColor = vi.fn(ok); export const getStockByLocation = vi.fn(ok); export const listStockChecks = vi.fn(ok); export const getStockCheck = vi.fn(ok); export const createStockCheck = vi.fn(ok); export const confirmStockCheck = vi.fn(ok); export const listStockAdjusts = vi.fn(ok); export const getStockAdjust = vi.fn(ok); export const createStockAdjust = vi.fn(ok); export const approveStockAdjust = vi.fn(ok); export const listUpstream = vi.fn(ok); export const listDownstream = vi.fn(ok); export const createRelation = vi.fn(ok); export const updateRelation = vi.fn(ok); export const listRelationHistory = vi.fn(ok); export const listSuppliers = vi.fn(ok); export const getSupplier = vi.fn(ok); export const createSupplier = vi.fn(ok); export const updateSupplier = vi.fn(ok); export const deleteSupplier = vi.fn(ok); export const listPurchaseOrders = vi.fn(ok); export const getPurchaseOrder = vi.fn(ok); export const createPurchaseOrder = vi.fn(ok); export const updatePurchaseOrder = vi.fn(ok); export const confirmPurchaseOrder = vi.fn(ok); export const cancelPurchaseOrder = vi.fn(ok); export const listPurchaseReceipts = vi.fn(ok); export const getPurchaseReceipt = vi.fn(ok); export const createPurchaseReceipt = vi.fn(ok); export const confirmPurchaseReceipt = vi.fn(ok); export const listPurchasePayments = vi.fn(ok); export const createPurchasePayment = vi.fn(ok); export const getPurchaseStatsSummary = vi.fn(ok); export const getPurchaseStatsBySupplier = vi.fn(ok); export const getPurchaseStatsByProduct = vi.fn(ok); export const listInventoryLogs = vi.fn(ok); // ── Production ─────────────────────────────────── export const createProductionPlan = vi.fn(ok); export const listProductionPlan = vi.fn(ok); export const getProductionPlan = vi.fn(() => Promise.resolve({ code: 0, msg: 'ok', success: true, data: { planId: 'plan-1', planCode: 'PP-001', productName: '测试产品', color: '红色', fabricCode: 'FC-01', colorCode: 'CC-01', targetQuantity: '1000', completedQuantity: '0', yarnUsagePerMeter: '0.5', productionPrice: '10', supplierId: 's1', status: 0, remark: '', startTime: '2024-01-01', creator: 'admin', operator: 'admin', createdAt: '2024-01-01', updatedAt: '2024-01-01', tenantId: 't1', yarnRatios: [], processSteps: [], inboundRecords: [], }, }), ); export const confirmPlan = vi.fn(ok); export const createShareLink = vi.fn(ok); export const completeStep = vi.fn(ok); export const createInbound = vi.fn(ok); export const listInbound = vi.fn(ok); export const getShareLinkPlanView = vi.fn(() => Promise.resolve({ code: 0, msg: 'ok', success: true, data: { plan: { planId: 'plan-1', planCode: 'PP-001', productName: '测试产品', color: '红色', fabricCode: 'FC-01', colorCode: 'CC-01', targetQuantity: '1000', completedQuantity: '0', yarnUsagePerMeter: '0.5', productionPrice: '10', supplierId: 's1', status: 1, remark: '', startTime: '2024-01-01', creator: 'admin', operator: 'admin', createdAt: '2024-01-01', updatedAt: '2024-01-01', tenantId: 't1', yarnRatios: [], processSteps: [], inboundRecords: [], }, link: { linkId: 'link-1', tenantId: 't1', planId: 'plan-1', shortCode: 'abc123', token: 'tok', factoryType: 'weaving', hideSensitive: 0, status: 0, clickCount: 1, clickedAt: '', respondedAt: '', rejectReason: '', expiresAt: '2024-12-31', createdBy: 'admin', createdAt: '2024-01-01', updatedAt: '2024-01-01', }, }, }), ); export const clickShareLink = vi.fn(ok); export const confirmShareLink = vi.fn(ok); export const rejectShareLink = vi.fn(ok);