-
Notifications
You must be signed in to change notification settings - Fork 6
/
offerrequests_test.go
129 lines (112 loc) · 3.87 KB
/
offerrequests_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
125
126
127
128
129
// 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 TestCreateOffersRequest(t *testing.T) {
defer gock.Off()
a := assert.New(t)
gock.New("https://api.duffel.com").
Post("/air/offer_requests").
MatchParam("return_offers", "true").
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-offer-request.json")
ctx := context.TODO()
client := New("duffel_test_123")
data, err := client.CreateOfferRequest(ctx, OfferRequestInput{
Passengers: []OfferRequestPassenger{
{
FamilyName: "Earhardt",
GivenName: "Amelia",
Type: PassengerTypeAdult,
},
{
Age: 14,
},
},
CabinClass: CabinClassEconomy,
ReturnOffers: true,
Slices: []OfferRequestSlice{
{
DepartureDate: Date(time.Now().AddDate(0, 0, 7)),
Origin: "JFK",
Destination: "AUS",
},
},
})
a.NoError(err)
a.NotNil(data)
a.Equal("1390.66 GBP", data.Offers[0].TotalAmount().String())
a.Equal("116.08 GBP", data.Offers[0].TaxAmount().String())
a.Len(data.Slices, 1)
a.Equal("2021-12-30", data.Slices[0].DepartureDate.String())
a.Equal("arp_jfk_us", data.Slices[0].Origin.ID)
a.Equal("airport", data.Slices[0].OriginType)
a.Equal("2021-12-30", data.Slices[0].DepartureDate.String())
}
func TestGetOfferRequest(t *testing.T) {
defer gock.Off()
a := assert.New(t)
gock.New("https://api.duffel.com").
Get("/air/offer_requests/orq_0000AEtEexyvXbB0OhB5jk").
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-offer-request.json")
ctx := context.TODO()
client := New("duffel_test_123")
data, err := client.GetOfferRequest(ctx, "orq_0000AEtEexyvXbB0OhB5jk")
a.NoError(err)
a.NotNil(data)
a.Equal("1390.66 GBP", data.Offers[0].TotalAmount().String())
a.Equal("116.08 GBP", data.Offers[0].TaxAmount().String())
a.Equal(false, data.Offers[0].LiveMode)
a.Equal("137", data.Offers[0].TotalEmissionsKg)
a.Equal(false, data.Offers[0].PassengerIdentityDocumentsRequired)
a.Equal("airport", data.Offers[0].Slices[0].DestinationType)
a.Equal(false, data.Offers[0].Slices[0].Changeable)
a.Equal("Refundable Main Cabin", data.Offers[0].Slices[0].FareBrandName)
// Assert that departing at is in the correct timezone
dep, err := data.Offers[0].Slices[0].Segments[0].DepartingAt()
a.NoError(err)
est, _ := time.LoadLocation("America/New_York")
a.True(dep.Equal(time.Date(2021, time.December, 30, 8, 55, 0, 0, est)), "Departure time should be in EST")
arr, err := data.Offers[0].Slices[0].Segments[0].ArrivingAt()
a.NoError(err)
a.True(arr.Equal(time.Date(2021, time.December, 30, 12, 07, 0, 0, est)), "Arrival time should be in EST")
}
func TestListOfferRequests(t *testing.T) {
defer gock.Off()
a := assert.New(t)
gock.New("https://api.duffel.com").
Get("/air/offer_requests").
// MatchParam("return_offers", "true").
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-list-offer-requests.json")
ctx := context.TODO()
client := New("duffel_test_123")
iter := client.ListOfferRequests(ctx)
iter.Next()
data := iter.Current()
err := iter.Err()
a.NoError(err)
a.NotNil(data)
a.Equal("arp_jfk_us", data.Slices[0].Origin.ID)
a.Equal("cit_aus_us", data.Slices[0].Destination.ID)
}