78 lines
2.2 KiB
TypeScript
78 lines
2.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildCalculationRuleCreateData,
|
|
buildCalculationRuleUpdateData,
|
|
} from "../router/calculation-rule-support.js";
|
|
|
|
describe("calculation-rule-support", () => {
|
|
it("buildCalculationRuleCreateData omits undefined optional fields", () => {
|
|
const result = buildCalculationRuleCreateData({
|
|
name: "Sick Days",
|
|
triggerType: "SICK",
|
|
costEffect: "ZERO",
|
|
chargeabilityEffect: "SKIP",
|
|
priority: 0,
|
|
isActive: true,
|
|
});
|
|
|
|
expect(result).toEqual({
|
|
name: "Sick Days",
|
|
triggerType: "SICK",
|
|
costEffect: "ZERO",
|
|
chargeabilityEffect: "SKIP",
|
|
priority: 0,
|
|
isActive: true,
|
|
});
|
|
expect(result).not.toHaveProperty("description");
|
|
expect(result).not.toHaveProperty("projectId");
|
|
expect(result).not.toHaveProperty("orderType");
|
|
expect(result).not.toHaveProperty("costReductionPercent");
|
|
});
|
|
|
|
it("buildCalculationRuleCreateData keeps provided optional fields", () => {
|
|
const result = buildCalculationRuleCreateData({
|
|
name: "Vacation Discount",
|
|
description: "Reduce cost for vacation",
|
|
triggerType: "VACATION",
|
|
projectId: "project_1",
|
|
orderType: "CHARGEABLE",
|
|
costEffect: "REDUCE",
|
|
costReductionPercent: 25,
|
|
chargeabilityEffect: "COUNT",
|
|
priority: 10,
|
|
isActive: false,
|
|
});
|
|
|
|
expect(result).toEqual({
|
|
name: "Vacation Discount",
|
|
description: "Reduce cost for vacation",
|
|
triggerType: "VACATION",
|
|
projectId: "project_1",
|
|
orderType: "CHARGEABLE",
|
|
costEffect: "REDUCE",
|
|
costReductionPercent: 25,
|
|
chargeabilityEffect: "COUNT",
|
|
priority: 10,
|
|
isActive: false,
|
|
});
|
|
});
|
|
|
|
it("buildCalculationRuleUpdateData only includes provided fields and preserves falsy values", () => {
|
|
const result = buildCalculationRuleUpdateData({
|
|
description: "",
|
|
costReductionPercent: 0,
|
|
priority: 0,
|
|
isActive: false,
|
|
});
|
|
|
|
expect(result).toEqual({
|
|
description: "",
|
|
costReductionPercent: 0,
|
|
priority: 0,
|
|
isActive: false,
|
|
});
|
|
expect(result).not.toHaveProperty("name");
|
|
expect(result).not.toHaveProperty("projectId");
|
|
});
|
|
});
|