-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathshooping_flight_pricing_test.go
83 lines (65 loc) · 1.88 KB
/
shooping_flight_pricing_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
package amadeus
import (
"fmt"
"os"
"testing"
"time"
"github.com/joho/godotenv"
)
func TestShoppingFlightPricingRequest(t *testing.T) {
err := godotenv.Load()
if err != nil {
fmt.Println("Not found .env file")
}
t.Run("TestShoppingFlightPricingRequest", func(t *testing.T) {
// create client
amadeus, err := New(
os.Getenv("AMADEUS_CLIENT_ID"),
os.Getenv("AMADEUS_CLIENT_SECRET"),
os.Getenv("AMADEUS_ENV"),
)
if err != nil {
t.Fatal("not expected error while creating client", err)
}
// get offer flights request
offerReq, offerResp, err := amadeus.NewRequest(ShoppingFlightOffers)
// set offer flights params
offerReq.(*ShoppingFlightOffersRequest).
SetCurrency("EUR").
SetSources("GDS").
Oneway(
"LON",
"PAR",
time.Now().AddDate(0, 5, 0).Format("2006-01-02"),
).
AddTravelers(1, 0, 0)
// send request flight offers
err = amadeus.Do(offerReq, &offerResp, "POST")
if err != nil {
t.Fatal("not expected error while geting flight offers data", err)
}
// get flight offers response
offerRespData := offerResp.(*ShoppingFlightOffersResponse)
// check if data is returned
if len(offerRespData.Data) == 0 {
t.Fatal("return 0 results in offer search request")
}
// get pricing request
pricingReq, pricingResp, err := amadeus.NewRequest(ShoppingFlightPricing)
// add offer from flight offers response
pricingReq.(*ShoppingFlightPricingRequest).AddOffer(
offerRespData.GetOffer(1),
)
// send request for flight pricing
err = amadeus.Do(pricingReq, &pricingResp, "POST")
if err != nil {
t.Fatal("not expected error while geting flight offers data", err)
}
// get flight pricing response
pricingRespData := pricingResp.(*ShoppingFlightPricingResponse)
// check if reponse exist
if len(pricingRespData.Data.FlightOffers) == 0 {
t.Error("return 0 results in offer search request")
}
})
}