refactor(api): share rate card support shapes

This commit is contained in:
2026-03-31 14:30:29 +02:00
parent ab46eca8b3
commit 85b4121253
3 changed files with 166 additions and 21 deletions
@@ -1,13 +1,61 @@
import { describe, expect, it } from "vitest";
import {
buildRateCardCreateAuditAfter,
buildRateCardCreateData,
buildRateCardLineCreateAuditAfter,
buildRateCardLineCreateData,
buildRateCardLineUpdateData,
buildRateCardListWhere,
buildRateCardReplaceLinesAuditAfter,
buildRateCardUpdateData,
rateCardCreateInclude,
rateCardDetailInclude,
rateCardLineOrderBy,
rateCardSummaryInclude,
} from "../router/rate-card-write-support.js";
describe("rate card write support", () => {
it("exposes shared include definitions", () => {
expect(rateCardSummaryInclude).toEqual({
_count: { select: { lines: true } },
client: { select: { id: true, name: true, code: true } },
});
expect(rateCardLineOrderBy).toEqual([
{ chapter: "asc" },
{ seniority: "asc" },
{ createdAt: "asc" },
]);
expect(rateCardDetailInclude).toEqual({
client: { select: { id: true, name: true, code: true } },
lines: {
select: {
id: true,
rateCardId: true,
roleId: true,
chapter: true,
seniority: true,
location: true,
workType: true,
serviceGroup: true,
costRateCents: true,
billRateCents: true,
machineRateCents: true,
attributes: true,
role: { select: { id: true, name: true } },
},
orderBy: rateCardLineOrderBy,
},
});
expect(rateCardCreateInclude).toEqual({
lines: {
select: rateCardDetailInclude.lines.select,
},
});
});
it("builds rate card list filters including effective date windows", () => {
expect(buildRateCardListWhere({
isActive: true,
@@ -97,4 +145,37 @@ describe("rate card write support", () => {
attributes: { region: "de" },
});
});
it("builds compact audit payloads", () => {
expect(buildRateCardCreateAuditAfter({
name: "Q1 2026",
currency: "EUR",
lines: [
{ costRateCents: 9500, attributes: {} },
{ costRateCents: 8000, attributes: {} },
],
})).toEqual({
name: "Q1 2026",
currency: "EUR",
lineCount: 2,
});
expect(buildRateCardLineCreateAuditAfter({
rateCardId: "rc_1",
line: {
chapter: "Delivery",
costRateCents: 9500,
billRateCents: 14000,
},
})).toEqual({
rateCardId: "rc_1",
chapter: "Delivery",
costRateCents: 9500,
billRateCents: 14000,
});
expect(buildRateCardReplaceLinesAuditAfter(3)).toEqual({
replacedLineCount: 3,
});
});
});