forked from airheartdev/duffel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatchofferrequests_test.go
More file actions
76 lines (65 loc) · 1.79 KB
/
batchofferrequests_test.go
File metadata and controls
76 lines (65 loc) · 1.79 KB
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
package duffel
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
"gopkg.in/h2non/gock.v1"
)
func TestCreateBatchOfferRequest(t *testing.T) {
defer gock.Off()
a := assert.New(t)
gock.New("https://api.duffel.com").
Post("/air/batch_offer_requests").
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-create-batch-offer-request.json")
ctx := context.TODO()
client := New("duffel_test_123")
data, err := client.CreateBatchOfferRequest(ctx, CreateBatchOfferRequestInput{
Passengers: []OfferRequestPassenger{
{
FamilyName: "Earhardt",
GivenName: "Amelia",
Type: PassengerTypeAdult,
},
{
Age: 14,
},
},
CabinClass: CabinClassEconomy,
Slices: []OfferRequestSlice{
{
DepartureDate: Date(time.Now().AddDate(0, 0, 7)),
Origin: "JFK",
Destination: "AUS",
},
},
})
a.NoError(err)
a.NotNil(data)
a.Equal(7, data.RemainingBatches)
a.Equal(7, data.TotalBatches)
}
func TestGetBatchOfferRequest(t *testing.T) {
defer gock.Off()
a := assert.New(t)
gock.New("https://api.duffel.com").
Get("/air/batch_offer_requests/orq_0000AhTmH2Thpl6RrM97qK").
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-batch-offer-request.json")
ctx := context.TODO()
client := New("duffel_test_123")
data, err := client.GetBatchOfferRequest(ctx, "orq_0000AhTmH2Thpl6RrM97qK")
a.NoError(err)
a.NotNil(data)
a.Equal(2, data.TotalBatches)
a.Equal(2, data.RemainingBatches)
}