refactor(api): extract rate card write support
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildRateCardCreateData,
|
||||
buildRateCardLineCreateData,
|
||||
buildRateCardLineUpdateData,
|
||||
buildRateCardListWhere,
|
||||
buildRateCardUpdateData,
|
||||
} from "../router/rate-card-write-support.js";
|
||||
|
||||
describe("rate card write support", () => {
|
||||
it("builds rate card list filters including effective date windows", () => {
|
||||
expect(buildRateCardListWhere({
|
||||
isActive: true,
|
||||
clientId: "client_1",
|
||||
search: "Standard",
|
||||
effectiveAt: new Date("2026-05-15T00:00:00.000Z"),
|
||||
})).toEqual({
|
||||
isActive: true,
|
||||
clientId: "client_1",
|
||||
name: { contains: "Standard", mode: "insensitive" },
|
||||
OR: [
|
||||
{ effectiveFrom: null },
|
||||
{ effectiveFrom: { lte: new Date("2026-05-15T00:00:00.000Z") } },
|
||||
],
|
||||
AND: [
|
||||
{
|
||||
OR: [
|
||||
{ effectiveTo: null },
|
||||
{ effectiveTo: { gte: new Date("2026-05-15T00:00:00.000Z") } },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("builds nested create data for a rate card and its lines", () => {
|
||||
expect(buildRateCardCreateData({
|
||||
name: "Q1 2026",
|
||||
currency: "EUR",
|
||||
effectiveFrom: new Date("2026-01-01T00:00:00.000Z"),
|
||||
clientId: "client_1",
|
||||
lines: [{
|
||||
roleId: "role_1",
|
||||
chapter: "Delivery",
|
||||
costRateCents: 9500,
|
||||
billRateCents: 14000,
|
||||
attributes: { level: "senior" },
|
||||
}],
|
||||
})).toEqual({
|
||||
name: "Q1 2026",
|
||||
currency: "EUR",
|
||||
effectiveFrom: new Date("2026-01-01T00:00:00.000Z"),
|
||||
clientId: "client_1",
|
||||
lines: {
|
||||
create: [{
|
||||
roleId: "role_1",
|
||||
chapter: "Delivery",
|
||||
costRateCents: 9500,
|
||||
billRateCents: 14000,
|
||||
attributes: { level: "senior" },
|
||||
}],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("builds standalone line create data with rate card id", () => {
|
||||
expect(buildRateCardLineCreateData("rc_1", {
|
||||
chapter: "Delivery",
|
||||
costRateCents: 8000,
|
||||
attributes: {},
|
||||
})).toEqual({
|
||||
rateCardId: "rc_1",
|
||||
chapter: "Delivery",
|
||||
costRateCents: 8000,
|
||||
attributes: {},
|
||||
});
|
||||
});
|
||||
|
||||
it("builds sparse rate card updates", () => {
|
||||
expect(buildRateCardUpdateData({
|
||||
name: "Updated 2026",
|
||||
isActive: false,
|
||||
})).toEqual({
|
||||
name: "Updated 2026",
|
||||
isActive: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("builds line updates including role disconnect semantics", () => {
|
||||
expect(buildRateCardLineUpdateData({
|
||||
roleId: null,
|
||||
costRateCents: 12345,
|
||||
attributes: { region: "de" },
|
||||
})).toEqual({
|
||||
role: { disconnect: true },
|
||||
costRateCents: 12345,
|
||||
attributes: { region: "de" },
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user