@appsemble/cli 0.30.14-test.6 → 0.32.1-test.15
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 +3 -3
- package/commands/app/create.js +9 -4
- package/commands/app/delete.js +1 -1
- package/commands/app/export.js +1 -1
- package/commands/app/patch.d.ts +2 -0
- package/commands/app/patch.js +8 -0
- package/commands/app/update.js +1 -1
- package/commands/asset/publish.js +1 -1
- package/commands/cleanupSoftDeletedRecords.d.ts +6 -0
- package/commands/cleanupSoftDeletedRecords.js +40 -0
- package/commands/config/get.js +6 -2
- package/commands/config/set.js +6 -1
- package/commands/migrate.js +19 -0
- package/commands/serve.js +5 -1
- package/commands/start.js +19 -0
- package/commands/synchronizeTrainings.d.ts +6 -0
- package/commands/synchronizeTrainings.js +40 -0
- package/index.js +5 -0
- package/lib/app.d.ts +8 -0
- package/lib/app.js +59 -17
- package/lib/asset.d.ts +1 -1
- package/lib/authentication.js +4 -4
- package/lib/block.js +15 -6
- package/lib/coercers.js +1 -0
- package/lib/config.js +26 -18
- package/lib/createServers.js +3 -1
- package/lib/group.d.ts +1 -1
- package/lib/group.js +7 -6
- package/lib/output.js +3 -1
- package/lib/processCss.js +1 -1
- package/lib/project.js +3 -2
- package/lib/serverImport.d.ts +1 -1
- package/lib/serverImport.js +1 -1
- package/package.json +19 -16
- package/server/db/methods.js +3 -0
- package/server/options/createAppAsset.d.ts +1 -1
- package/server/options/createAppAsset.js +5 -6
- package/server/options/createAppResourcesWithAssets.js +4 -6
- package/server/options/createSettings.js +1 -1
- package/server/options/createTheme.js +2 -0
- package/server/options/getAppAsset.js +5 -10
- package/server/options/getAppAssets.js +5 -9
- package/server/options/getAppScreenshots.js +3 -3
- package/server/options/getBlockAsset.js +3 -0
- package/server/options/getTheme.js +1 -0
- package/server/options/options.js +2 -0
- package/templates/apps/empty/app-definition.yaml +2 -2
- package/templates/blocks/mini-jsx/package.json +4 -1
- package/templates/blocks/mini-jsx/src/index.tsx +1 -1
- package/templates/blocks/preact/package.json +5 -2
- package/templates/blocks/vanilla/package.json +4 -1
- package/vitest.setup.js +11 -2
- package/lib/app.test.d.ts +0 -1
- package/lib/app.test.js +0 -2212
- package/lib/asset.test.d.ts +0 -1
- package/lib/asset.test.js +0 -105
- package/lib/block.test.d.ts +0 -1
- package/lib/block.test.js +0 -235
- package/lib/coercers.test.d.ts +0 -1
- package/lib/coercers.test.js +0 -27
- package/lib/config.test.d.ts +0 -1
- package/lib/config.test.js +0 -239
- package/lib/group.test.d.ts +0 -1
- package/lib/group.test.js +0 -616
- package/lib/organization.test.d.ts +0 -1
- package/lib/organization.test.js +0 -222
- package/lib/resource.test.d.ts +0 -1
- package/lib/resource.test.js +0 -393
- package/server/db/methods.test.d.ts +0 -1
- package/server/db/methods.test.js +0 -366
- package/server/options/parseQuery.test.d.ts +0 -1
- package/server/options/parseQuery.test.js +0 -46
package/lib/group.test.js
DELETED
|
@@ -1,616 +0,0 @@
|
|
|
1
|
-
import { createServer, createTestAppMember, createTestUser, models, setArgv, } from '@appsemble/server';
|
|
2
|
-
import { PredefinedOrganizationRole } from '@appsemble/types';
|
|
3
|
-
import { setTestApp } from 'axios-test-instance';
|
|
4
|
-
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
-
import { createGroup, deleteGroup, deleteMember, inviteMember, resolveAnnotations, updateGroup, updateMember, } from './group.js';
|
|
6
|
-
import { initAxios } from './initAxios.js';
|
|
7
|
-
import { authorizeCLI } from './testUtils.js';
|
|
8
|
-
const { App, AppMember, BlockVersion, Group, GroupInvite, GroupMember, Organization, OrganizationMember, } = models;
|
|
9
|
-
const argv = { host: 'http://localhost', secret: 'test', aesSecret: 'testSecret' };
|
|
10
|
-
let user;
|
|
11
|
-
let organization;
|
|
12
|
-
let testApp;
|
|
13
|
-
describe('group', () => {
|
|
14
|
-
beforeAll(() => {
|
|
15
|
-
vi.useFakeTimers();
|
|
16
|
-
setArgv(argv);
|
|
17
|
-
});
|
|
18
|
-
beforeEach(async () => {
|
|
19
|
-
vi.clearAllTimers();
|
|
20
|
-
vi.setSystemTime(0);
|
|
21
|
-
const server = await createServer();
|
|
22
|
-
testApp = await setTestApp(server);
|
|
23
|
-
initAxios({ remote: testApp.defaults.baseURL });
|
|
24
|
-
user = await createTestUser();
|
|
25
|
-
organization = await Organization.create({
|
|
26
|
-
id: 'testorganization',
|
|
27
|
-
name: 'Test Organization',
|
|
28
|
-
});
|
|
29
|
-
await OrganizationMember.create({
|
|
30
|
-
OrganizationId: organization.id,
|
|
31
|
-
UserId: user.id,
|
|
32
|
-
role: PredefinedOrganizationRole.Owner,
|
|
33
|
-
});
|
|
34
|
-
await Organization.create({ id: 'appsemble', name: 'Appsemble' });
|
|
35
|
-
await BlockVersion.create({
|
|
36
|
-
name: 'test',
|
|
37
|
-
OrganizationId: 'appsemble',
|
|
38
|
-
version: '0.0.0',
|
|
39
|
-
parameters: {
|
|
40
|
-
type: 'object',
|
|
41
|
-
properties: {
|
|
42
|
-
foo: {
|
|
43
|
-
type: 'number',
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
afterAll(() => {
|
|
50
|
-
vi.useRealTimers();
|
|
51
|
-
});
|
|
52
|
-
describe('createGroup', () => {
|
|
53
|
-
it('should create a new group', async () => {
|
|
54
|
-
const app = await App.create({
|
|
55
|
-
definition: {
|
|
56
|
-
name: 'Test App',
|
|
57
|
-
defaultPage: 'Test Page',
|
|
58
|
-
security: {
|
|
59
|
-
groups: {
|
|
60
|
-
join: 'anyone',
|
|
61
|
-
invite: [],
|
|
62
|
-
},
|
|
63
|
-
default: {
|
|
64
|
-
role: 'Reader',
|
|
65
|
-
policy: 'everyone',
|
|
66
|
-
},
|
|
67
|
-
roles: {
|
|
68
|
-
Reader: {},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
path: 'test-app',
|
|
73
|
-
vapidPublicKey: 'a',
|
|
74
|
-
vapidPrivateKey: 'b',
|
|
75
|
-
OrganizationId: organization.id,
|
|
76
|
-
});
|
|
77
|
-
const clientCredentials = await authorizeCLI('groups:write', testApp);
|
|
78
|
-
await createGroup({
|
|
79
|
-
appId: app.id,
|
|
80
|
-
name: 'test',
|
|
81
|
-
remote: testApp.defaults.baseURL,
|
|
82
|
-
clientCredentials,
|
|
83
|
-
});
|
|
84
|
-
const group = await Group.findOne();
|
|
85
|
-
expect(group).toMatchInlineSnapshot(`
|
|
86
|
-
{
|
|
87
|
-
"AppId": 1,
|
|
88
|
-
"annotations": null,
|
|
89
|
-
"created": 1970-01-01T00:00:00.000Z,
|
|
90
|
-
"demo": false,
|
|
91
|
-
"id": 1,
|
|
92
|
-
"name": "test",
|
|
93
|
-
"updated": 1970-01-01T00:00:00.000Z,
|
|
94
|
-
}
|
|
95
|
-
`);
|
|
96
|
-
});
|
|
97
|
-
it('should throw if app does not exist', async () => {
|
|
98
|
-
const clientCredentials = await authorizeCLI('groups:write', testApp);
|
|
99
|
-
await expect(() => createGroup({
|
|
100
|
-
appId: 1,
|
|
101
|
-
name: 'test',
|
|
102
|
-
remote: testApp.defaults.baseURL,
|
|
103
|
-
clientCredentials,
|
|
104
|
-
})).rejects.toThrow('Request failed with status code 404');
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
describe('deleteGroup', () => {
|
|
108
|
-
it('should delete a group', async () => {
|
|
109
|
-
const app = await App.create({
|
|
110
|
-
definition: {
|
|
111
|
-
name: 'Test App',
|
|
112
|
-
defaultPage: 'Test Page',
|
|
113
|
-
security: {
|
|
114
|
-
groups: {
|
|
115
|
-
join: 'anyone',
|
|
116
|
-
invite: [],
|
|
117
|
-
},
|
|
118
|
-
default: {
|
|
119
|
-
role: 'Reader',
|
|
120
|
-
policy: 'everyone',
|
|
121
|
-
},
|
|
122
|
-
roles: {
|
|
123
|
-
Reader: {},
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
path: 'test-app',
|
|
128
|
-
vapidPublicKey: 'a',
|
|
129
|
-
vapidPrivateKey: 'b',
|
|
130
|
-
OrganizationId: organization.id,
|
|
131
|
-
});
|
|
132
|
-
const group = await Group.create({
|
|
133
|
-
AppId: app.id,
|
|
134
|
-
name: 'test',
|
|
135
|
-
});
|
|
136
|
-
const clientCredentials = await authorizeCLI('groups:write', testApp);
|
|
137
|
-
await deleteGroup({
|
|
138
|
-
appId: app.id,
|
|
139
|
-
id: group.id,
|
|
140
|
-
remote: testApp.defaults.baseURL,
|
|
141
|
-
clientCredentials,
|
|
142
|
-
});
|
|
143
|
-
expect(group).toMatchInlineSnapshot(`
|
|
144
|
-
{
|
|
145
|
-
"AppId": 1,
|
|
146
|
-
"annotations": null,
|
|
147
|
-
"created": 1970-01-01T00:00:00.000Z,
|
|
148
|
-
"demo": false,
|
|
149
|
-
"id": 1,
|
|
150
|
-
"name": "test",
|
|
151
|
-
"updated": 1970-01-01T00:00:00.000Z,
|
|
152
|
-
}
|
|
153
|
-
`);
|
|
154
|
-
const foundGroup = await Group.findOne();
|
|
155
|
-
expect(foundGroup).toBeNull();
|
|
156
|
-
});
|
|
157
|
-
it('should throw an error if the group does not exist', async () => {
|
|
158
|
-
const app = await App.create({
|
|
159
|
-
definition: {
|
|
160
|
-
name: 'Test App',
|
|
161
|
-
defaultPage: 'Test Page',
|
|
162
|
-
security: {
|
|
163
|
-
groups: {
|
|
164
|
-
join: 'anyone',
|
|
165
|
-
invite: [],
|
|
166
|
-
},
|
|
167
|
-
default: {
|
|
168
|
-
role: 'Reader',
|
|
169
|
-
policy: 'everyone',
|
|
170
|
-
},
|
|
171
|
-
roles: {
|
|
172
|
-
Reader: {},
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
path: 'test-app',
|
|
177
|
-
vapidPublicKey: 'a',
|
|
178
|
-
vapidPrivateKey: 'b',
|
|
179
|
-
OrganizationId: organization.id,
|
|
180
|
-
});
|
|
181
|
-
const clientCredentials = await authorizeCLI('groups:write', testApp);
|
|
182
|
-
await expect(() => deleteGroup({ appId: app.id, id: 1, remote: testApp.defaults.baseURL, clientCredentials })).rejects.toThrow('Request failed with status code 404');
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
describe('updateGroup', () => {
|
|
186
|
-
it('should update a group', async () => {
|
|
187
|
-
const app = await App.create({
|
|
188
|
-
definition: {
|
|
189
|
-
name: 'Test App',
|
|
190
|
-
defaultPage: 'Test Page',
|
|
191
|
-
security: {
|
|
192
|
-
groups: {
|
|
193
|
-
join: 'anyone',
|
|
194
|
-
invite: [],
|
|
195
|
-
},
|
|
196
|
-
default: {
|
|
197
|
-
role: 'Reader',
|
|
198
|
-
policy: 'everyone',
|
|
199
|
-
},
|
|
200
|
-
roles: {
|
|
201
|
-
Reader: {},
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
path: 'test-app',
|
|
206
|
-
vapidPublicKey: 'a',
|
|
207
|
-
vapidPrivateKey: 'b',
|
|
208
|
-
OrganizationId: organization.id,
|
|
209
|
-
});
|
|
210
|
-
const group = await Group.create({
|
|
211
|
-
AppId: app.id,
|
|
212
|
-
name: 'test',
|
|
213
|
-
});
|
|
214
|
-
await authorizeCLI('groups:write', testApp);
|
|
215
|
-
await updateGroup({
|
|
216
|
-
appId: app.id,
|
|
217
|
-
id: group.id,
|
|
218
|
-
remote: testApp.defaults.baseURL,
|
|
219
|
-
name: 'test2',
|
|
220
|
-
});
|
|
221
|
-
await group.reload();
|
|
222
|
-
expect(group).toMatchInlineSnapshot(`
|
|
223
|
-
{
|
|
224
|
-
"AppId": 1,
|
|
225
|
-
"annotations": null,
|
|
226
|
-
"created": 1970-01-01T00:00:00.000Z,
|
|
227
|
-
"demo": false,
|
|
228
|
-
"id": 1,
|
|
229
|
-
"name": "test2",
|
|
230
|
-
"updated": 1970-01-01T00:00:00.000Z,
|
|
231
|
-
}
|
|
232
|
-
`);
|
|
233
|
-
});
|
|
234
|
-
it('should throw an error if the group does not exist', async () => {
|
|
235
|
-
const app = await App.create({
|
|
236
|
-
definition: {
|
|
237
|
-
name: 'Test App',
|
|
238
|
-
defaultPage: 'Test Page',
|
|
239
|
-
security: {
|
|
240
|
-
groups: {
|
|
241
|
-
join: 'anyone',
|
|
242
|
-
invite: [],
|
|
243
|
-
},
|
|
244
|
-
default: {
|
|
245
|
-
role: 'Reader',
|
|
246
|
-
policy: 'everyone',
|
|
247
|
-
},
|
|
248
|
-
roles: {
|
|
249
|
-
Reader: {},
|
|
250
|
-
},
|
|
251
|
-
},
|
|
252
|
-
},
|
|
253
|
-
path: 'test-app',
|
|
254
|
-
vapidPublicKey: 'a',
|
|
255
|
-
vapidPrivateKey: 'b',
|
|
256
|
-
OrganizationId: organization.id,
|
|
257
|
-
});
|
|
258
|
-
const group = await Group.create({
|
|
259
|
-
AppId: app.id,
|
|
260
|
-
name: 'test',
|
|
261
|
-
});
|
|
262
|
-
await group.destroy();
|
|
263
|
-
const clientCredentials = await authorizeCLI('groups:write', testApp);
|
|
264
|
-
await expect(() => updateGroup({
|
|
265
|
-
appId: app.id,
|
|
266
|
-
id: group.id,
|
|
267
|
-
remote: testApp.defaults.baseURL,
|
|
268
|
-
name: 'test2',
|
|
269
|
-
clientCredentials,
|
|
270
|
-
})).rejects.toThrow('Request failed with status code 404');
|
|
271
|
-
});
|
|
272
|
-
it('should throw an error if the user is not authenticated', async () => {
|
|
273
|
-
const app = await App.create({
|
|
274
|
-
definition: {
|
|
275
|
-
name: 'Test App',
|
|
276
|
-
defaultPage: 'Test Page',
|
|
277
|
-
security: {
|
|
278
|
-
groups: {
|
|
279
|
-
join: 'anyone',
|
|
280
|
-
invite: [],
|
|
281
|
-
},
|
|
282
|
-
default: {
|
|
283
|
-
role: 'Reader',
|
|
284
|
-
policy: 'everyone',
|
|
285
|
-
},
|
|
286
|
-
roles: {
|
|
287
|
-
Reader: {},
|
|
288
|
-
},
|
|
289
|
-
},
|
|
290
|
-
},
|
|
291
|
-
path: 'test-app',
|
|
292
|
-
vapidPublicKey: 'a',
|
|
293
|
-
vapidPrivateKey: 'b',
|
|
294
|
-
OrganizationId: organization.id,
|
|
295
|
-
});
|
|
296
|
-
const group = await Group.create({
|
|
297
|
-
AppId: app.id,
|
|
298
|
-
name: 'test',
|
|
299
|
-
});
|
|
300
|
-
await expect(() => updateGroup({
|
|
301
|
-
appId: app.id,
|
|
302
|
-
id: group.id,
|
|
303
|
-
remote: testApp.defaults.baseURL,
|
|
304
|
-
name: 'test2',
|
|
305
|
-
})).rejects.toThrow('Request failed with status code 401');
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
describe('inviteMember', () => {
|
|
309
|
-
it('should invite a member to a group', async () => {
|
|
310
|
-
const app = await App.create({
|
|
311
|
-
definition: {
|
|
312
|
-
name: 'Test App',
|
|
313
|
-
defaultPage: 'Test Page',
|
|
314
|
-
security: {
|
|
315
|
-
default: {
|
|
316
|
-
role: 'Reader',
|
|
317
|
-
policy: 'everyone',
|
|
318
|
-
},
|
|
319
|
-
roles: {
|
|
320
|
-
Reader: {},
|
|
321
|
-
},
|
|
322
|
-
},
|
|
323
|
-
},
|
|
324
|
-
path: 'test-app',
|
|
325
|
-
vapidPublicKey: 'a',
|
|
326
|
-
vapidPrivateKey: 'b',
|
|
327
|
-
OrganizationId: organization.id,
|
|
328
|
-
});
|
|
329
|
-
const group = await Group.create({
|
|
330
|
-
AppId: app.id,
|
|
331
|
-
name: 'test',
|
|
332
|
-
});
|
|
333
|
-
await AppMember.create({
|
|
334
|
-
email: user.primaryEmail,
|
|
335
|
-
AppId: app.id,
|
|
336
|
-
UserId: user.id,
|
|
337
|
-
role: 'Reader',
|
|
338
|
-
name: user.name,
|
|
339
|
-
});
|
|
340
|
-
await authorizeCLI('groups:write', testApp);
|
|
341
|
-
await inviteMember({
|
|
342
|
-
appId: app.id,
|
|
343
|
-
id: group.id,
|
|
344
|
-
remote: testApp.defaults.baseURL,
|
|
345
|
-
user: user.primaryEmail,
|
|
346
|
-
role: 'Reader',
|
|
347
|
-
});
|
|
348
|
-
const invite = await GroupInvite.findOne();
|
|
349
|
-
expect(invite.dataValues).toMatchInlineSnapshot({
|
|
350
|
-
key: expect.any(String),
|
|
351
|
-
}, `
|
|
352
|
-
{
|
|
353
|
-
"GroupId": 1,
|
|
354
|
-
"created": 1970-01-01T00:00:00.000Z,
|
|
355
|
-
"email": "test@example.com",
|
|
356
|
-
"key": Any<String>,
|
|
357
|
-
"role": "Reader",
|
|
358
|
-
"updated": 1970-01-01T00:00:00.000Z,
|
|
359
|
-
}
|
|
360
|
-
`);
|
|
361
|
-
});
|
|
362
|
-
it('should throw an error if the group does not exist', async () => {
|
|
363
|
-
const app = await App.create({
|
|
364
|
-
definition: {
|
|
365
|
-
name: 'Test App',
|
|
366
|
-
defaultPage: 'Test Page',
|
|
367
|
-
security: {
|
|
368
|
-
groups: {
|
|
369
|
-
join: 'anyone',
|
|
370
|
-
invite: [],
|
|
371
|
-
},
|
|
372
|
-
default: {
|
|
373
|
-
role: 'Reader',
|
|
374
|
-
policy: 'everyone',
|
|
375
|
-
},
|
|
376
|
-
roles: {
|
|
377
|
-
Reader: {},
|
|
378
|
-
},
|
|
379
|
-
},
|
|
380
|
-
},
|
|
381
|
-
path: 'test-app',
|
|
382
|
-
vapidPublicKey: 'a',
|
|
383
|
-
vapidPrivateKey: 'b',
|
|
384
|
-
OrganizationId: organization.id,
|
|
385
|
-
});
|
|
386
|
-
await authorizeCLI('groups:write', testApp);
|
|
387
|
-
await expect(() => inviteMember({
|
|
388
|
-
appId: app.id,
|
|
389
|
-
id: 10,
|
|
390
|
-
remote: testApp.defaults.baseURL,
|
|
391
|
-
user: user.primaryEmail,
|
|
392
|
-
role: 'Reader',
|
|
393
|
-
})).rejects.toThrow('Request failed with status code 400');
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
describe('updateMember', () => {
|
|
397
|
-
it('should update role of a group member', async () => {
|
|
398
|
-
const app = await App.create({
|
|
399
|
-
definition: {
|
|
400
|
-
name: 'Test App',
|
|
401
|
-
defaultPage: 'Test Page',
|
|
402
|
-
security: {
|
|
403
|
-
default: {
|
|
404
|
-
role: 'Reader',
|
|
405
|
-
policy: 'everyone',
|
|
406
|
-
},
|
|
407
|
-
roles: {
|
|
408
|
-
Reader: {},
|
|
409
|
-
Updater: {
|
|
410
|
-
inherits: ['Manager'],
|
|
411
|
-
},
|
|
412
|
-
},
|
|
413
|
-
},
|
|
414
|
-
},
|
|
415
|
-
path: 'test-app',
|
|
416
|
-
vapidPublicKey: 'a',
|
|
417
|
-
vapidPrivateKey: 'b',
|
|
418
|
-
OrganizationId: organization.id,
|
|
419
|
-
});
|
|
420
|
-
const group = await Group.create({
|
|
421
|
-
AppId: app.id,
|
|
422
|
-
name: 'test',
|
|
423
|
-
});
|
|
424
|
-
const member = await AppMember.create({
|
|
425
|
-
email: user.primaryEmail,
|
|
426
|
-
AppId: app.id,
|
|
427
|
-
UserId: user.id,
|
|
428
|
-
role: 'Updater',
|
|
429
|
-
name: user.name,
|
|
430
|
-
});
|
|
431
|
-
const groupMember = await GroupMember.create({
|
|
432
|
-
GroupId: group.id,
|
|
433
|
-
AppMemberId: member.id,
|
|
434
|
-
role: 'Reader',
|
|
435
|
-
});
|
|
436
|
-
await authorizeCLI('groups:write', testApp);
|
|
437
|
-
await updateMember({
|
|
438
|
-
appId: app.id,
|
|
439
|
-
remote: testApp.defaults.baseURL,
|
|
440
|
-
user: groupMember.id,
|
|
441
|
-
role: 'Updater',
|
|
442
|
-
id: group.id,
|
|
443
|
-
});
|
|
444
|
-
expect(groupMember.role).toBe('Reader');
|
|
445
|
-
await groupMember.reload();
|
|
446
|
-
expect(groupMember.role).toBe('Updater');
|
|
447
|
-
});
|
|
448
|
-
it('should throw an error if the user is not a GroupMember', async () => {
|
|
449
|
-
const app = await App.create({
|
|
450
|
-
definition: {
|
|
451
|
-
name: 'Test App',
|
|
452
|
-
defaultPage: 'Test Page',
|
|
453
|
-
security: {
|
|
454
|
-
groups: {
|
|
455
|
-
join: 'anyone',
|
|
456
|
-
invite: [],
|
|
457
|
-
},
|
|
458
|
-
default: {
|
|
459
|
-
role: 'Reader',
|
|
460
|
-
policy: 'everyone',
|
|
461
|
-
},
|
|
462
|
-
roles: {
|
|
463
|
-
Reader: {},
|
|
464
|
-
Updater: {
|
|
465
|
-
inherits: ['Manager'],
|
|
466
|
-
},
|
|
467
|
-
},
|
|
468
|
-
},
|
|
469
|
-
},
|
|
470
|
-
path: 'test-app',
|
|
471
|
-
vapidPublicKey: 'a',
|
|
472
|
-
vapidPrivateKey: 'b',
|
|
473
|
-
OrganizationId: organization.id,
|
|
474
|
-
});
|
|
475
|
-
const group = await Group.create({
|
|
476
|
-
AppId: app.id,
|
|
477
|
-
name: 'test',
|
|
478
|
-
});
|
|
479
|
-
await AppMember.create({
|
|
480
|
-
email: user.primaryEmail,
|
|
481
|
-
AppId: app.id,
|
|
482
|
-
UserId: user.id,
|
|
483
|
-
role: 'Updater',
|
|
484
|
-
name: user.name,
|
|
485
|
-
});
|
|
486
|
-
await authorizeCLI('groups:write', testApp);
|
|
487
|
-
await expect(() => updateMember({
|
|
488
|
-
appId: app.id,
|
|
489
|
-
remote: testApp.defaults.baseURL,
|
|
490
|
-
user: user.id,
|
|
491
|
-
role: 'Updater',
|
|
492
|
-
id: group.id,
|
|
493
|
-
})).rejects.toThrow('Request failed with status code 404');
|
|
494
|
-
});
|
|
495
|
-
});
|
|
496
|
-
describe('deleteMember', () => {
|
|
497
|
-
it('should delete a group member', async () => {
|
|
498
|
-
const app = await App.create({
|
|
499
|
-
definition: {
|
|
500
|
-
name: 'Test App',
|
|
501
|
-
defaultPage: 'Test Page',
|
|
502
|
-
security: {
|
|
503
|
-
groups: {
|
|
504
|
-
join: 'anyone',
|
|
505
|
-
invite: [],
|
|
506
|
-
},
|
|
507
|
-
default: {
|
|
508
|
-
role: 'Reader',
|
|
509
|
-
policy: 'everyone',
|
|
510
|
-
},
|
|
511
|
-
roles: {
|
|
512
|
-
Reader: {},
|
|
513
|
-
Updater: {
|
|
514
|
-
inherits: ['Maintainer'],
|
|
515
|
-
},
|
|
516
|
-
},
|
|
517
|
-
},
|
|
518
|
-
},
|
|
519
|
-
path: 'test-app',
|
|
520
|
-
vapidPublicKey: 'a',
|
|
521
|
-
vapidPrivateKey: 'b',
|
|
522
|
-
OrganizationId: organization.id,
|
|
523
|
-
});
|
|
524
|
-
const group = await Group.create({
|
|
525
|
-
AppId: app.id,
|
|
526
|
-
name: 'test',
|
|
527
|
-
});
|
|
528
|
-
const member = await AppMember.create({
|
|
529
|
-
email: user.primaryEmail,
|
|
530
|
-
AppId: app.id,
|
|
531
|
-
UserId: user.id,
|
|
532
|
-
role: 'Updater',
|
|
533
|
-
name: user.name,
|
|
534
|
-
});
|
|
535
|
-
await authorizeCLI('groups:write', testApp);
|
|
536
|
-
await createTestUser('test2@example.com');
|
|
537
|
-
const member2 = await createTestAppMember(app.id, 'test2@example.com');
|
|
538
|
-
await GroupMember.create({
|
|
539
|
-
GroupId: group.id,
|
|
540
|
-
AppMemberId: member.id,
|
|
541
|
-
role: 'Updater',
|
|
542
|
-
});
|
|
543
|
-
const { id: groupMemberId } = await GroupMember.create({
|
|
544
|
-
GroupId: group.id,
|
|
545
|
-
AppMemberId: member2.id,
|
|
546
|
-
role: 'Reader',
|
|
547
|
-
});
|
|
548
|
-
await deleteMember({
|
|
549
|
-
id: group.id,
|
|
550
|
-
appId: app.id,
|
|
551
|
-
user: groupMemberId,
|
|
552
|
-
remote: testApp.defaults.baseURL,
|
|
553
|
-
});
|
|
554
|
-
const foundGroupMember = await GroupMember.findByPk(groupMemberId);
|
|
555
|
-
expect(foundGroupMember).toBeNull();
|
|
556
|
-
});
|
|
557
|
-
it('should throw an error if the GroupMember does not exist', async () => {
|
|
558
|
-
const app = await App.create({
|
|
559
|
-
definition: {
|
|
560
|
-
name: 'Test App',
|
|
561
|
-
defaultPage: 'Test Page',
|
|
562
|
-
security: {
|
|
563
|
-
groups: {
|
|
564
|
-
join: 'anyone',
|
|
565
|
-
invite: [],
|
|
566
|
-
},
|
|
567
|
-
default: {
|
|
568
|
-
role: 'Reader',
|
|
569
|
-
policy: 'everyone',
|
|
570
|
-
},
|
|
571
|
-
roles: {
|
|
572
|
-
Reader: {},
|
|
573
|
-
},
|
|
574
|
-
},
|
|
575
|
-
},
|
|
576
|
-
path: 'test-app',
|
|
577
|
-
vapidPublicKey: 'a',
|
|
578
|
-
vapidPrivateKey: 'b',
|
|
579
|
-
OrganizationId: organization.id,
|
|
580
|
-
});
|
|
581
|
-
const group = await Group.create({
|
|
582
|
-
AppId: app.id,
|
|
583
|
-
name: 'test',
|
|
584
|
-
});
|
|
585
|
-
await AppMember.create({
|
|
586
|
-
email: user.primaryEmail,
|
|
587
|
-
AppId: app.id,
|
|
588
|
-
UserId: user.id,
|
|
589
|
-
role: 'Manager',
|
|
590
|
-
name: user.name,
|
|
591
|
-
});
|
|
592
|
-
await authorizeCLI('groups:write', testApp);
|
|
593
|
-
await expect(() => deleteMember({
|
|
594
|
-
appId: app.id,
|
|
595
|
-
remote: testApp.defaults.baseURL,
|
|
596
|
-
user: user.id,
|
|
597
|
-
id: group.id,
|
|
598
|
-
})).rejects.toThrow('Request failed with status code 404');
|
|
599
|
-
});
|
|
600
|
-
});
|
|
601
|
-
describe('resolveAnnotations', () => {
|
|
602
|
-
it('should resolve group annotations', () => {
|
|
603
|
-
const unresolvedAnnotations = ['foo=bar', 'hello=world'];
|
|
604
|
-
const annotations = resolveAnnotations(unresolvedAnnotations);
|
|
605
|
-
expect(annotations).toMatchObject({
|
|
606
|
-
foo: 'bar',
|
|
607
|
-
hello: 'world',
|
|
608
|
-
});
|
|
609
|
-
});
|
|
610
|
-
it('should throw an error if annotations are not in right format', () => {
|
|
611
|
-
const unresolvedAnnotations = ['foo:bar', 'hello.world'];
|
|
612
|
-
expect(() => resolveAnnotations(unresolvedAnnotations)).toThrow('One of the annotations did not follow the pattern of key=value');
|
|
613
|
-
});
|
|
614
|
-
});
|
|
615
|
-
});
|
|
616
|
-
//# sourceMappingURL=group.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|