-
Notifications
You must be signed in to change notification settings - Fork 0
/
headless_model_test.go
74 lines (69 loc) · 1.64 KB
/
headless_model_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
package tebex
import (
"encoding/json"
"testing"
)
func TestHeadlessBasketUnmarshalLinks1(t *testing.T) {
data := `{
"ident": "abcdef",
"complete": true,
"id": 12345,
"country": "US",
"ip": "127.0.0.1",
"username_id": "abcdef",
"username": "test123",
"cancel_url": "https:\/\/hollowcube.net",
"complete_url": "https:\/\/hollowcube.net",
"complete_auto_redirect": true,
"base_price": 39.96,
"sales_tax": 0,
"total_price": 39.96,
"currency": "USD",
"packages": [],
"coupons": [],
"giftcards": [],
"creator_code": null,
"links": {
"checkout": "IAMLINK"
}
}`
var result HeadlessBasket
err := json.Unmarshal([]byte(data), &result)
if err != nil {
t.Errorf("Failed to unmarshal: %v", err)
}
if result.Links.Checkout != "IAMLINK" {
t.Errorf("Unexpected value: %v", result.Links.Checkout)
}
}
func TestHeadlessBasketUnmarshalLinks2(t *testing.T) {
data := `{
"ident": "abcdef",
"complete": true,
"id": 12345,
"country": "US",
"ip": "127.0.0.1",
"username_id": "abcdef",
"username": "test123",
"cancel_url": "https:\/\/hollowcube.net",
"complete_url": "https:\/\/hollowcube.net",
"complete_auto_redirect": true,
"base_price": 39.96,
"sales_tax": 0,
"total_price": 39.96,
"currency": "USD",
"packages": [],
"coupons": [],
"giftcards": [],
"creator_code": null,
"links": []
}`
var result HeadlessBasket
err := json.Unmarshal([]byte(data), &result)
if err != nil {
t.Errorf("Failed to unmarshal: %v", err)
}
if result.Links.Checkout != "" {
t.Errorf("Unexpected value: %v", result.Links.Checkout)
}
}