mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
119 lines
3.5 KiB
TypeScript
119 lines
3.5 KiB
TypeScript
import { assertEimsInvoiceConfig, buildEimsContext } from "./eims-invoice-context";
|
|
import { eimsConfig } from "./eims-test-fixtures";
|
|
|
|
const SESSION = { systemNumber: "B0360154BA", systemType: "SYS" };
|
|
|
|
describe("assertEimsInvoiceConfig — charge-type overrides", () => {
|
|
it("passes when EIMS_TAX_CODE_BY_CHARGE_TYPE and _RATE_ list the same charge types", () => {
|
|
expect(() =>
|
|
assertEimsInvoiceConfig(
|
|
eimsConfig({
|
|
invoice: {
|
|
...eimsConfig().invoice,
|
|
taxCodeByChargeType: { RAIL_FREIGHT: "VAT0" },
|
|
taxRateByChargeType: { RAIL_FREIGHT: "0" },
|
|
},
|
|
}),
|
|
),
|
|
).not.toThrow();
|
|
});
|
|
|
|
it("throws when a charge type has a code but no rate, or a rate but no code", () => {
|
|
expect(() =>
|
|
assertEimsInvoiceConfig(
|
|
eimsConfig({
|
|
invoice: {
|
|
...eimsConfig().invoice,
|
|
taxCodeByChargeType: { RAIL_FREIGHT: "VAT0" },
|
|
taxRateByChargeType: {},
|
|
},
|
|
}),
|
|
),
|
|
).toThrow(/mismatched: RAIL_FREIGHT/);
|
|
|
|
expect(() =>
|
|
assertEimsInvoiceConfig(
|
|
eimsConfig({
|
|
invoice: {
|
|
...eimsConfig().invoice,
|
|
taxCodeByChargeType: {},
|
|
taxRateByChargeType: { RAIL_FREIGHT: "0" },
|
|
},
|
|
}),
|
|
),
|
|
).toThrow(/mismatched: RAIL_FREIGHT/);
|
|
});
|
|
|
|
it("throws when a rate/excise/discount override is not a number", () => {
|
|
expect(() =>
|
|
assertEimsInvoiceConfig(
|
|
eimsConfig({
|
|
invoice: {
|
|
...eimsConfig().invoice,
|
|
taxCodeByChargeType: { RAIL_FREIGHT: "VAT0" },
|
|
taxRateByChargeType: { RAIL_FREIGHT: "not-a-number" },
|
|
},
|
|
}),
|
|
),
|
|
).toThrow(/EIMS_TAX_RATE_BY_CHARGE_TYPE\[RAIL_FREIGHT\]/);
|
|
|
|
expect(() =>
|
|
assertEimsInvoiceConfig(
|
|
eimsConfig({ invoice: { ...eimsConfig().invoice, discountByChargeType: { X: "abc" } } }),
|
|
),
|
|
).toThrow(/EIMS_DISCOUNT_BY_CHARGE_TYPE\[X\]/);
|
|
});
|
|
});
|
|
|
|
describe("buildEimsContext — taxForLine", () => {
|
|
const input = { documentNumber: "24", invoiceCounter: 7, previousIrn: "", session: SESSION };
|
|
const line = (chargeType: string) => ({ chargeType, quantity: 1, unitRate: 100, amount: 100 });
|
|
|
|
it("uses the per-chargeType override when one is configured", () => {
|
|
const context = buildEimsContext(
|
|
eimsConfig({
|
|
invoice: {
|
|
...eimsConfig().invoice,
|
|
taxCode: "VAT15",
|
|
taxRatePercent: 15,
|
|
taxCodeByChargeType: { RAIL_FREIGHT: "VAT0" },
|
|
taxRateByChargeType: { RAIL_FREIGHT: "0" },
|
|
exciseByChargeType: { RAIL_FREIGHT: "5" },
|
|
discountByChargeType: { RAIL_FREIGHT: "10" },
|
|
},
|
|
}),
|
|
input,
|
|
);
|
|
|
|
expect(context.taxForLine(line("RAIL_FREIGHT"), 1)).toEqual({
|
|
code: "VAT0",
|
|
ratePercent: 0,
|
|
exciseTaxValue: 5,
|
|
discount: 10,
|
|
});
|
|
});
|
|
|
|
it("falls back to the invoice-wide default for a charge type with no override", () => {
|
|
const context = buildEimsContext(
|
|
eimsConfig({
|
|
invoice: {
|
|
...eimsConfig().invoice,
|
|
taxCode: "VAT15",
|
|
taxRatePercent: 15,
|
|
exciseTaxValue: 0,
|
|
taxCodeByChargeType: { RAIL_FREIGHT: "VAT0" },
|
|
taxRateByChargeType: { RAIL_FREIGHT: "0" },
|
|
},
|
|
}),
|
|
input,
|
|
);
|
|
|
|
expect(context.taxForLine(line("HANDLING"), 1)).toEqual({
|
|
code: "VAT15",
|
|
ratePercent: 15,
|
|
exciseTaxValue: 0,
|
|
discount: 0,
|
|
});
|
|
});
|
|
});
|