-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
229 lines (224 loc) · 7.35 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
/* globals describe, beforeAll, it, expect */
const R = require('ramda');
const moment = require('moment');
const faker = require('faker');
const axiosRaw = require('axios');
const axios = async (...args) => {
return axiosRaw(...args)
.catch(err => {
const errMsg = R.path(['response', 'data'], err);
console.log('error in ti2-xola', args[0], errMsg)
if (errMsg) throw new Error(errMsg);
throw err;
});
};
const Plugin = require('./index');
const { typeDefs: productTypeDefs, query: productQuery } = require('./node_modules/ti2/controllers/graphql-schemas/product');
const { typeDefs: availTypeDefs, query: availQuery } = require('./node_modules/ti2/controllers/graphql-schemas/availability');
const { typeDefs: bookingTypeDefs, query: bookingQuery } = require('./node_modules/ti2/controllers/graphql-schemas/booking');
const { typeDefs: rateTypeDefs, query: rateQuery } = require('./node_modules/ti2/controllers/graphql-schemas/rate');
const { typeDefs: pickupTypeDefs, query: pickupQuery } = require('./node_modules/ti2/controllers/graphql-schemas/pickup-point');
const typeDefsAndQueries = {
productTypeDefs,
productQuery,
availTypeDefs,
availQuery,
bookingTypeDefs,
bookingQuery,
rateTypeDefs,
rateQuery,
pickupQuery,
pickupTypeDefs,
};
const app = new Plugin({
endpoint: process.env.ti2_xola_endpoint,
apiKey: process.env.ti2_xola_apiKey,
jwtKey: process.env.ti2_xola_jwtKey,
});
const rnd = arr => arr[Math.floor(Math.random() * arr.length)];
describe('search tests', () => {
let products;
let testProduct = {
productId: '643d733e45c0452ed70d1a81',
productName: 'Yara Valley Tour',
};
const token = {
sellerId: '6438627e25d0273673056fcb',
};
const dateFormat = 'YYYY-MM-DD';
beforeAll(async () => {
// nada
});
describe('utilities', () => {
describe('validateToken', () => {
it('valid token', async () => {
expect(token).toBeTruthy();
const retVal = await app.validateToken({
axios,
token,
});
expect(retVal).toBeTruthy();
});
it('invalid token', async () => {
const retVal = await app.validateToken({
axios,
token: { someRandom: 'thing' },
});
expect(retVal).toBeFalsy();
});
});
describe('template tests', () => {
let template;
it('get the template', async () => {
template = await app.tokenTemplate();
const rules = Object.keys(template);
expect(rules).toContain('apiKey');
});
});
});
describe('booking process', () => {
it('get for all products, a test product should exist', async () => {
const retVal = await app.searchProducts({
axios,
token,
typeDefsAndQueries,
});
expect(Array.isArray(retVal.products)).toBeTruthy();
// console.log(retVal.products.filter(({ productName }) => productName === testProduct.productName));
expect(retVal.products).toContainObject([{
productName: testProduct.productName,
}]);
testProduct = {
...retVal.products.find(({ productName }) => productName === testProduct.productName),
};
expect(testProduct.productId).toBeTruthy();
});
let busProducts = [];
it('should be able to get a product by name', async () => {
const retVal = await app.searchProducts({
axios,
token,
typeDefsAndQueries,
payload: {
productName: '*yara*',
},
});
expect(Array.isArray(retVal.products)).toBeTruthy();
expect(retVal.products.length).toBeGreaterThan(0);
busProducts = retVal.products;
});
let availabilityKey;
it('should be able to get availability', async () => {
const retVal = await app.searchAvailability({
axios,
token,
typeDefsAndQueries,
payload: {
startDate: moment().add(1, 'M').format(dateFormat),
endDate: moment().add(1, 'M').format(dateFormat),
dateFormat,
productIds: [
'643d733e45c0452ed70d1a81',
],
optionIds: ['230'],
units: [
[{ unitId:'643d733e45c0452ed70d1a7e', quantity: 2 }],
],
},
});
expect(retVal).toBeTruthy();
const { availability } = retVal;
expect(availability).toHaveLength(1);
expect(availability[0].length).toBeGreaterThan(0);
availabilityKey = R.path([0, 0, 'key'], availability);
expect(availabilityKey).toBeTruthy();
});
let booking = require('./__fixtures__/booking.js');
const reference = faker.datatype.uuid();
it('should be able to create a booking', async () => {
const fullName = faker.name.findName().split(' ');
const retVal = await app.createBooking({
axios,
token,
typeDefsAndQueries,
payload: {
availabilityKey,
notes: faker.lorem.paragraph(),
settlementMethod: 'DEFERRED',
holder: {
name: fullName[0],
surname: fullName[1],
phoneNumber: faker.phone.phoneNumber(),
emailAddress: `morry+tests_${faker.lorem.slug()}@tourconnect.com`,
country: faker.address.countryCode(),
locales: ['en-US', 'en', 'es'],
},
reference,
},
});
expect(retVal.booking).toBeTruthy();
({ booking } = retVal);
expect(booking).toBeTruthy();
expect(R.path(['id'], booking)).toBeTruthy();
expect(R.path(['supplierBookingId'], booking)).toBeTruthy();
expect(R.path(['cancellable'], booking)).toBeTruthy();
});
let bookings = [];
it('it should be able to search bookings by id', async () => {
const retVal = await app.searchBooking({
axios,
token,
typeDefsAndQueries,
payload: {
bookingId: booking.id,
},
});
expect(Array.isArray(retVal.bookings)).toBeTruthy();
({ bookings } = retVal);
expect(R.path([0, 'id'], bookings)).toBeTruthy();
});
it('it should be able to search bookings by reference', async () => {
const retVal = await app.searchBooking({
axios,
token,
typeDefsAndQueries,
payload: {
bookingId: 'VOUCHER_GYG123',
},
});
expect(Array.isArray(retVal.bookings)).toBeTruthy();
({ bookings } = retVal);
expect(R.path([0, 'id'], bookings)).toBeTruthy();
});
it('it should be able to search bookings by travelDate', async () => {
const retVal = await app.searchBooking({
axios,
token,
typeDefsAndQueries,
payload: {
travelDateStart: moment().add(1, 'M').format(dateFormat),
travelDateEnd: moment().add(1, 'M').format(dateFormat),
dateFormat,
},
});
expect(Array.isArray(retVal.bookings)).toBeTruthy();
({ bookings } = retVal);
expect(R.path([0, 'id'], bookings)).toBeTruthy();
});
it('should be able to cancel the booking', async () => {
const retVal = await app.cancelBooking({
axios,
token,
typeDefsAndQueries,
payload: {
bookingId: booking.id,
reason: faker.lorem.paragraph(),
},
});
const { cancellation } = retVal;
expect(cancellation).toBeTruthy();
expect(R.path(['id'], cancellation)).toBeTruthy();
expect(R.path(['cancellable'], cancellation)).toBeFalsy();
});
});
});