ti2-ventrata 1.0.23 → 1.0.25

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.
package/index.js CHANGED
@@ -9,6 +9,7 @@ const wildcardMatch = require('./utils/wildcardMatch');
9
9
  const { translateProduct } = require('./resolvers/product');
10
10
  const { translateAvailability } = require('./resolvers/availability');
11
11
  const { translateBooking } = require('./resolvers/booking');
12
+ const { translatePickupPoint } = require('./resolvers/pickup-point');
12
13
 
13
14
  const CONCURRENCY = 3; // is this ok ?
14
15
  if (process.env.debug) {
@@ -29,7 +30,7 @@ const getHeaders = ({
29
30
  ...acceptLanguage ? { 'Accept-Language': acceptLanguage } : {},
30
31
  'Content-Type': 'application/json',
31
32
  ...resellerId ? { Referer: resellerId } : {},
32
- 'Octo-Capabilities': 'octo/pricing,octo/pickups',
33
+ 'Octo-Capabilities': 'octo/pricing,octo/pickups,octo/cart',
33
34
  ...requestId ? { requestId } : {},
34
35
  // 'Octo-Capabilities': 'octo/pricing',
35
36
  });
@@ -575,32 +576,49 @@ class Plugin {
575
576
  })),
576
577
  });
577
578
  }
578
- }
579
579
 
