This repository has been archived by the owner on Feb 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpayment_test.go
121 lines (106 loc) · 2.21 KB
/
payment_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
package go_klarna
import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)
func TestPaymentSrv_CancelExistingAuthorization(t *testing.T) {
setupServer()
defer tearDown()
// initialization
assertions := assert.New(t)
setupMux(
assertions,
"/credit/v1/authorizations/abc",
nil,
http.MethodDelete,
nil,
)
c := testingClient()
pSrv := NewPaymentSrv(c)
err := pSrv.CancelExistingAuthorization("abc")
assertions.Empty(err)
}
func TestPaymentSrv_CreateNewOrder(t *testing.T) {
setupServer()
defer tearDown()
// initialization
request := &PaymentOrder{}
assertions := assert.New(t)
mockedResponse := &PaymentOrderInfo{
OrderID: "123",
RedirectURL: "redirectUri",
FraudStatus: "no",
}
setupMux(
assertions,
"/credit/v1/authorizations/abc/order",
request,
http.MethodPost,
mockedResponse,
)
c := testingClient()
pSrv := NewPaymentSrv(c)
actualResponse, err := pSrv.CreateNewOrder("abc", request)
assertions.Empty(err)
assertions.Equal(mockedResponse, actualResponse)
}
func TestPaymentSrv_UpdateExistingSession(t *testing.T) {
setupServer()
defer tearDown()
// initialization
request := &PaymentOrder{}
assertions := assert.New(t)
setupMux(
assertions,
"/credit/v1/sessions/1a2b",
request,
http.MethodPost,
nil,
)
c := testingClient()
pSrv := NewPaymentSrv(c)
err := pSrv.UpdateExistingSession("1a2b", request)
assertions.Empty(err)
}
func TestPaymentSrv_CreateNewSession(t *testing.T) {
setupServer()
defer tearDown()
// initialization
assertions := assert.New(t)
mockedRes := &PaymentSession{
SessionID: "101",
ClientToken: "abc",
}
request := &PaymentOrder{
PurchaseCountry: "DE",
PurchaseCurrency: "EUR",
Locale: "de-DE",
BillingAddress: &Address{
GivenName: "Floating tester",
},
OrderAmount: 4,
OrderTaxAmount: 6,
OrderLines: []*Line{
{
Name: "line 1",
Quantity: 3,
UnitPrice: 2,
TotalAmount: 6,
},
},
}
// mock the server response
setupMux(
assertions,
"/credit/v1/sessions",
request,
http.MethodPost,
mockedRes,
)
c := testingClient()
pSrv := NewPaymentSrv(c)
ps, err := pSrv.CreateNewSession(request)
assertions.Empty(err)
assertions.Equal(mockedRes, ps)
}