-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
274 lines (269 loc) · 9.65 KB
/
index.test.js
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/* globals describe, beforeAll, it, expect */
const R = require('ramda');
const axios = require('axios');
const moment = require('moment');
const faker = require('faker');
const Plugin = require('./index');
const app = new Plugin();
const rnd = (arr) => arr[Math.floor(Math.random() * arr.length)];
describe('travel-gate', () => {
// let validKey = process;
let accommodation;
let availability;
let quoteId;
let bookingId;
const token = {
apiKey: process.env.ti2_travelgate_apiKey,
endpoint: process.env.ti2_travelgate_endpoint,
clientCode: process.env.ti2_travelgate_clientCode,
/*
* A travel company that buys accommodation services
* via Hotel-X API is considered a "client" in our architecture".
* Client codes are consistent throughout all TravelgateX implementations.
* These codes are used to identify the business that is making the request
* and to confirm that the business has a configuration assigned to it.
*/
};
const defaultAccessCode = 0;
/*
* Accesses are displayed as numeric codes in Hotel-X and represent Supplier
* configurations for a given credential. Those configurations include:
* URLs
* Credentials
* Markets
* Rate Types
* Specific Supplier settings
* An access is used by just a client exclusively.
* The same supplier has different access depends on the number of clients
* connected to him, even if the configuration is almost the same.
*/
const dateFormat = 'DD/MM/YYYY';
it('make sure the token is valid', () => {
expect(token.apiKey).toBeTruthy();
expect(token.endpoint).toBeTruthy();
expect(token.clientCode).toBeTruthy();
});
describe('tooling tests', () => {
describe('validateToken', () => {
it('valid token', async () => {
const retVal = await app.validateToken({
axios,
token,
});
expect(retVal).toBeTruthy();
});
it('invalid token', async () => {
const retVal = await app.validateToken({
axios,
token: { ...token, apiKey: 'somerandom' },
});
expect(retVal).toBeFalsy();
});
});
describe('template', () => {
let template;
it('get the template', async () => {
template = await app.tokenTemplate();
const rules = Object.keys(template);
expect(rules).toContain('clientCode');
expect(rules).toContain('endpoint');
expect(rules).toContain('apiKey');
});
it('apiKey', () => {
const apiKey = template.apiKey.regExp;
expect(apiKey.test('something')).toBeFalsy();
expect(apiKey.test('f5eb2e1f-4b8f-4b43-a858-4a12d77b8299')).toBeTruthy();
});
it('clientCode', () => {
const clientCode = template.clientCode.regExp;
expect(clientCode.test('')).toBeFalsy();
expect(clientCode.test('tourconnect')).toBeTruthy();
});
it('endpoint', () => {
const endpoint = template.endpoint.regExp;
expect(endpoint.test('something')).toBeFalsy();
expect(endpoint.test('https://api.travelgatex.com')).toBeTruthy();
});
});
});
describe('booking', () => {
describe('hotel booking process', () => {
it('search for all available hotels, test hotel should exist', async () => {
const retVal = await app.searchProducts({
axios,
payload: {
access: defaultAccessCode,
},
token,
});
expect(retVal).toBeTruthy();
({ accommodation } = retVal);
expect(accommodation.length).toBeGreaterThan(0);
expect(accommodation.find((e) => /test/gi.test(e.hotelName))).toBeTruthy();
});
it('should be able to check availability for test hotel 1 and 2', async () => {
const retVal = await app.searchAvailability({
axios,
token,
payload: {
travelDateStart: moment().add(6, 'M').format(dateFormat),
travelDateEnd: moment().add(6, 'M').add(7, 'd').format(dateFormat),
dateFormat,
hotels: ['1', '2'],
occupancies: [{ paxes: [{ age: 30 }, { age: 40 }] }],
context: 'HOTELTEST',
currency: 'EUR',
market: 'ES',
language: 'es',
nationality: 'ES',
testMode: true,
access: defaultAccessCode,
},
});
expect(retVal).toBeTruthy();
({ availability } = retVal);
expect(availability.length).toBeGreaterThan(0);
expect(availability.find((e) => e.rooms.find((r) => /double standard/gi.test(r.description)))).toBeTruthy();
availability = rnd(availability); // pick 1
});
it('should be able to quote for an availability result', async () => {
const { id } = availability; // availability result id
const retVal = await app.searchQuote({
axios,
token,
payload: {
id,
context: 'HOTELTEST',
testMode: true,
},
});
expect(retVal).toBeTruthy();
quoteId = R.path(['quote', 'id'], retVal);
// ({ quote: [{ id: quoteId }] } = retVal);
expect(quoteId).toBeTruthy();
});
it('should be able to book a reservation of 1 room', async () => {
const fullName = faker.name.findName().split(' ');
const billName = faker.name.findName().split(' ');
const expDate = moment().add(1, 'y');
const paxes = [
fullName,
faker.name.findName().split(' '),
];
const retVal = await app.createBooking({
axios,
token,
payload: {
id: quoteId, // availability result id
clientReference: faker.finance.account(),
holder: { name: fullName[0], surname: fullName[1] },
remarks: faker.lorem.sentence(),
...(availability.paymentType === 'DIRECT' ? {
paymentCard: {
cardType: rnd(['VI', 'MC']),
holder: { name: billName[0], surname: billName[1] },
number: '4242 4242 4242 4242',
CVC: '914',
expire: { month: expDate.month(), year: expDate.year() },
},
} : {}),
rooms: {
occupancyRefId: 1,
paxes: [
{
name: paxes[0][0],
surname: paxes[0][1],
age: faker.datatype.number({ min: 21, max: 60 }),
},
{
name: paxes[1][0],
surname: paxes[1][1],
age: faker.datatype.number({ min: 21, max: 60 }),
},
],
},
context: 'HOTELTEST',
testMode: true,
},
});
expect(retVal).toBeTruthy();
bookingId = R.path(['booking', 'reference', 'bookingID'], retVal);
expect(bookingId).toBeTruthy();
});
it('sould be able to cancel the generated booking', async () => {
const retVal = await app.cancelBooking({
axios,
token,
payload: {
id: bookingId || '1[1|201228|201229|200226|1|es|EUR|0|TEST_LOCATOR_1|975723',
context: 'HOTELTEST',
testMode: true,
},
});
expect(retVal).toBeTruthy();
expect(R.path(['cancellation', 'status'], retVal)).toBe('CANCELLED');
});
});
describe('existing bookings search', () => {
it('should be search bookings by purchase date', async () => {
const payload = {
purchaseDateStart: '06/03/2020',
purchaseDateEnd: '07/03/2020',
dateFormat: 'DD/MM/YYYY',
context: 'HOTELTEST',
access: defaultAccessCode,
language: 'es',
};
const retVal = await app.searchBooking({
axios,
payload,
token,
});
expect(Array.isArray(retVal.bookings)).toBeTruthy();
expect(retVal.bookings.length).toBeGreaterThan(0);
expect(retVal.bookings.filter(
(e) => moment(e.bookingDate, 'YYYY-MM-DD').isBefore(moment(payload.purchaseDateStart, payload.dateFormat))
|| moment(e.bookingDate, 'YYYY-MM-DD').isAfter(moment(payload.purchaseDateEnd, payload.dateFormat)),
).length).toBe(0);
});
it('should be search bookings by travel date', async () => {
const payload = {
travelDateStart: '09/03/2020',
travelDateEnd: '10/03/2020',
dateFormat: 'DD/MM/YYYY',
context: 'HOTELTEST',
access: defaultAccessCode,
language: 'es',
};
const retVal = await app.searchBooking({
axios,
payload,
token,
});
expect(Array.isArray(retVal.bookings)).toBeTruthy();
expect(retVal.bookings.length).toBeGreaterThan(0);
expect(retVal.bookings.filter(
(e) => moment(e.start, 'YYYY-MM-DD').isBefore(moment(payload.travelDateStart, payload.dateFormat))
|| moment(e.start, 'YYYY-MM-DD').isAfter(moment(payload.travelDateEnd, payload.dateFormat)),
).length).toBe(0);
});
it('should be able to search by booking Id', async () => {
const retVal = await app.searchBooking({
axios,
payload: {
bookingId: '988671',
hotelCode: '1', // required for booking search
currency: 'USD', // required for booking search
context: 'HOTELTEST',
access: defaultAccessCode,
language: 'es',
},
token,
});
// console.log(retVal.bookings[0]);
expect(Array.isArray(retVal.bookings)).toBeTruthy();
expect(retVal.bookings.length).toBeGreaterThan(0);
});
});
});
});