2022-10-24 10:46:14 +02:00
|
|
|
/*
|
|
|
|
This file is part of GNU Taler
|
2022-12-16 20:59:37 +01:00
|
|
|
(C) 2021-2023 Taler Systems S.A.
|
2022-10-24 10:46:14 +02:00
|
|
|
|
|
|
|
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/>
|
|
|
|
*/
|
|
|
|
|
2022-12-20 21:45:24 +01:00
|
|
|
/**
|
2023-01-03 14:01:04 +01:00
|
|
|
*
|
|
|
|
* @author Sebastian Javier Marchano (sebasjm)
|
|
|
|
*/
|
2022-10-24 10:46:14 +02:00
|
|
|
|
2023-01-03 05:57:39 +01:00
|
|
|
import { expect } from "chai";
|
2023-02-15 23:32:42 +01:00
|
|
|
import { AMOUNT_REGEX, PAYTO_REGEX } from "./constants.js";
|
2022-10-24 10:46:14 +02:00
|
|
|
|
2023-01-03 14:01:04 +01:00
|
|
|
describe("payto uri format", () => {
|
2022-10-24 10:46:14 +02:00
|
|
|
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",
|
|
|
|
];
|
2022-12-20 21:45:24 +01:00
|
|
|
|
2023-01-03 14:01:04 +01:00
|
|
|
it("should be valid", () => {
|
|
|
|
valids.forEach((v) => expect(v).match(PAYTO_REGEX));
|
2022-10-24 10:46:14 +02:00
|
|
|
});
|
2022-12-20 21:45:24 +01:00
|
|
|
|
2022-10-24 10:46:14 +02:00
|
|
|
const invalids = [
|
|
|
|
// has two question marks
|
2023-01-03 14:01:04 +01:00
|
|
|
"payto://iban/DE75?512108001245126199?amount=EUR:200.0&message=hello",
|
2022-10-24 10:46:14 +02:00
|
|
|
// has a space
|
2023-01-03 14:01:04 +01:00
|
|
|
"payto://ach /122000661/1234",
|
2022-10-24 10:46:14 +02:00
|
|
|
// has a space
|
2023-01-03 14:01:04 +01:00
|
|
|
"payto://upi/alice@ example.com?receiver-name=Alice&amount=INR:200",
|
2022-10-24 10:46:14 +02:00
|
|
|
// invalid field name (mount instead of amount)
|
2023-01-03 14:01:04 +01:00
|
|
|
"payto://void/?mount=EUR:10.5",
|
2022-10-24 10:46:14 +02:00
|
|
|
// payto:// is incomplete
|
2023-01-03 14:01:04 +01:00
|
|
|
"payto: //ilp/g.acme.bob",
|
|
|
|
];
|
2022-12-20 21:45:24 +01:00
|
|
|
|
2023-01-03 14:01:04 +01:00
|
|
|
it("should not be valid", () => {
|
|
|
|
invalids.forEach((v) => expect(v).not.match(PAYTO_REGEX));
|
2022-12-20 21:45:24 +01:00
|
|
|
});
|
2023-01-03 14:01:04 +01:00
|
|
|
});
|
2022-10-24 10:46:14 +02:00
|
|
|
|
2023-01-03 14:01:04 +01:00
|
|
|
describe("amount format", () => {
|
2022-10-24 10:46:14 +02:00
|
|
|
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",
|
|
|
|
];
|
2022-12-20 21:45:24 +01:00
|
|
|
|
2023-01-03 14:01:04 +01:00
|
|
|
it("should be valid", () => {
|
|
|
|
valids.forEach((v) => expect(v).match(AMOUNT_REGEX));
|
2022-10-24 10:46:14 +02:00
|
|
|
});
|
2022-12-20 21:45:24 +01:00
|
|
|
|
2022-10-24 10:46:14 +02:00
|
|
|
const invalids = [
|
|
|
|
//no currency name
|
2023-01-03 14:01:04 +01:00
|
|
|
":10",
|
2022-10-24 10:46:14 +02:00
|
|
|
//use . instead of ,
|
2023-01-03 14:01:04 +01:00
|
|
|
"ARS:1.000.000",
|
2022-10-24 10:46:14 +02:00
|
|
|
//currency name with numbers
|
2023-01-03 14:01:04 +01:00
|
|
|
"1ARS:10",
|
2022-10-24 10:46:14 +02:00
|
|
|
//currency name with numbers
|
2023-01-03 14:01:04 +01:00
|
|
|
"AR5:10",
|
2022-10-24 10:46:14 +02:00
|
|
|
//missing value
|
2023-01-03 14:01:04 +01:00
|
|
|
"USD:",
|
|
|
|
];
|
2022-12-20 21:45:24 +01:00
|
|
|
|
2023-01-03 14:01:04 +01:00
|
|
|
it("should not be valid", () => {
|
|
|
|
invalids.forEach((v) => expect(v).not.match(AMOUNT_REGEX));
|
2022-12-20 21:45:24 +01:00
|
|
|
});
|
2023-01-03 14:01:04 +01:00
|
|
|
});
|