forked from Flaconi/go-klarna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkout_test.go
99 lines (82 loc) · 1.64 KB
/
checkout_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
package go_klarna
import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)
func TestCheckoutSrv_CreateNewOrder(t *testing.T) {
setupServer()
defer tearDown()
// initialization
request := new(CheckoutOrder)
assertions := assert.New(t)
setupMux(
assertions,
"/checkout/v3/orders",
request,
http.MethodPost,
mockedResponse,
)
c := testingClient()
pSrv := NewCheckoutSrv(c)
err := pSrv.CreateNewOrder(request)
assertions.Empty(err)
}
func TestCheckoutSrv_RetrieveOrder(t *testing.T) {
setupServer()
defer tearDown()
// initialization
assertions := assert.New(t)
setupMux(
assertions,
"/checkout/v3/orders/abc",
nil,
http.MethodGet,
mockedResponse,
)
c := testingClient()
pSrv := NewCheckoutSrv(c)
ord, err := pSrv.RetrieveOrder("abc")
assertions.Empty(err)
assertions.Equal(mockedResponse, ord)
}
func TestCheckoutSrv_UpdateOrder(t *testing.T) {
setupServer()
defer tearDown()
// initialization
assertions := assert.New(t)
setupMux(
assertions,
"/checkout/v3/orders/abc",
nil,
http.MethodPost,
mockedResponse,
)
c := testingClient()
pSrv := NewCheckoutSrv(c)
err := pSrv.UpdateOrder("abc", mockedResponse)
assertions.Empty(err)
}
var mockedResponse = &CheckoutOrder{
PurchaseCountry: "US",
PurchaseCurrency: "EUR",
Locale: "en-US",
OrderAmount: 0,
OrderTaxAmount: 0,
OrderLines: []*Line{
{
Name: "line 1",
Quantity: 3,
UnitPrice: 2,
TaxRate: 12,
TotalTaxAmount: 12,
TotalAmount: 6,
},
},
MerchantURLS: &CheckoutMerchantURLS{
Terms: "",
Checkout: "",
Confirmation: "",
Push: "",
},
}