ti2-ventrata 1.0.4 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +23 -16
  2. package/index.test.js +20 -20
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -14,15 +14,22 @@ const isNilOrEmptyArray = el => {
14
14
  return R.isNil(el) || R.isEmpty(el);
15
15
  };
16
16
 
17
- const doMap = (obj, map) => {
17
+ const doMap = (obj, map, omitParam = []) => {
18
18
  const retVal = {};
19
+ const omit = [
20
+ ...omitParam,
21
+ ...Object.keys(map),
22
+ ];
19
23
  Object.entries(map).forEach(([attribute, fn]) => {
20
24
  const newVal = fn(obj);
21
25
  if (newVal !== undefined) {
22
26
  retVal[attribute] = newVal;
23
27
  }
24
28
  });
25
- return retVal;
29
+ return {
30
+ ...retVal,
31
+ ...R.omit(omit, obj),
32
+ };
26
33
  };
27
34
 
28
35
  const doMapCurry = mapObj => item => doMap(item, mapObj);
@@ -30,10 +37,13 @@ const doMapCurry = mapObj => item => doMap(item, mapObj);
30
37
  const productMapIn = {
31
38
  productId: R.path(['id']),
32
39
  productName: R.path(['title']),
33
- options: e => e.options.map(option => ({
34
- optionId: R.path(['id'], option),
35
- optionName: R.path(['title'], option),
36
- })),
40
+ options: e => R.pathOr(undefined, ['options'], e).map(option => doMap(option, optionMapIn, ['id', 'title'])),
41
+ };
42
+
43
+ const optionMapIn = {
44
+ optionId: R.path(['id']),
45
+ optionName: R.path(['title']),
46
+ units: option => R.pathOr(undefined, ['units'], option).map(unit => doMap(unit, unitMap)),
37
47
  };
38
48
 
39
49
  const rateMap = {
@@ -68,12 +78,6 @@ const capitalize = sParam => {
68
78
  return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
69
79
  };
70
80
 
71
- // const optionMap = {
72
- // optionId: R.path(['id']),
73
- // optionName: R.path(['title']),
74
- // units: option => R.pathOr(undefined, ['units'], option).map(unit => doMap(unit, unitMap)),
75
- // };
76
-
77
81
  const unitMap = {
78
82
  unitId: R.path(['id']),
79
83
  unitName: R.path(['title']),
@@ -199,14 +203,17 @@ class Plugin {
199
203
  headers,
200
204
  }));
201
205
  if (!Array.isArray(results)) results = [results];
202
- let products = results.map(e => doMap(e, productMapIn));
206
+ let products = results.map(e => doMap(e, productMapIn, ['id', 'title']));
203
207
  // dynamic extra filtering
204
208
  if (!isNilOrEmpty(payload)) {
205
209
  const extraFilters = R.omit(['productId'], payload);
206
210
  if (Object.keys(extraFilters).length > 0) {
207
211
  products = products.filter(
208
212
  product => Object.entries(extraFilters).every(
209
- ([key, value]) => wildcardMatch(value, product[key]),
213
+ ([key, value]) => {
214
+ if (typeof value === 'string') return wildcardMatch(value, product[key]);
215
+ return true;
216
+ },
210
217
  ),
211
218
  );
212
219
  }
@@ -272,7 +279,7 @@ class Plugin {
272
279
  optionIds,
273
280
  occupancies,
274
281
  startDate,
275
- // endDate,
282
+ endDate,
276
283
  dateFormat,
277
284
  },
278
285
  }) {
@@ -290,7 +297,7 @@ class Plugin {
290
297
  assert(optionIds.every(Boolean), 'some invalid optionId(s)');
291
298
  assert(occupancies.every(Boolean), 'some invalid occupacies(s)');
292
299
  const localDateStart = moment(startDate, dateFormat).format('YYYY-MM-DD');
293
- const localDateEnd = moment(startDate, dateFormat).format('YYYY-MM-DD');
300
+ const localDateEnd = moment(endDate, dateFormat).format('YYYY-MM-DD');
294
301
  // obtain the rates
295
302
  const { quote } = await this.searchQuote({
296
303
  token,
package/index.test.js CHANGED
@@ -10,13 +10,13 @@ const app = new Plugin({
10
10
  jwtKey: process.env.ti2_ventrata_jwtKey,
11
11
  });
12
12
 
13
- const rnd = (arr) => arr[Math.floor(Math.random() * arr.length)];
13
+ const rnd = arr => arr[Math.floor(Math.random() * arr.length)];
14
14
 
15
15
  describe('search tests', () => {
16
16
  let products;
17
17
  let testProduct = {
18
18
  productName: 'Pub Crawl Tour',
19
- }
19
+ };
20
20
  const token = {
21
21
  apiKey: process.env.ti2_ventrata_apiKey,
22
22
  endpoint: process.env.ti2_ventrata_endpoint,
@@ -74,7 +74,7 @@ describe('search tests', () => {
74
74
  token,
75
75
  payload: {
76
76
  productId: testProduct.productId,
77
- }
77
+ },
78
78
  });
79
79
  expect(Array.isArray(retVal.products)).toBeTruthy();
80
80
  expect(retVal.products).toHaveLength(1);
@@ -181,7 +181,7 @@ describe('search tests', () => {
181
181
  phoneNumber: faker.phone.phoneNumber(),
182
182
  emailAddress: `salvador+tests_${faker.lorem.slug()}@tourconnect.com`,
183
183
  country: faker.address.countryCode(),
184
- locales:  ['en-US', 'en', 'es'],
184
+ locales: ['en-US', 'en', 'es'],
185
185
  },
186
186
  reference,
187
187
  },
@@ -189,9 +189,9 @@ describe('search tests', () => {
189
189
  expect(retVal.booking).toBeTruthy();
190
190
  ({ booking } = retVal);
191
191
  expect(booking).toBeTruthy();
192
- expect(R.path(['id'], booking)).toBeTruthy()
193
- expect(R.path(['supplierId'], booking)).toBeTruthy()
194
- expect(R.path(['cancellable'], booking)).toBeTruthy()
192
+ expect(R.path(['id'], booking)).toBeTruthy();
193
+ expect(R.path(['supplierId'], booking)).toBeTruthy();
194
+ expect(R.path(['cancellable'], booking)).toBeTruthy();
195
195
  // console.log({ booking });
196
196
  });
197
197
  it('should be able to cancel the booking', async () => {
@@ -200,13 +200,13 @@ describe('search tests', () => {
200
200
  payload: {
201
201
  bookingId: booking.id,
202
202
  reason: faker.lorem.paragraph(),
203
- }
203
+ },
204
204
  });
205
- ({ cancellation } = retVal);
205
+ const { cancellation } = retVal;
206
206
  expect(cancellation).toBeTruthy();
207
207
  expect(cancellation).toBeTruthy();
208
- expect(R.path(['id'], cancellation)).toBeTruthy()
209
- expect(R.path(['cancellable'], cancellation)).toBeFalsy()
208
+ expect(R.path(['id'], cancellation)).toBeTruthy();
209
+ expect(R.path(['cancellable'], cancellation)).toBeFalsy();
210
210
  });
211
211
  let bookings = [];
212
212
  it('it should be able to search bookings by id', async () => {
@@ -214,33 +214,33 @@ describe('search tests', () => {
214
214
  token,
215
215
  payload: {
216
216
  bookingId: booking.id,
217
- }
217
+ },
218
218
  });
219
219
  expect(Array.isArray(retVal.bookings)).toBeTruthy();
220
220
  ({ bookings } = retVal);
221
- expect(R.path([0, 'id'], bookings)).toBeTruthy()
221
+ expect(R.path([0, 'id'], bookings)).toBeTruthy();
222
222
  });
223
223
  it('it should be able to search bookings by reference', async () => {
224
224
  const retVal = await app.searchBooking({
225
225
  token,
226
226
  payload: {
227
227
  bookingId: reference,
228
- }
228
+ },
229
229
  });
230
230
  expect(Array.isArray(retVal.bookings)).toBeTruthy();
231
231
  ({ bookings } = retVal);
232
- expect(R.path([0, 'id'], bookings)).toBeTruthy()
232
+ expect(R.path([0, 'id'], bookings)).toBeTruthy();
233
233
  });
234
234
  it('it should be able to search bookings by supplierId', async () => {
235
235
  const retVal = await app.searchBooking({
236
236
  token,
237
237
  payload: {
238
238
  bookingId: booking.supplierId,
239
- }
239
+ },
240
240
  });
241
241
  expect(Array.isArray(retVal.bookings)).toBeTruthy();
242
242
  ({ bookings } = retVal);
243
- expect(R.path([0, 'id'], bookings)).toBeTruthy()
243
+ expect(R.path([0, 'id'], bookings)).toBeTruthy();
244
244
  });
245
245
  it('it should be able to search bookings by travelDate', async () => {
246
246
  const retVal = await app.searchBooking({
@@ -249,11 +249,11 @@ describe('search tests', () => {
249
249
  travelDateStart: moment().add(6, 'M').format(dateFormat),
250
250
  travelDateEnd: moment().add(6, 'M').add(2, 'd').format(dateFormat),
251
251
  dateFormat,
252
- }
252
+ },
253
253
  });
254
254
  expect(Array.isArray(retVal.bookings)).toBeTruthy();
255
255
  ({ bookings } = retVal);
256
- expect(R.path([0, 'id'], bookings)).toBeTruthy()
256
+ expect(R.path([0, 'id'], bookings)).toBeTruthy();
257
257
  });
258
- });
258
+ });
259
259
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-ventrata",
3
- "version": "1.0.4",
3
+ "version": "1.0.7",
4
4
  "description": "Ventrata's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {