summaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/tests/functions/regex.test.ts
blob: ed06fb6551247a2569e2f1dd143132a37b7114f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 This file is part of GNU Taler
 (C) 2021 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/>
 */

 /**
 *
 * @author Sebastian Javier Marchano (sebasjm)
 */

import { AMOUNT_REGEX, PAYTO_REGEX } from "../../src/utils/constants.js";

describe('payto uri format', () => {
  const valids = [
    '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'
  ]
  
  test('should be valid', () => {
    valids.forEach(v => expect(v).toMatch(PAYTO_REGEX))
  });
  
  const invalids = [
    // has two question marks
    'payto://iban/DE75?512108001245126199?amount=EUR:200.0&message=hello',
    // has a space
    'payto://ach /122000661/1234',
    // has a space
    'payto://upi/alice@ example.com?receiver-name=Alice&amount=INR:200',
    // invalid field name (mount instead of amount)
    'payto://void/?mount=EUR:10.5',
    // payto:// is incomplete
    'payto: //ilp/g.acme.bob'
  ]
  
  test('should not be valid', () => {
    invalids.forEach(v => expect(v).not.toMatch(PAYTO_REGEX))
  });  
})

describe('amount format', () => {
  const valids = [
    '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',
  ]
  
  test('should be valid', () => {
    valids.forEach(v => expect(v).toMatch(AMOUNT_REGEX))
  });
  
  const invalids = [
    //no currency name
    ':10',
    //use . instead of ,
    'ARS:1.000.000',
    //currency name with numbers
    '1ARS:10',
    //currency name with numbers
    'AR5:10',
    //missing value
    'USD:',
  ]
  
  test('should not be valid', () => {
    invalids.forEach(v => expect(v).not.toMatch(AMOUNT_REGEX))
  });  

})