wallet-core/packages/merchant-backoffice-ui/src/utils/regex.test.ts

88 lines
2.4 KiB
TypeScript
Raw Normal View History

/*
This file is part of GNU Taler
2022-12-16 20:59:37 +01:00
(C) 2021-2023 Taler Systems S.A.
GNU Taler is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
2023-01-03 14:01:04 +01:00
*
* @author Sebastian Javier Marchano (sebasjm)
*/
import { expect } from "chai";
2022-11-04 14:24:29 +01:00
import { AMOUNT_REGEX, PAYTO_REGEX } from "../../src/utils/constants.js";
2023-01-03 14:01:04 +01:00
describe("payto uri format", () => {
const valids = [
2023-01-03 14:01:04 +01:00
"payto://iban/DE75512108001245126199?amount=EUR:200.0&message=hello",
"payto://ach/122000661/1234",
"payto://upi/alice@example.com?receiver-name=Alice&amount=INR:200",
"payto://void/?amount=EUR:10.5",
"payto://ilp/g.acme.bob",
];
2023-01-03 14:01:04 +01:00
it("should be valid", () => {
valids.forEach((v) => expect(v).match(PAYTO_REGEX));
});
const invalids = [
// has two question marks
2023-01-03 14:01:04 +01:00
"payto://iban/DE75?512108001245126199?amount=EUR:200.0&message=hello",
// has a space
2023-01-03 14:01:04 +01:00
"payto://ach /122000661/1234",
// has a space
2023-01-03 14:01:04 +01:00
"payto://upi/alice@ example.com?receiver-name=Alice&amount=INR:200",
// invalid field name (mount instead of amount)
2023-01-03 14:01:04 +01:00
"payto://void/?mount=EUR:10.5",
// payto:// is incomplete
2023-01-03 14:01:04 +01:00
"payto: //ilp/g.acme.bob",
];
2023-01-03 14:01:04 +01:00
it("should not be valid", () => {
invalids.forEach((v) => expect(v).not.match(PAYTO_REGEX));
});
2023-01-03 14:01:04 +01:00
});
2023-01-03 14:01:04 +01:00
describe("amount format", () => {
const valids = [
2023-01-03 14:01:04 +01:00
"ARS:10",
"COL:10.2",
"UY:1,000.2",
"ARS:10.123,123",
"ARS:1,000,000",
"ARSCOL:10",
"THISISTHEMOTHERCOIN:1,000,000.123,123",
];
2023-01-03 14:01:04 +01:00
it("should be valid", () => {
valids.forEach((v) => expect(v).match(AMOUNT_REGEX));
});
const invalids = [
//no currency name
2023-01-03 14:01:04 +01:00
":10",
//use . instead of ,
2023-01-03 14:01:04 +01:00
"ARS:1.000.000",
//currency name with numbers
2023-01-03 14:01:04 +01:00
"1ARS:10",
//currency name with numbers
2023-01-03 14:01:04 +01:00
"AR5:10",
//missing value
2023-01-03 14:01:04 +01:00
"USD:",
];
2023-01-03 14:01:04 +01:00
it("should not be valid", () => {
invalids.forEach((v) => expect(v).not.match(AMOUNT_REGEX));
});
2023-01-03 14:01:04 +01:00
});