-
Notifications
You must be signed in to change notification settings - Fork 6
/
qrbill_test.go
120 lines (104 loc) · 2.15 KB
/
qrbill_test.go
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package qrbill_test
import (
"testing"
"github.com/stapelberg/qrbill"
)
func TestAmountValidation(t *testing.T) {
for _, tt := range []struct {
amount string
wantAmount string
}{
{
// ensure empty amount values are not modified
amount: "",
wantAmount: "",
},
{
amount: "50",
wantAmount: "50.00",
},
{
amount: "50.3",
wantAmount: "50.30",
},
{
amount: "50.32",
wantAmount: "50.32",
},
{
amount: "50.32",
wantAmount: "50.32",
},
{
amount: "50.000",
wantAmount: "50.00",
},
{
amount: "50.339",
wantAmount: "50.34",
},
{
amount: "50.331",
wantAmount: "50.33",
},
{
amount: "50.-",
wantAmount: "0.00", // result of invalid input
},
{
amount: ".30",
wantAmount: "0.30",
},
{
amount: ".3",
wantAmount: "0.30",
},
{
// minimum amount mentioned in the Implementation Guidelines
amount: "0.01",
wantAmount: "0.01",
},
{
// maximum amount mentioned in the Implementation Guidelines
amount: "999999999.99",
wantAmount: "999999999.99",
},
} {
t.Run(tt.amount, func(t *testing.T) {
qrch := &qrbill.QRCH{
CdtrInf: qrbill.QRCHCdtrInf{
IBAN: "CH0209000000870913543",
Cdtr: qrbill.Address{
AdrTp: qrbill.AddressTypeCombined,
Name: "Legalize it",
StrtNmOrAdrLine1: "Quellenstrasse 25",
BldgNbOrAdrLine2: "8005 Zürich",
Ctry: "CH",
},
},
CcyAmt: qrbill.QRCHCcyAmt{
Amt: tt.amount,
Ccy: "CHF",
},
UltmtDbtr: qrbill.Address{
AdrTp: qrbill.AddressTypeCombined,
Name: "Michael Stapelberg",
StrtNmOrAdrLine1: "Stauffacherstr 42",
BldgNbOrAdrLine2: "8004 Zürich",
Ctry: "CH",
},
RmtInf: qrbill.QRCHRmtInf{
Tp: "NON", // Reference type
Ref: "", // Reference
AddInf: qrbill.QRCHRmtInfAddInf{
Ustrd: "test",
},
},
}
validated := qrch.Validate()
if got, want := validated.CcyAmt.Amt, tt.wantAmount; got != want {
t.Errorf("CcyAmt.Amt = %q, want %q", got, want)
}
})
}
}