ti2 1.0.121 → 1.0.123
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/README.md +28 -1
- package/__tests__/plugin-capabilities.js +42 -0
- package/api.yml +84 -12
- package/controllers/README.md +25 -35
- package/controllers/__tests__/bookings-searchProducts.js +481 -216
- package/controllers/__tests__/product-search-ttr.js +39 -0
- package/controllers/__tests__/user.js +5 -1
- package/controllers/app.js +20 -17
- package/controllers/bookings.js +337 -163
- package/controllers/user.js +1 -0
- package/index.js +11 -1
- package/package.json +1 -1
- package/worker/__tests__/job-api.js +55 -3
- package/worker/__tests__/job-plugin.js +3 -3
- package/worker/index.js +16 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const bookings = require('../bookings');
|
|
2
|
+
|
|
3
|
+
describe('resolveProductSearchTtrSeconds', () => {
|
|
4
|
+
const oneDay = bookings.oneDayProductSearchTtrSeconds;
|
|
5
|
+
const weekly = bookings.defaultProductSearchTtrSeconds;
|
|
6
|
+
|
|
7
|
+
it('uses a seven-day default when no TTR is configured', () => {
|
|
8
|
+
expect(bookings.resolveProductSearchTtrSeconds({}, {})).toBe(weekly);
|
|
9
|
+
expect(weekly).toBe(oneDay * 7);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('keeps an explicit one-day token TTR', () => {
|
|
13
|
+
expect(bookings.resolveProductSearchTtrSeconds({
|
|
14
|
+
ttlForProducts: oneDay,
|
|
15
|
+
}, {})).toBe(oneDay);
|
|
16
|
+
expect(bookings.resolveProductSearchTtrSeconds({
|
|
17
|
+
ttlForProducts: String(oneDay),
|
|
18
|
+
}, {})).toBe(String(oneDay));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('keeps an explicit non-legacy TTR, including short test values', () => {
|
|
22
|
+
expect(bookings.resolveProductSearchTtrSeconds({
|
|
23
|
+
ttlForProducts: 2,
|
|
24
|
+
}, {})).toBe(2);
|
|
25
|
+
expect(bookings.resolveProductSearchTtrSeconds({
|
|
26
|
+
ttlForProducts: oneDay * 2,
|
|
27
|
+
}, {})).toBe(oneDay * 2);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('keeps an explicit one-day plugin cacheSettings TTR', () => {
|
|
31
|
+
expect(bookings.resolveProductSearchTtrSeconds({}, {
|
|
32
|
+
cacheSettings: {
|
|
33
|
+
bookingsProductSearch: {
|
|
34
|
+
ttr: oneDay,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
})).toBe(oneDay);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -40,6 +40,9 @@ describe('user', () => {
|
|
|
40
40
|
plugins,
|
|
41
41
|
} = await testUtils({
|
|
42
42
|
plugins: [appName],
|
|
43
|
+
pluginCapabilities: {
|
|
44
|
+
[appName]: { weeklyProductCatalogSync: true },
|
|
45
|
+
},
|
|
43
46
|
}));
|
|
44
47
|
await db.models.UserAppKey.destroy({ where: { userId } });
|
|
45
48
|
// create an App
|
|
@@ -353,10 +356,11 @@ describe('user', () => {
|
|
|
353
356
|
expect(returnValue.success).toBe(true);
|
|
354
357
|
});
|
|
355
358
|
it('should be able to get all the methods for an app', async () => {
|
|
356
|
-
const { methods } = await doApiGet({
|
|
359
|
+
const { capabilities, methods } = await doApiGet({
|
|
357
360
|
url: `/app/${appName}/methods`,
|
|
358
361
|
token: userKey,
|
|
359
362
|
});
|
|
363
|
+
expect(capabilities).toEqual({ weeklyProductCatalogSync: true });
|
|
360
364
|
expect(methods).toEqual(
|
|
361
365
|
expect.arrayContaining([
|
|
362
366
|
'validateToken', 'getProduct',
|
package/controllers/app.js
CHANGED
|
@@ -50,7 +50,6 @@ const tokenTemplate = async (req, res, next) => {
|
|
|
50
50
|
try {
|
|
51
51
|
const thePlugin = req.app.plugins.find(({ name }) => name === pluginName);
|
|
52
52
|
assert(thePlugin);
|
|
53
|
-
let template = thePlugin.tokenTemplate();
|
|
54
53
|
const safeRegExp = el => {
|
|
55
54
|
if (!el || !(el.regExp instanceof RegExp)) {
|
|
56
55
|
return el;
|
|
@@ -64,24 +63,28 @@ const tokenTemplate = async (req, res, next) => {
|
|
|
64
63
|
},
|
|
65
64
|
};
|
|
66
65
|
};
|
|
67
|
-
template = R.map(safeRegExp,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
66
|
+
const template = R.map(safeRegExp, {
|
|
67
|
+
...thePlugin.tokenTemplate(),
|
|
68
|
+
// ttlProducts and doNotCallPluginForProducts are being used at ti2 level
|
|
69
|
+
// hence we should just by default allow them for all ti2 plugins
|
|
70
|
+
ttlForProducts: {
|
|
71
|
+
type: 'number',
|
|
72
|
+
regExp: /.+/,
|
|
73
|
+
default: 60 * 60 * 24 * 7, // 7 days; weekly full product catalog refresh
|
|
74
|
+
},
|
|
75
|
+
doNotCallPluginForProducts: {
|
|
76
|
+
type: 'boolean',
|
|
77
|
+
regExp: /.+/,
|
|
78
|
+
default: false,
|
|
79
|
+
},
|
|
80
|
+
productSearchOmitServiceCodes: {
|
|
81
|
+
type: 'text',
|
|
82
|
+
regExp: /^[\sA-Za-z0-9,]*$/,
|
|
83
|
+
default: '',
|
|
84
|
+
description: 'Service codes that every product search for this integration must omit',
|
|
83
85
|
},
|
|
84
86
|
});
|
|
87
|
+
return res.json({ template });
|
|
85
88
|
} catch (err) {
|
|
86
89
|
return next(err);
|
|
87
90
|
}
|