-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpayments_test.go
136 lines (131 loc) · 3.17 KB
/
payments_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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package domain
import (
"testing"
"github.com/michaljemala/payments-sample/pkg/internal/errors"
)
func TestPayment_Validate(t *testing.T) {
testCases := []struct {
name string
in Payment
errFunc func(t *testing.T, err error)
}{
{
name: "No ID",
in: Payment{
Amount: Monetary{
Value: MustDecimalFrom("1000.0"),
Currency: "EUR",
},
Creditor: PaymentParty{
AccountNumber: "SK3302000000000000012351",
},
Debtor: PaymentParty{
AccountNumber: "SK0809000000000123123123",
},
Scheme: "SWIFT",
},
errFunc: assertInvalidArgumentError,
},
{
name: "No amount currency",
in: Payment{
BaseObject: BaseObject{ID: MustIDFrom("276c8bbf-79ca-4ac2-b319-0f1c51463540")},
Amount: Monetary{
Value: MustDecimalFrom("1000.0"),
},
Creditor: PaymentParty{
AccountNumber: "SK3302000000000000012351",
},
Debtor: PaymentParty{
AccountNumber: "SK0809000000000123123123",
},
Scheme: "SWIFT",
},
errFunc: assertInvalidArgumentError,
},
{
name: "No scheme",
in: Payment{
BaseObject: BaseObject{ID: MustIDFrom("276c8bbf-79ca-4ac2-b319-0f1c51463540")},
Amount: Monetary{
Value: MustDecimalFrom("1000.0"),
Currency: "EUR",
},
Creditor: PaymentParty{
AccountNumber: "SK3302000000000000012351",
},
Debtor: PaymentParty{
AccountNumber: "SK0809000000000123123123",
},
},
errFunc: assertInvalidArgumentError,
},
{
name: "No creditor account number",
in: Payment{
BaseObject: BaseObject{ID: MustIDFrom("276c8bbf-79ca-4ac2-b319-0f1c51463540")},
Amount: Monetary{
Value: MustDecimalFrom("1000.0"),
Currency: "EUR",
},
Debtor: PaymentParty{
AccountNumber: "SK0809000000000123123123",
},
Scheme: "SWIFT",
},
errFunc: assertInvalidArgumentError,
},
{
name: "No debtor account number",
in: Payment{
BaseObject: BaseObject{ID: MustIDFrom("276c8bbf-79ca-4ac2-b319-0f1c51463540")},
Amount: Monetary{
Value: MustDecimalFrom("1000.0"),
Currency: "EUR",
},
Creditor: PaymentParty{
AccountNumber: "SK3302000000000000012351",
},
Scheme: "SWIFT",
},
errFunc: assertInvalidArgumentError,
},
{
name: "Valid payment",
in: Payment{
BaseObject: BaseObject{ID: MustIDFrom("276c8bbf-79ca-4ac2-b319-0f1c51463540")},
Amount: Monetary{
Value: MustDecimalFrom("1000.0"),
Currency: "EUR",
},
Creditor: PaymentParty{
AccountNumber: "SK3302000000000000012351",
},
Debtor: PaymentParty{
AccountNumber: "SK0809000000000123123123",
},
Scheme: "SWIFT",
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := tc.in.Validate()
if err != nil {
if tc.errFunc == nil {
t.Fatalf("unexpected error: %v", err)
}
}
})
}
}
func assertInvalidArgumentError(t *testing.T, err error) {
switch err := err.(type) {
case errors.Error:
if want, have := errors.ErrCodeGenericInvalidArgument, err.Code; want != have {
t.Fatalf("invalid error code: want %s, have %s", want, have)
}
default:
t.Fatalf("invalid error type: want %T, have %T", errors.Error{}, err)
}
}