-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathorderchanges_test.go
124 lines (107 loc) · 3.4 KB
/
orderchanges_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
// Copyright 2021-present Airheart, Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
package duffel
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
"gopkg.in/h2non/gock.v1"
)
func TestCreateOrderChangeRequest(t *testing.T) {
defer gock.Off()
// gock.Observe(gock.DumpRequest)
gock.New("https://api.duffel.com").
Post("/air/order_change_requests").
JSON(`{
"data": {
"slices": {
"remove": [
{
"slice_id": "sli_00009htYpSCXrwaB9Dn123"
}
],
"add": [
{
"origin": "LHR",
"destination": "JFK",
"departure_date": "2020-04-24",
"cabin_class": "economy"
}
]
},
"order_id": "ord_0000A3bQ8FJIQoEfuC07n6"
}
}`).
Reply(201).
SetHeader("Ratelimit-Limit", "5").
SetHeader("Ratelimit-Remaining", "5").
SetHeader("Ratelimit-Reset", time.Now().Format(time.RFC1123)).
SetHeader("Date", time.Now().Format(time.RFC1123)).
File("fixtures/201-create-order-change-request.json")
a := assert.New(t)
ctx := context.TODO()
client := New("duffel_test_123")
order, err := client.CreateOrderChangeRequest(ctx, OrderChangeRequestParams{
OrderID: "ord_0000A3bQ8FJIQoEfuC07n6",
Slices: SliceChange{
Remove: []SliceRemove{
{SliceID: "sli_00009htYpSCXrwaB9Dn123"},
},
Add: []SliceAdd{
{
Origin: "LHR",
Destination: "JFK",
DepartureDate: Date(time.Date(2020, time.April, 24, 0, 0, 0, 0, time.UTC)),
CabinClass: CabinClassEconomy,
},
},
},
})
a.NoError(err)
a.Equal("ocr_0000A3bQP9RLVfNUcdpLpw", order.ID)
a.Equal("ord_0000A3bQ8FJIQoEfuC07n6", order.OrderID)
a.Equal(false, order.LiveMode)
a.Len(order.OrderChangeOffers, 1)
}
func TestGetOrderChangeRequest(t *testing.T) {
defer gock.Off()
// gock.Observe(gock.DumpRequest)
gock.New("https://api.duffel.com").
Get("/air/order_change_requests/ocr_0000A3bQP9RLVfNUcdpLpw").
Reply(200).
SetHeader("Ratelimit-Limit", "5").
SetHeader("Ratelimit-Remaining", "5").
SetHeader("Ratelimit-Reset", time.Now().Format(time.RFC1123)).
SetHeader("Date", time.Now().Format(time.RFC1123)).
File("fixtures/200-get-order-change-request.json")
a := assert.New(t)
ctx := context.TODO()
client := New("duffel_test_123")
data, err := client.GetOrderChangeRequest(ctx, "ocr_0000A3bQP9RLVfNUcdpLpw")
a.NoError(err)
a.Equal("ocr_0000A3bQP9RLVfNUcdpLpw", data.ID)
a.Equal("ord_0000A3bQ8FJIQoEfuC07n6", data.OrderID)
a.Equal("35.50 GBP", data.OrderChangeOffers[0].NewTotalAmount().String())
a.Equal("10.50 GBP", data.OrderChangeOffers[0].PenaltyTotalAmount().String())
a.Equal("90.80 GBP", data.OrderChangeOffers[0].ChangeTotalAmount().String())
}
func TestCreatePendingOrderChange(t *testing.T) {
defer gock.Off()
gock.New("https://api.duffel.com").
Post("/air/order_changes").
Reply(201).
SetHeader("Ratelimit-Limit", "5").
SetHeader("Ratelimit-Remaining", "5").
SetHeader("Ratelimit-Reset", time.Now().Format(time.RFC1123)).
SetHeader("Date", time.Now().Format(time.RFC1123)).
File("fixtures/201-create-pending-order-change.json")
a := assert.New(t)
ctx := context.TODO()
client := New("duffel_test_123")
data, err := client.CreatePendingOrderChange(ctx, "oco_0000A3vUda8dKRtUSQPSXw")
a.NoError(err)
a.Equal("ocr_0000A3tQSmKyqOrcySrGbo", data.ID)
a.Equal("ord_0000A3tQcCRZ9R8OY0QlxA", data.OrderID)
}