Skip to content

Commit

Permalink
test: useFeeBreakdown()
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Dec 5, 2024
1 parent a8f8c85 commit fb74c41
Showing 1 changed file with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ describe("useFeeBreakdown() hook", () => {
reduction: 200,
vat: 160,
},
exemptions: [],
reductions: [],
});
});

Expand All @@ -54,9 +56,81 @@ describe("useFeeBreakdown() hook", () => {
total: 800,
reduction: 200,
vat: 160,
}
},
exemptions: [],
reductions: [],
});
});

it("parses 'true' reduction values to a list of keys", () => {
const mockPassportData = {
"application.fee.calculated": 1000,
"application.fee.payable": 800,
"application.fee.payable.vat": 160,
"application.fee.reduction.reasonOne": ["true"],
"application.fee.reduction.reasonTwo": ["true"],
};

vi.mocked(useStore).mockReturnValue([mockPassportData, "test-session"]);

const result = useFeeBreakdown();

expect(result?.reductions).toHaveLength(2);
expect(result?.reductions).toEqual(
expect.arrayContaining(["reasonOne", "reasonTwo"])
);
});

it("does not parse 'false' reduction values to a list of keys", () => {
const mockPassportData = {
"application.fee.calculated": 1000,
"application.fee.payable": 800,
"application.fee.payable.vat": 160,
"application.fee.reduction.reasonOne": ["false"],
"application.fee.reduction.reasonTwo": ["false"],
};

vi.mocked(useStore).mockReturnValue([mockPassportData, "test-session"]);

const result = useFeeBreakdown();

expect(result?.reductions).toHaveLength(0);
});

it("parses 'true' exemption values to a list of keys", () => {
const mockPassportData = {
"application.fee.calculated": 1000,
"application.fee.payable": 800,
"application.fee.payable.vat": 160,
"application.fee.exemption.reasonOne": ["true"],
"application.fee.exemption.reasonTwo": ["true"],
};

vi.mocked(useStore).mockReturnValue([mockPassportData, "test-session"]);

const result = useFeeBreakdown();

expect(result?.exemptions).toHaveLength(2);
expect(result?.exemptions).toEqual(
expect.arrayContaining(["reasonOne", "reasonTwo"])
);
});

it("does not parse 'false' exemption values to a list of keys", () => {
const mockPassportData = {
"application.fee.calculated": 1000,
"application.fee.payable": 800,
"application.fee.payable.vat": 160,
"application.fee.exemption.reasonOne": ["false"],
"application.fee.exemption.reasonTwo": ["false"],
};

vi.mocked(useStore).mockReturnValue([mockPassportData, "test-session"]);

const result = useFeeBreakdown();

expect(result?.exemptions).toHaveLength(0);
});
});

describe("invalid inputs", () => {
Expand Down

0 comments on commit fb74c41

Please sign in to comment.