580
- const pickUnit = (units, paxs) => {
581
- const evalOne = (unit, pax) => {
582
- if (pax.age < R.path(['restrictions', 'minAge'], unit)) {
583
- return false;
584
- }
585
- if (pax.age > R.path(['restrictions', 'maxAge'], unit)) {
586
- return false;
587
- }
588
- return true;
589
- };
590
- if (paxs.length > 1) { // find group units
591
- const group = units.filter(({ restrictions }) => Boolean(restrictions)).find(unit => {
592
- if (
593
- R.path(['restrictions', 'paxCount'], unit) === paxs.length
594
- && paxs.every(pax => evalOne(unit, pax))
595
- ) return true;
596
- return false;
580
+ async getPickupPoints({
581
+ token: {
582
+ apiKey,
583
+ endpoint,
584
+ octoEnv,
585
+ acceptLanguage,
586
+ resellerId,
587
+ },
588
+ typeDefsAndQueries: {
589
+ pickupTypeDefs,
590
+ pickupQuery,
591
+ },
592
+ requestId,
593
+ }) {
594
+ const url = `${endpoint || this.endpoint}/products`;
595
+ const headers = getHeaders({
596
+ apiKey,
597
+ endpoint,
598
+ octoEnv,
599
+ acceptLanguage,
600
+ resellerId,
601
+ requestId,
597
602
  });
598
- if (group) return [group];
603
+ const products = R.pathOr([], ['data'], await this.axios({
604
+ method: 'get',
605
+ url,
606
+ headers,
607
+ }));
608
+ const pickupPoints = R.call(R.compose(
609
+ R.uniqBy(R.prop('id')),
610
+ R.chain(R.propOr([], 'pickupPoints')),
611
+ R.filter(o => o.pickupPoints && o.pickupPoints.length),
612
+ R.chain(R.propOr([], 'options')),
613
+ ), products);
614
+ return {
615
+ pickupPoints: await Promise.map(pickupPoints, async pickup => translatePickupPoint({
616
+ rootValue: pickup,
617
+ typeDefs: pickupTypeDefs,
618
+ query: pickupQuery,
619
+ })),
620
+ };
599
621
  }
600
- return paxs.map(pax => units
601
- .filter(unit => R.path(['restrictions', 'paxCount'], unit) === 1)
602
- .find(unit => evalOne(unit, pax))); // individual units
603
- };
622
+ }
604
623
 
605
624
  module.exports = Plugin;
606
- module.exports.pickUnit = pickUnit;
package/index.test.js CHANGED
@@ -4,12 +4,12 @@ const moment = require('moment');
4
4
  const faker = require('faker');
5
5
 
6
6
  const Plugin = require('./index');
7
- const fixtureUnits = require('./__fixtures__/units.js');
8
7
 
9
8
  const { typeDefs: productTypeDefs, query: productQuery } = require('./node_modules/ti2/controllers/graphql-schemas/product');
10
9
  const { typeDefs: availTypeDefs, query: availQuery } = require('./node_modules/ti2/controllers/graphql-schemas/availability');
11
10
  const { typeDefs: bookingTypeDefs, query: bookingQuery } = require('./node_modules/ti2/controllers/graphql-schemas/booking');
12
11
  const { typeDefs: rateTypeDefs, query: rateQuery } = require('./node_modules/ti2/controllers/graphql-schemas/rate');
12
+ const { typeDefs: pickupTypeDefs, query: pickupQuery } = require('./node_modules/ti2/controllers/graphql-schemas/pickup-point');
13
13
 
14
14
  const typeDefsAndQueries = {
15
15
  productTypeDefs,
@@ -20,6 +20,8 @@ const typeDefsAndQueries = {
20
20
  bookingQuery,
21
21
  rateTypeDefs,
22
22
  rateQuery,
23
+ pickupQuery,
24
+ pickupTypeDefs,
23
25
  };
24
26
 
25
27
  const app = new Plugin({
@@ -43,31 +45,6 @@ describe('search tests', () => {
43
45
  // nada
44
46
  });
45
47
  describe('utilities', () => {
46
- describe('pickUnit', () => {
47
- it('adult', () => {
48
- const result = Plugin.pickUnit(fixtureUnits, [{ age: 40 }]);
49
- expect(result.length).toBe(1);
50
- expect(result[0]).toContainObject([{ id: 'adult' }]);
51
- });
52
- it('child', () => {
53
- const result = Plugin.pickUnit(fixtureUnits, [{ age: 10 }]);
54
- expect(result.length).toBe(1);
55
- expect(result[0]).toContainObject([{ id: 'child' }]);
56
- });
57
- it('senior', () => {
58
- const result = Plugin.pickUnit(fixtureUnits, [{ age: 70 }]);
59
- expect(result.length).toBe(1);
60
- expect(result[0]).toContainObject([{ id: 'senior' }]);
61
- });
62
- it('family', () => {
63
- const result = Plugin.pickUnit(fixtureUnits, [
64
- { age: 70 }, { age: 32 }, { age: 32 }, { age: 14 },
65
- ]);
66
- expect(result.length).toBe(1);
67
- expect(result[0]).toContainObject([{ id: 'family' }]);
68
- });
69
- it.todo('family + one');
70
- });
71
48
  describe('validateToken', () => {
72
49
  it('valid token', async () => {
73
50
  const retVal = await app.validateToken({
@@ -331,5 +308,13 @@ describe('search tests', () => {
331
308
  expect(R.path(['supplierBookingId'], booking)).toBeTruthy();
332
309
  expect(R.path(['cancellable'], booking)).toBeTruthy();
333
310
  });
311
+ it('should be able to get a list of pickuppoints', async () => {
312
+ const retVal = await app.getPickupPoints({
313
+ token,
314
+ typeDefsAndQueries,
315
+ });
316
+ expect(Array.isArray(retVal.pickupPoints)).toBeTruthy();
317
+ expect(R.path(['pickupPoints', 0, 'id'], retVal)).toBeTruthy();
318
+ });
334
319
  });
335
320
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-ventrata",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "description": "Ventrata's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -10,9 +10,10 @@ const capitalize = sParam => {
10
10
  const resolvers = {
11
11
  Query: {
12
12
  id: R.path(['id']),
13
- orderId: R.path(['orderReference']),
14
13
  bookingId: R.path(['id']),
14
+ orderId: R.path(['orderReference']),
15
15
  supplierBookingId: R.path(['supplierReference']),
16
+ resellerReference: R.propOr('', 'resellerReference'),
16
17
  status: e => capitalize(R.path(['status'], e)),
17
18
  productId: R.path(['product', 'id']),
18
19
  productName: root => R.path(['product', 'title'], root) || R.path(['product', 'internalName'], root),
@@ -44,7 +45,6 @@ const resolvers = {
44
45
  },
45
46
  optionId: R.path(['option', 'id']),
46
47
  optionName: root => R.path(['option', 'title'], root) || R.path(['option', 'internalName'], root),
47
- resellerReference: R.propOr('', 'resellerReference'),
48
48
  publicUrl: () => null,
49
49
  privateUrl: () => null,
50
50
  pickupRequested: R.prop('pickupRequested'),
@@ -0,0 +1,28 @@
1
+ const { makeExecutableSchema } = require('@graphql-tools/schema');
2
+ const R = require('ramda');
3
+ const { graphql } = require('graphql');
4
+
5
+ const resolvers = {
6
+ Query: {
7
+ id: R.path(['id']),
8
+ name: R.path(['name']),
9
+ },
10
+ };
11
+
12
+ const translatePickupPoint = async ({ rootValue, typeDefs, query }) => {
13
+ const schema = makeExecutableSchema({
14
+ typeDefs,
15
+ resolvers,
16
+ });
17
+ const retVal = await graphql({
18
+ schema,
19
+ rootValue,
20
+ source: query,
21
+ });
22
+ if (retVal.errors) throw new Error(retVal.errors);
23
+ return retVal.data;
24
+ };
25
+
26
+ module.exports = {
27
+ translatePickupPoint,
28
+ };