完善借款、编号、付款与预算并发及验收(09-06-release-gate-integrity)
汇总已落盘的借款本金与还款、兼容历史编号的周期化编号、付款责任与回单核验、报销进度和排序、PWA/采购事务、错误原因与日期校验及ERP退役。 统一共享预算池锁序和锁后判断,恢复差旅原预算选择,补原因码固定夹具及反向完整性检查。 纳入配套迁移、测试、受管QA、分层验收合同、规约及任务记录;原始证据留在ignored artifacts。 关联任务:09-17-company-loan-principal-repayment、09-17-erp-exclusive-retirement、09-18-reimbursement-periodic-numbering、09-08-reimbursement-payment-closeout、09-18-local-concurrency-product-fixes、09-19-budget-pool-concurrency、09-05-error-explainability-payment-readiness。 预算补审由Claude定向验证2文件928项通过,原4446/28及r6结果仍仅对应各自历史输入;本轮未重跑测试。 完整新候选门禁、R1真实入口接入与12项公网义务仍开放。生产编号未启用、差旅仍冻结;不推送、不部署,不宣称发布资格。
这个提交包含在:
@@ -1,3 +1,4 @@
|
||||
const { enableNumbering } = require("../helpers/activeNumbering");
|
||||
const fs = require("node:fs/promises");
|
||||
const os = require("node:os");
|
||||
const path = require("node:path");
|
||||
@@ -11,31 +12,22 @@ const featureFlags = require("../../../src/services/featureFlags");
|
||||
const notifications = require("../../../src/services/notifications");
|
||||
const email = require("../../../src/services/email");
|
||||
const notificationDispatcher = require("../../../src/services/notificationDispatcher");
|
||||
const erpJournal = require("../../../src/services/integrations/erpJournal");
|
||||
const { encryptStringOrThrow } = require("../../../src/services/crypto");
|
||||
|
||||
const evaluateFeatureFlagMock = vi.fn();
|
||||
const createNotificationsWithRecordsMock = vi.fn(async () => []);
|
||||
const sendNotificationEmailSafeMock = vi.fn(async () => undefined);
|
||||
const flushNotificationDispatchTasksMock = vi.fn(async () => undefined);
|
||||
const enqueueReimbursementJournalExportMock = vi.fn(async () => ({
|
||||
id: "outbox-1",
|
||||
status: "pending",
|
||||
duplicated: false,
|
||||
requeued: false,
|
||||
}));
|
||||
|
||||
const originalEvaluateFeatureFlag = featureFlags.evaluateFeatureFlag;
|
||||
const originalCreateNotificationsWithRecords = notifications.createNotificationsWithRecords;
|
||||
const originalSendNotificationEmailSafe = email.sendNotificationEmailSafe;
|
||||
const originalFlushNotificationDispatchTasks = notificationDispatcher.flushNotificationDispatchTasks;
|
||||
const originalEnqueueReimbursementJournalExport = erpJournal.enqueueReimbursementJournalExport;
|
||||
|
||||
featureFlags.evaluateFeatureFlag = evaluateFeatureFlagMock;
|
||||
notifications.createNotificationsWithRecords = createNotificationsWithRecordsMock;
|
||||
email.sendNotificationEmailSafe = sendNotificationEmailSafeMock;
|
||||
notificationDispatcher.flushNotificationDispatchTasks = flushNotificationDispatchTasksMock;
|
||||
erpJournal.enqueueReimbursementJournalExport = enqueueReimbursementJournalExportMock;
|
||||
|
||||
delete require.cache[require.resolve("../../../src/routes/paymentBatches")];
|
||||
const paymentBatchesRoutes = require("../../../src/routes/paymentBatches");
|
||||
@@ -291,6 +283,7 @@ function buildPrisma(options = {}) {
|
||||
};
|
||||
|
||||
const tx = {
|
||||
businessNumberPolicy: { findUnique: vi.fn(async () => null) },
|
||||
paymentReceiptClaim: { count: vi.fn(async () => 0), findMany: vi.fn(async () => []), create: vi.fn() },
|
||||
paymentReceiptTransactionAlias: { count: vi.fn(async () => 0), findMany: vi.fn(async () => []), create: vi.fn() },
|
||||
paymentReceiptManualProposal: { findMany: vi.fn(async () => []) },
|
||||
@@ -505,6 +498,7 @@ function buildPrisma(options = {}) {
|
||||
employee: {
|
||||
findMany: vi.fn(async () => state.employees.map((employee) => ({ ...employee }))),
|
||||
},
|
||||
notification: { findMany: vi.fn(async () => []) },
|
||||
$executeRaw: vi.fn(async () => 0),
|
||||
$queryRaw: vi.fn(async (query, ...values) => {
|
||||
const text = Array.isArray(query) ? query.join(" ") : String(query?.sql ?? query ?? "");
|
||||
@@ -808,7 +802,6 @@ async function buildApp(options = {}) {
|
||||
};
|
||||
const paymentBatchEnabled = options.paymentBatchEnabled ?? true;
|
||||
const paymentBatchAllowedDepartmentIds = options.paymentBatchAllowedDepartmentIds ?? null;
|
||||
const erpSyncEnabled = options.erpSyncEnabled ?? true;
|
||||
|
||||
evaluateFeatureFlagMock.mockImplementation(async ({ flagKey, departmentId = null, strictDepartment = true }) => {
|
||||
if (flagKey === featureFlags.FEATURE_FLAG_KEYS.paymentBatch) {
|
||||
@@ -841,16 +834,6 @@ async function buildApp(options = {}) {
|
||||
requiresDepartment: false,
|
||||
};
|
||||
}
|
||||
if (flagKey === featureFlags.FEATURE_FLAG_KEYS.erpSync) {
|
||||
return {
|
||||
flagKey,
|
||||
enabled: erpSyncEnabled,
|
||||
reason: erpSyncEnabled ? "mock_on" : "mock_off",
|
||||
envEnabled: erpSyncEnabled,
|
||||
matchedDepartmentId: null,
|
||||
requiresDepartment: false,
|
||||
};
|
||||
}
|
||||
return {
|
||||
flagKey,
|
||||
enabled: false,
|
||||
@@ -924,10 +907,52 @@ afterAll(() => {
|
||||
notifications.createNotificationsWithRecords = originalCreateNotificationsWithRecords;
|
||||
email.sendNotificationEmailSafe = originalSendNotificationEmailSafe;
|
||||
notificationDispatcher.flushNotificationDispatchTasks = originalFlushNotificationDispatchTasks;
|
||||
erpJournal.enqueueReimbursementJournalExport = originalEnqueueReimbursementJournalExport;
|
||||
});
|
||||
|
||||
describe("payment batch reimbursement routes", () => {
|
||||
it.each(["list", "detail"])("sorts legacy and monthly reimbursement numbers without mutating payment order: %s", async (view) => {
|
||||
const { app, prisma, state, tempDir } = await buildApp();
|
||||
const original = state.batch.items[0];
|
||||
const entries = [
|
||||
{ suffix: "0003", code: "BX-20260917-10", amount: "30.00" },
|
||||
{ suffix: "0002", code: "BX-20260917-2", amount: "20.00" },
|
||||
{ suffix: "0001", code: "BX-20260917-2", amount: "10.00" },
|
||||
{ suffix: "0006", code: "BX-202609-10000", amount: "60.00" },
|
||||
{ suffix: "0005", code: "BX-202609-0010", amount: "50.00" },
|
||||
{ suffix: "0004", code: "BX-202609-0002", amount: "40.00" },
|
||||
].map(({ suffix, code, amount }) => Object.freeze({ ...original,
|
||||
id: `66666666-6666-4666-8666-66666666${suffix}`, entity_code: code, amount,
|
||||
}));
|
||||
const batch = { ...state.batch, items: Object.freeze(entries) };
|
||||
prisma.paymentBatch.findUnique.mockResolvedValue(batch);
|
||||
prisma.paymentBatch.findMany.mockResolvedValue([batch]);
|
||||
try {
|
||||
const response = await app.inject({ method: "GET", url: view === "list" ? "/api/payment-batches" : `/api/payment-batches/${BATCH_ID}`, headers: { authorization: "Bearer synthetic-test" } });
|
||||
expect(response.statusCode).toBe(200);
|
||||
const result = response.json().data;
|
||||
const items = view === "list" ? result.items[0].items : result.item.items;
|
||||
expect(items.map((item) => [item.id, item.entityCode, item.amount])).toEqual(
|
||||
[entries[5], entries[4], entries[3], entries[2], entries[1], entries[0]].map((item) => [item.id, item.entity_code, item.amount]),
|
||||
);
|
||||
expect(batch.items).toEqual(entries);
|
||||
expect(prisma.paymentBatch.update).not.toHaveBeenCalled();
|
||||
expect(prisma.auditLog.create).not.toHaveBeenCalled();
|
||||
} finally { await app.close(); await fs.rm(tempDir, { recursive: true, force: true }); }
|
||||
});
|
||||
|
||||
it("keeps historical travel response order unchanged", async () => {
|
||||
const { app, prisma, state, tempDir } = await buildApp();
|
||||
const entries = ["TRAVEL-10", "TRAVEL-2"].map((entity_code, index) => ({
|
||||
...state.batch.items[0], id: `travel-item-${index}`, entity_id: TRAVEL_ORDER_ID, entity_code,
|
||||
}));
|
||||
prisma.paymentBatch.findMany.mockResolvedValue([{ ...state.batch, entity_type: "travel_order", items: entries }]);
|
||||
try {
|
||||
const response = await app.inject({ method: "GET", url: "/api/payment-batches", headers: { authorization: "Bearer synthetic-test" } });
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json().data.items[0].items.map((item) => item.entityCode)).toEqual(["TRAVEL-10", "TRAVEL-2"]);
|
||||
} finally { await app.close(); await fs.rm(tempDir, { recursive: true, force: true }); }
|
||||
});
|
||||
|
||||
it.each(["legacy", "superseded", "amount", "voided", "reused"])("blocks bank execution for %s evidence", async (condition) => {
|
||||
const { app, state, tx, tempDir } = await buildApp({ verifiedReceipt: condition !== "legacy" });
|
||||
if (condition === "superseded") state.receiptAttachments[0].receipt_ocr_version += 1;
|
||||
@@ -1167,20 +1192,6 @@ describe("payment batch reimbursement routes", () => {
|
||||
updated_by: ACTOR_ID,
|
||||
}),
|
||||
});
|
||||
expect(enqueueReimbursementJournalExportMock).toHaveBeenCalledWith(
|
||||
expect.any(Object),
|
||||
expect.objectContaining({
|
||||
paymentBatchEnabled: true,
|
||||
erpSyncEnabled: true,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
actorId: ACTOR_ID,
|
||||
reimbursement: expect.objectContaining({
|
||||
id: REIMBURSEMENT_ID,
|
||||
status: "paid",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(createNotificationsWithRecordsMock).toHaveBeenCalledWith(
|
||||
expect.any(Object),
|
||||
expect.objectContaining({
|
||||
@@ -1919,7 +1930,7 @@ describe("payment batch reimbursement routes", () => {
|
||||
expect(tx.paymentBatch.create.mock.calls[0][0].data.name).toBe("付款批次编号验证");
|
||||
expect(tx.paymentBatch.create.mock.calls[1][0].data.name).toBe("付款批次编号验证");
|
||||
const advisoryLockCalls = tx.$executeRaw.mock.calls.filter(([query]) =>
|
||||
Array.isArray(query) && query.join(" ").includes("pg_advisory_xact_lock"),
|
||||
Array.isArray(query) && query.join(" ").includes("pg_advisory_xact_lock("),
|
||||
);
|
||||
expect(advisoryLockCalls).toHaveLength(2);
|
||||
|
||||
@@ -2070,7 +2081,6 @@ describe("payment batch reimbursement routes", () => {
|
||||
expect(response.json().error.details.receiptAttachments).toBe("bank_receipt_required");
|
||||
expect(state.batch.status).toBe("reviewed");
|
||||
expect(state.reimbursement.status).toBe("approved");
|
||||
expect(enqueueReimbursementJournalExportMock).not.toHaveBeenCalled();
|
||||
|
||||
await app.close();
|
||||
});
|
||||
@@ -2131,7 +2141,6 @@ describe("payment batch reimbursement routes", () => {
|
||||
expect(tx.paymentBatchItem.update).not.toHaveBeenCalled();
|
||||
expect(tx.paymentBatch.update).not.toHaveBeenCalled();
|
||||
expect(tx.auditLog.create).not.toHaveBeenCalled();
|
||||
expect(enqueueReimbursementJournalExportMock).not.toHaveBeenCalled();
|
||||
expect(createNotificationsWithRecordsMock).not.toHaveBeenCalled();
|
||||
|
||||
await app.close();
|
||||
@@ -2161,7 +2170,6 @@ describe("payment batch reimbursement routes", () => {
|
||||
expect(state.batch.status).toBe("reviewed");
|
||||
expect(state.batch.items[0].status).toBe("pending");
|
||||
expect(tx.auditLog.create).not.toHaveBeenCalled();
|
||||
expect(enqueueReimbursementJournalExportMock).not.toHaveBeenCalled();
|
||||
expect(createNotificationsWithRecordsMock).not.toHaveBeenCalled();
|
||||
|
||||
await app.close();
|
||||
@@ -2186,7 +2194,6 @@ describe("payment batch reimbursement routes", () => {
|
||||
expect(tx.entityRiskFlag.create).not.toHaveBeenCalled();
|
||||
expect(tx.paymentBatch.update).not.toHaveBeenCalled();
|
||||
expect(tx.auditLog.create).not.toHaveBeenCalled();
|
||||
expect(enqueueReimbursementJournalExportMock).not.toHaveBeenCalled();
|
||||
expect(createNotificationsWithRecordsMock).not.toHaveBeenCalled();
|
||||
|
||||
await app.close();
|
||||
@@ -2894,14 +2901,6 @@ describe("payment batch reimbursement routes", () => {
|
||||
}),
|
||||
}),
|
||||
});
|
||||
expect(enqueueReimbursementJournalExportMock).toHaveBeenCalledTimes(1);
|
||||
expect(enqueueReimbursementJournalExportMock).toHaveBeenCalledWith(
|
||||
expect.any(Object),
|
||||
expect.any(Object),
|
||||
expect.objectContaining({
|
||||
reimbursement: expect.objectContaining({ id: REIMBURSEMENT_ID }),
|
||||
}),
|
||||
);
|
||||
expect(createNotificationsWithRecordsMock).toHaveBeenCalledTimes(1);
|
||||
expect(createNotificationsWithRecordsMock).toHaveBeenCalledWith(
|
||||
expect.any(Object),
|
||||
@@ -2933,7 +2932,6 @@ describe("payment batch reimbursement routes", () => {
|
||||
expect(state.batch.items[0].failure_code).toBe("VALID_001");
|
||||
expect(state.reimbursement.status).toBe("reviewing");
|
||||
expect(state.invoice.status).toBe("bound");
|
||||
expect(enqueueReimbursementJournalExportMock).not.toHaveBeenCalled();
|
||||
expect(createNotificationsWithRecordsMock).not.toHaveBeenCalled();
|
||||
|
||||
await app.close();
|
||||
@@ -3277,3 +3275,14 @@ describe("payment batch reimbursement routes", () => {
|
||||
await app.close();
|
||||
});
|
||||
});
|
||||
|
||||
it("creates an annual payment batch retaining an old reimbursement source code", async () => {
|
||||
const { app, tx, tempDir } = await buildApp(); enableNumbering(tx);
|
||||
try {
|
||||
const response = await app.inject({ method: "POST", url: "/api/payment-batches", headers: { authorization: "Bearer test" },
|
||||
payload: { entityType: "reimbursement", entityIds: [REIMBURSEMENT_ID] } });
|
||||
expect(response.statusCode).toBe(201);
|
||||
expect(tx.paymentBatch.create.mock.calls[0][0].data.batch_no).toMatch(/^PB-\d{4}-0001$/);
|
||||
expect(tx.paymentBatchItem.create.mock.calls[0][0].data.entity_code).toMatch(/^BX-/);
|
||||
} finally { await app.close(); await fs.rm(tempDir, { recursive: true, force: true }); }
|
||||
});
|
||||
|
||||
在新工单中引用
屏蔽一个用户