ti2 1.0.7 → 1.0.11
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/.github/workflows/deploy.yml +1 -2
- package/.github/workflows/tests.yml +32 -8
- package/README.md +51 -11
- package/api.yml +504 -15
- package/controllers/__tests__/admin.js +27 -30
- package/controllers/__tests__/app.js +33 -37
- package/controllers/__tests__/bookings.js +129 -35
- package/controllers/__tests__/ping.js +5 -10
- package/controllers/__tests__/user.js +57 -62
- package/controllers/admin.js +28 -5
- package/controllers/bookings.js +114 -1
- package/controllers/user.js +2 -2
- package/index.js +3 -1
- package/jsdoc.conf.json +25 -0
- package/migrations/20200114173707-addTCApp.js +0 -3
- package/package.json +9 -6
- package/seeders/.gitkeep +0 -0
- package/test/plugin.js +415 -0
- package/test/slugify.js +21 -0
- package/test/utils.js +95 -96
package/test/utils.js
CHANGED
|
@@ -1,111 +1,110 @@
|
|
|
1
|
+
/* global afterAll */
|
|
2
|
+
|
|
1
3
|
const chance = require('chance').Chance();
|
|
2
4
|
const request = require('supertest');
|
|
3
5
|
const assert = require('assert');
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
6
|
+
const appReq = require('../index');
|
|
7
|
+
const Plugin = require('./plugin');
|
|
8
|
+
const slugify = require('./slugify');
|
|
9
|
+
const sqldb = require('../models/db');
|
|
7
10
|
|
|
8
11
|
const { env: { adminKey } } = process;
|
|
9
12
|
|
|
10
13
|
const timeout = ms => (new Promise(resolve => setTimeout(resolve, ms)));
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
afterAll(async () => {
|
|
16
|
+
await sqldb.connectionManager.close();
|
|
17
|
+
});
|
|
18
|
+
module.exports = (appParams = {}) => {
|
|
19
|
+
const plugins = (() => {
|
|
20
|
+
if (Array.isArray(appParams.plugins)) {
|
|
21
|
+
const retVal = {};
|
|
22
|
+
appParams.plugins.forEach(pluginName => {
|
|
23
|
+
retVal[pluginName] = Plugin;
|
|
24
|
+
});
|
|
25
|
+
return retVal;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
mockName: Plugin,
|
|
29
|
+
};
|
|
30
|
+
})();
|
|
31
|
+
const app = appReq({
|
|
32
|
+
startServer: false,
|
|
33
|
+
...appParams,
|
|
34
|
+
plugins,
|
|
35
|
+
});
|
|
31
36
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const appSetup = async ({ userId: userIdParam } = {}) => {
|
|
40
|
-
const userId = userIdParam || chance.guid();
|
|
41
|
-
const appName1 = slugify(
|
|
42
|
-
chance.company(),
|
|
43
|
-
).toLowerCase();
|
|
44
|
-
const newApp = {
|
|
45
|
-
name: appName1,
|
|
46
|
-
packageName: `ti2-${appName1}`,
|
|
47
|
-
adminEmail: chance.email(),
|
|
48
|
-
};
|
|
49
|
-
const apiKey1 = chance.guid();
|
|
50
|
-
const token = {
|
|
51
|
-
endpoint: chance.url(),
|
|
52
|
-
apiKey: apiKey1,
|
|
53
|
-
};
|
|
54
|
-
const { body: { value: appKey } } = await request(app)
|
|
55
|
-
.post('/app')
|
|
56
|
-
.set('Authorization', `Bearer ${adminKey}`)
|
|
57
|
-
.send(newApp);
|
|
58
|
-
await request(app)
|
|
59
|
-
.post(`/${newApp.name}/${userId}`)
|
|
60
|
-
.set('Authorization', `Bearer ${appKey}`)
|
|
61
|
-
.send({
|
|
62
|
-
tokenHint: token.apiKey.split('-')[0],
|
|
63
|
-
token,
|
|
64
|
-
});
|
|
65
|
-
return {
|
|
66
|
-
newApp,
|
|
37
|
+
const doApi = async ({
|
|
38
|
+
query,
|
|
39
|
+
verb,
|
|
40
|
+
payload,
|
|
41
|
+
url,
|
|
67
42
|
token,
|
|
68
|
-
|
|
69
|
-
|
|
43
|
+
expectStatusCode = 200,
|
|
44
|
+
rawResponse = false,
|
|
45
|
+
}) => {
|
|
46
|
+
let resp;
|
|
47
|
+
if (token) {
|
|
48
|
+
resp = await request(app)[verb](url)
|
|
49
|
+
.set({ Authorization: `Bearer ${token}` })
|
|
50
|
+
.query(query)
|
|
51
|
+
.send(payload);
|
|
52
|
+
} else {
|
|
53
|
+
resp = await request(app)[verb](url).query(query).send(payload);
|
|
54
|
+
}
|
|
55
|
+
// if (resp.statusCode !== 200) assert.strictEqual(resp, `${url}-${expectStatusCode}`);
|
|
56
|
+
assert.strictEqual(`${url}-${resp.statusCode}`, `${url}-${expectStatusCode}`);
|
|
57
|
+
if (rawResponse) return resp;
|
|
58
|
+
return resp.body;
|
|
70
59
|
};
|
|
71
|
-
};
|
|
72
60
|
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
verb
|
|
76
|
-
|
|
77
|
-
url,
|
|
78
|
-
token,
|
|
79
|
-
expectStatusCode = 200,
|
|
80
|
-
rawResponse = false,
|
|
81
|
-
}) => {
|
|
82
|
-
let resp;
|
|
83
|
-
if (token) {
|
|
84
|
-
resp = await request(app)[verb](url)
|
|
85
|
-
.set({ Authorization: `Bearer ${token}` })
|
|
86
|
-
.query(query)
|
|
87
|
-
.send(payload);
|
|
88
|
-
} else {
|
|
89
|
-
resp = await request(app)[verb](url).query(query).send(payload);
|
|
90
|
-
}
|
|
91
|
-
// if (resp.statusCode !== 200) assert.strictEqual(resp, `${url}-${expectStatusCode}`);
|
|
92
|
-
assert.strictEqual(`${url}-${resp.statusCode}`, `${url}-${expectStatusCode}`);
|
|
93
|
-
if (rawResponse) return resp;
|
|
94
|
-
return resp.body;
|
|
95
|
-
};
|
|
61
|
+
const doApiGet = params => doApi({ ...params, verb: 'get' });
|
|
62
|
+
const doApiPost = params => doApi({ ...params, verb: 'post' });
|
|
63
|
+
const doApiPut = params => doApi({ ...params, verb: 'put' });
|
|
64
|
+
const doApiDelete = params => doApi({ ...params, verb: 'delete' });
|
|
96
65
|
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
|
|
66
|
+
const appSetup = async ({ userId: userIdParam } = {}) => {
|
|
67
|
+
const userId = userIdParam || chance.guid();
|
|
68
|
+
const appName1 = slugify(
|
|
69
|
+
chance.company(),
|
|
70
|
+
).toLowerCase();
|
|
71
|
+
const newApp = {
|
|
72
|
+
name: appName1,
|
|
73
|
+
packageName: `ti2-${appName1}`,
|
|
74
|
+
adminEmail: chance.email(),
|
|
75
|
+
};
|
|
76
|
+
const apiKey1 = chance.guid();
|
|
77
|
+
const token = {
|
|
78
|
+
endpoint: chance.url(),
|
|
79
|
+
apiKey: apiKey1,
|
|
80
|
+
};
|
|
81
|
+
const { body: { value: appKey } } = await request(app)
|
|
82
|
+
.post('/app')
|
|
83
|
+
.set('Authorization', `Bearer ${adminKey}`)
|
|
84
|
+
.send(newApp);
|
|
85
|
+
await request(app)
|
|
86
|
+
.post(`/${newApp.name}/${userId}`)
|
|
87
|
+
.set('Authorization', `Bearer ${appKey}`)
|
|
88
|
+
.send({
|
|
89
|
+
tokenHint: token.apiKey.split('-')[0],
|
|
90
|
+
token,
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
newApp,
|
|
94
|
+
token,
|
|
95
|
+
appKey,
|
|
96
|
+
userId,
|
|
97
|
+
};
|
|
98
|
+
};
|
|
101
99
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
100
|
+
return {
|
|
101
|
+
appSetup,
|
|
102
|
+
doApiDelete,
|
|
103
|
+
doApiGet,
|
|
104
|
+
doApiPost,
|
|
105
|
+
doApiPut,
|
|
106
|
+
slugify,
|
|
107
|
+
timeout,
|
|
108
|
+
plugins: app.plugins,
|
|
109
|
+
};
|
|
111
110
|
};
|