-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathordercancellations_test.go
82 lines (69 loc) · 2.47 KB
/
ordercancellations_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
// 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 TestCancelOrder(t *testing.T) {
defer gock.Off()
// gock.Observe(gock.DumpRequest)
a := assert.New(t)
gock.New("https://api.duffel.com").
Post("/air/order_cancellations").
Reply(201).
JSON(`{"data":{"order_id":"ord_00009hthhsUZ8W4LxQgkjo"}}`).
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-cancellation.json")
ctx := context.TODO()
client := New("duffel_test_123")
data, err := client.CreateOrderCancellation(ctx, "ord_00009hthhsUZ8W4LxQgkjo")
a.NoError(err)
a.NotNil(data)
a.Equal("90.80 GBP", data.RefundAmount().String())
}
func TestConfirmCancelOrder(t *testing.T) {
defer gock.Off()
a := assert.New(t)
gock.New("https://api.duffel.com").
Post("/air/order_cancellations/ore_00009qzZWzjDipIkqpaUAj/actions/confirm").
BodyString("").
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-cancellation.json") // Uses the same payload as the create endpoint.
ctx := context.TODO()
client := New("duffel_test_123")
data, err := client.ConfirmOrderCancellation(ctx, "ore_00009qzZWzjDipIkqpaUAj")
a.NoError(err)
a.NotNil(data)
a.Equal("ore_00009qzZWzjDipIkqpaUAj", data.ID)
a.Equal("90.80 GBP", data.RefundAmount().String())
}
func TestGetOrderCancellation(t *testing.T) {
defer gock.Off()
a := assert.New(t)
gock.New("https://api.duffel.com").
Get("/air/order_cancellations/ore_00009qzZWzjDipIkqpaUAj").
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-cancellation.json")
ctx := context.TODO()
client := New("duffel_test_123")
data, err := client.GetOrderCancellation(ctx, "ore_00009qzZWzjDipIkqpaUAj")
a.NoError(err)
a.NotNil(data)
a.Equal("90.80 GBP", data.RefundAmount().String())
}