-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
529bc7b
commit 82fc438
Showing
2 changed files
with
77 additions
and
6 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
editor.planx.uk/src/@planx/components/Pay/Public/FeeBreakdown/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { PassportFeeFields } from "./types"; | ||
import { calculateReduction, toFeeBreakdown, toNumber } from "./utils"; | ||
|
||
describe("toNumber() helper function", () => { | ||
it("outputs a number when passed a number", () => { | ||
const input = 12; | ||
const output = toNumber(input); | ||
|
||
expect(output).toEqual(input); | ||
}); | ||
|
||
it("outputs a number when passed a number tuple", () => { | ||
const input: [number] = [12]; | ||
const output = toNumber(input); | ||
|
||
expect(output).toEqual(12); | ||
}); | ||
}); | ||
|
||
describe("calculateReduction() helper function", () => { | ||
it("correctly outputs the reduction when a calculated value is provided", () => { | ||
const input: PassportFeeFields = { | ||
"application.fee.calculated": 100, | ||
"application.fee.payable": 50, | ||
"application.fee.payable.vat": 0, | ||
}; | ||
const reduction = calculateReduction(input); | ||
|
||
expect(reduction).toEqual(50); | ||
}); | ||
|
||
it("defaults to 0 when calculated is 0", () => { | ||
const input: PassportFeeFields = { | ||
"application.fee.calculated": 0, | ||
"application.fee.payable": 100, | ||
"application.fee.payable.vat": 0, | ||
}; | ||
const reduction = calculateReduction(input); | ||
|
||
expect(reduction).toEqual(0); | ||
}); | ||
}); | ||
|
||
describe("toFeeBreakdown() helper function", () => { | ||
it("correctly maps fields", () => { | ||
const input: PassportFeeFields = { | ||
"application.fee.calculated": 100, | ||
"application.fee.payable": 50, | ||
"application.fee.payable.vat": 10, | ||
}; | ||
|
||
const output = toFeeBreakdown(input); | ||
|
||
expect(output.applicationFee).toEqual(input["application.fee.calculated"]); | ||
expect(output.total).toEqual(input["application.fee.payable"]); | ||
expect(output.vat).toEqual(input["application.fee.payable.vat"]); | ||
expect(output.reduction).toEqual(50); | ||
}); | ||
|
||
it("sets applicationFee to payable amount if no calculated value is provided", () => { | ||
const input: PassportFeeFields = { | ||
"application.fee.calculated": 0, | ||
"application.fee.payable": 50, | ||
"application.fee.payable.vat": 10, | ||
}; | ||
|
||
const output = toFeeBreakdown(input); | ||
|
||
expect(output.applicationFee).toEqual(input["application.fee.payable"]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters