hotfix: Set proper minimum and maximum defaults that can be entered in billing input (#6842)

This commit is contained in:
sp.wack
2025-02-20 17:58:23 +04:00
committed by GitHub
parent f869ad995c
commit 3f8bc8a7ea
3 changed files with 13 additions and 5 deletions

View File

@@ -149,7 +149,7 @@ describe("PaymentForm", () => {
renderPaymentForm();
const topUpInput = await screen.findByTestId("top-up-input");
await user.type(topUpInput, "20"); // test assumes the minimum is 25
await user.type(topUpInput, "9"); // test assumes the minimum is 10
const topUpButton = screen.getByText("Add credit");
await user.click(topUpButton);

View File

@@ -24,9 +24,15 @@ describe("amountIsValid", () => {
});
test("when an amount less than the minimum is passed", () => {
// test assumes the minimum is 25
expect(amountIsValid("24")).toBe(false);
expect(amountIsValid("24.99")).toBe(false);
// test assumes the minimum is 10
expect(amountIsValid("9")).toBe(false);
expect(amountIsValid("9.99")).toBe(false);
});
test("when an amount more than the maximum is passed", () => {
// test assumes the minimum is 25000
expect(amountIsValid("25001")).toBe(false);
expect(amountIsValid("25000.01")).toBe(false);
});
});
});

View File

@@ -1,10 +1,12 @@
const MINIMUM_AMOUNT = 25;
const MINIMUM_AMOUNT = 10;
const MAXIMUM_AMOUNT = 25_000;
export const amountIsValid = (amount: string) => {
const float = parseFloat(amount);
if (Number.isNaN(float)) return false;
if (float < 0) return false;
if (float < MINIMUM_AMOUNT) return false;
if (float > MAXIMUM_AMOUNT) return false;
return true;
};