@appsemble/cli 0.30.1 → 0.30.3

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/lib/group.test.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createServer, createTestAppMember, createTestUser, models, setArgv, useTestDatabase, } from '@appsemble/server';
1
+ import { createServer, createTestAppMember, createTestUser, models, setArgv, } from '@appsemble/server';
2
2
  import { PredefinedOrganizationRole } from '@appsemble/types';
3
3
  import { setTestApp } from 'axios-test-instance';
4
4
  import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -10,348 +10,348 @@ const argv = { host: 'http://localhost', secret: 'test', aesSecret: 'testSecret'
10
10
  let user;
11
11
  let organization;
12
12
  let testApp;
13
- useTestDatabase(import.meta);
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
- },
13
+ describe('group', () => {
14
+ beforeAll(() => {
15
+ vi.useFakeTimers();
16
+ setArgv(argv);
47
17
  });
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',
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({
75
30
  OrganizationId: organization.id,
31
+ UserId: user.id,
32
+ role: PredefinedOrganizationRole.Owner,
76
33
  });
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,
34
+ await Organization.create({ id: 'appsemble', name: 'Appsemble' });
35
+ await BlockVersion.create({
101
36
  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: {},
37
+ OrganizationId: 'appsemble',
38
+ version: '0.0.0',
39
+ parameters: {
40
+ type: 'object',
41
+ properties: {
42
+ foo: {
43
+ type: 'number',
124
44
  },
125
45
  },
126
46
  },
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
47
  });
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
48
  });
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');
49
+ afterAll(() => {
50
+ vi.useRealTimers();
183
51
  });
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: {},
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
+ },
202
70
  },
203
71
  },
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',
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');
213
105
  });
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
106
  });
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: [],
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
+ },
243
125
  },
244
- default: {
245
- role: 'Reader',
246
- policy: 'everyone',
247
- },
248
- roles: {
249
- Reader: {},
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
+ },
250
174
  },
251
175
  },
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',
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');
261
183
  });
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
184
  });
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: [],
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
+ },
281
203
  },
282
- default: {
283
- role: 'Reader',
284
- policy: 'everyone',
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
+ },
285
251
  },
286
- roles: {
287
- Reader: {},
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
+ },
288
289
  },
289
290
  },
290
- },
291
- path: 'test-app',
292
- vapidPublicKey: 'a',
293
- vapidPrivateKey: 'b',
294
- OrganizationId: organization.id,
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');
295
306
  });
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
  });
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
- groups: {
316
- join: 'anyone',
317
- invite: [],
318
- },
319
- default: {
320
- role: 'Reader',
321
- policy: 'everyone',
322
- },
323
- roles: {
324
- Reader: {},
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
+ groups: {
316
+ join: 'anyone',
317
+ invite: [],
318
+ },
319
+ default: {
320
+ role: 'Reader',
321
+ policy: 'everyone',
322
+ },
323
+ roles: {
324
+ Reader: {},
325
+ },
325
326
  },
326
327
  },
327
- },
328
- path: 'test-app',
329
- vapidPublicKey: 'a',
330
- vapidPrivateKey: 'b',
331
- OrganizationId: organization.id,
332
- });
333
- const group = await Group.create({
334
- AppId: app.id,
335
- name: 'test',
336
- });
337
- await AppMember.create({
338
- email: user.primaryEmail,
339
- AppId: app.id,
340
- UserId: user.id,
341
- role: 'Manager',
342
- name: user.name,
343
- });
344
- await authorizeCLI('groups:write', testApp);
345
- await inviteMember({
346
- appId: app.id,
347
- id: group.id,
348
- remote: testApp.defaults.baseURL,
349
- user: user.primaryEmail,
350
- });
351
- const invite = await GroupInvite.findOne();
352
- expect(invite.dataValues).toMatchInlineSnapshot({
353
- key: expect.any(String),
354
- }, `
328
+ path: 'test-app',
329
+ vapidPublicKey: 'a',
330
+ vapidPrivateKey: 'b',
331
+ OrganizationId: organization.id,
332
+ });
333
+ const group = await Group.create({
334
+ AppId: app.id,
335
+ name: 'test',
336
+ });
337
+ await AppMember.create({
338
+ email: user.primaryEmail,
339
+ AppId: app.id,
340
+ UserId: user.id,
341
+ role: 'Manager',
342
+ name: user.name,
343
+ });
344
+ await authorizeCLI('groups:write', testApp);
345
+ await inviteMember({
346
+ appId: app.id,
347
+ id: group.id,
348
+ remote: testApp.defaults.baseURL,
349
+ user: user.primaryEmail,
350
+ });
351
+ const invite = await GroupInvite.findOne();
352
+ expect(invite.dataValues).toMatchInlineSnapshot({
353
+ key: expect.any(String),
354
+ }, `
355
355
  {
356
356
  "GroupId": 1,
357
357
  "created": 1970-01-01T00:00:00.000Z,
@@ -361,249 +361,250 @@ describe('inviteMember', () => {
361
361
  "updated": 1970-01-01T00:00:00.000Z,
362
362
  }
363
363
  `);
364
- });
365
- it('should throw an error if the group does not exist', async () => {
366
- const app = await App.create({
367
- definition: {
368
- name: 'Test App',
369
- defaultPage: 'Test Page',
370
- security: {
371
- groups: {
372
- join: 'anyone',
373
- invite: [],
374
- },
375
- default: {
376
- role: 'Reader',
377
- policy: 'everyone',
378
- },
379
- roles: {
380
- Reader: {},
381
- },
382
- },
383
- },
384
- path: 'test-app',
385
- vapidPublicKey: 'a',
386
- vapidPrivateKey: 'b',
387
- OrganizationId: organization.id,
388
364
  });
389
- await authorizeCLI('groups:write', testApp);
390
- await expect(() => inviteMember({
391
- appId: app.id,
392
- id: 10,
393
- remote: testApp.defaults.baseURL,
394
- user: user.primaryEmail,
395
- })).rejects.toThrow('Request failed with status code 400');
396
- });
397
- });
398
- describe('updateMember', () => {
399
- it('should update role of a group member', async () => {
400
- const app = await App.create({
401
- definition: {
402
- name: 'Test App',
403
- defaultPage: 'Test Page',
404
- security: {
405
- groups: {
406
- join: 'anyone',
407
- invite: [],
408
- },
409
- default: {
410
- role: 'Reader',
411
- policy: 'everyone',
412
- },
413
- roles: {
414
- Reader: {},
365
+ it('should throw an error if the group does not exist', async () => {
366
+ const app = await App.create({
367
+ definition: {
368
+ name: 'Test App',
369
+ defaultPage: 'Test Page',
370
+ security: {
371
+ groups: {
372
+ join: 'anyone',
373
+ invite: [],
374
+ },
375
+ default: {
376
+ role: 'Reader',
377
+ policy: 'everyone',
378
+ },
379
+ roles: {
380
+ Reader: {},
381
+ },
415
382
  },
416
383
  },
417
- },
418
- path: 'test-app',
419
- vapidPublicKey: 'a',
420
- vapidPrivateKey: 'b',
421
- OrganizationId: organization.id,
422
- });
423
- const group = await Group.create({
424
- AppId: app.id,
425
- name: 'test',
426
- });
427
- const member = await AppMember.create({
428
- email: user.primaryEmail,
429
- AppId: app.id,
430
- UserId: user.id,
431
- role: 'Manager',
432
- name: user.name,
433
- });
434
- const groupMember = await GroupMember.create({
435
- GroupId: group.id,
436
- AppMemberId: member.id,
437
- });
438
- await authorizeCLI('groups:write', testApp);
439
- await updateMember({
440
- appId: app.id,
441
- remote: testApp.defaults.baseURL,
442
- user: groupMember.id,
443
- role: 'GroupMembersManager',
444
- id: group.id,
384
+ path: 'test-app',
385
+ vapidPublicKey: 'a',
386
+ vapidPrivateKey: 'b',
387
+ OrganizationId: organization.id,
388
+ });
389
+ await authorizeCLI('groups:write', testApp);
390
+ await expect(() => inviteMember({
391
+ appId: app.id,
392
+ id: 10,
393
+ remote: testApp.defaults.baseURL,
394
+ user: user.primaryEmail,
395
+ })).rejects.toThrow('Request failed with status code 400');
445
396
  });
446
- expect(groupMember.role).toBe('Member');
447
- await groupMember.reload();
448
- expect(groupMember.role).toBe('GroupMembersManager');
449
397
  });
450
- it('should throw an error if the user is not a GroupMember', async () => {
451
- const app = await App.create({
452
- definition: {
453
- name: 'Test App',
454
- defaultPage: 'Test Page',
455
- security: {
456
- groups: {
457
- join: 'anyone',
458
- invite: [],
459
- },
460
- default: {
461
- role: 'Reader',
462
- policy: 'everyone',
463
- },
464
- roles: {
465
- Reader: {},
398
+ describe('updateMember', () => {
399
+ it('should update role of a group member', async () => {
400
+ const app = await App.create({
401
+ definition: {
402
+ name: 'Test App',
403
+ defaultPage: 'Test Page',
404
+ security: {
405
+ groups: {
406
+ join: 'anyone',
407
+ invite: [],
408
+ },
409
+ default: {
410
+ role: 'Reader',
411
+ policy: 'everyone',
412
+ },
413
+ roles: {
414
+ Reader: {},
415
+ },
466
416
  },
467
417
  },
468
- },
469
- path: 'test-app',
470
- vapidPublicKey: 'a',
471
- vapidPrivateKey: 'b',
472
- OrganizationId: organization.id,
473
- });
474
- const group = await Group.create({
475
- AppId: app.id,
476
- name: 'test',
477
- });
478
- await AppMember.create({
479
- email: user.primaryEmail,
480
- AppId: app.id,
481
- UserId: user.id,
482
- role: 'Manager',
483
- name: user.name,
484
- });
485
- await authorizeCLI('groups:write', testApp);
486
- await expect(() => updateMember({
487
- appId: app.id,
488
- remote: testApp.defaults.baseURL,
489
- user: user.id,
490
- role: 'GroupMembersManager',
491
- id: group.id,
492
- })).rejects.toThrow('Request failed with status code 404');
493
- });
494
- });
495
- describe('deleteMember', () => {
496
- it('should delete a group member', async () => {
497
- const app = await App.create({
498
- definition: {
499
- name: 'Test App',
500
- defaultPage: 'Test Page',
501
- security: {
502
- groups: {
503
- join: 'anyone',
504
- invite: [],
505
- },
506
- default: {
507
- role: 'Reader',
508
- policy: 'everyone',
509
- },
510
- roles: {
511
- Reader: {},
418
+ path: 'test-app',
419
+ vapidPublicKey: 'a',
420
+ vapidPrivateKey: 'b',
421
+ OrganizationId: organization.id,
422
+ });
423
+ const group = await Group.create({
424
+ AppId: app.id,
425
+ name: 'test',
426
+ });
427
+ const member = await AppMember.create({
428
+ email: user.primaryEmail,
429
+ AppId: app.id,
430
+ UserId: user.id,
431
+ role: 'Manager',
432
+ name: user.name,
433
+ });
434
+ const groupMember = await GroupMember.create({
435
+ GroupId: group.id,
436
+ AppMemberId: member.id,
437
+ });
438
+ await authorizeCLI('groups:write', testApp);
439
+ await updateMember({
440
+ appId: app.id,
441
+ remote: testApp.defaults.baseURL,
442
+ user: groupMember.id,
443
+ role: 'GroupMembersManager',
444
+ id: group.id,
445
+ });
446
+ expect(groupMember.role).toBe('Member');
447
+ await groupMember.reload();
448
+ expect(groupMember.role).toBe('GroupMembersManager');
449
+ });
450
+ it('should throw an error if the user is not a GroupMember', async () => {
451
+ const app = await App.create({
452
+ definition: {
453
+ name: 'Test App',
454
+ defaultPage: 'Test Page',
455
+ security: {
456
+ groups: {
457
+ join: 'anyone',
458
+ invite: [],
459
+ },
460
+ default: {
461
+ role: 'Reader',
462
+ policy: 'everyone',
463
+ },
464
+ roles: {
465
+ Reader: {},
466
+ },
512
467
  },
513
468
  },
514
- },
515
- path: 'test-app',
516
- vapidPublicKey: 'a',
517
- vapidPrivateKey: 'b',
518
- OrganizationId: organization.id,
519
- });
520
- const group = await Group.create({
521
- AppId: app.id,
522
- name: 'test',
523
- });
524
- const member = await AppMember.create({
525
- email: user.primaryEmail,
526
- AppId: app.id,
527
- UserId: user.id,
528
- role: 'Maintainer',
529
- name: user.name,
530
- });
531
- await authorizeCLI('groups:write', testApp);
532
- await createTestUser('test2@example.com');
533
- const member2 = await createTestAppMember(app.id, 'test2@example.com');
534
- await GroupMember.create({
535
- GroupId: group.id,
536
- AppMemberId: member.id,
469
+ path: 'test-app',
470
+ vapidPublicKey: 'a',
471
+ vapidPrivateKey: 'b',
472
+ OrganizationId: organization.id,
473
+ });
474
+ const group = await Group.create({
475
+ AppId: app.id,
476
+ name: 'test',
477
+ });
478
+ await AppMember.create({
479
+ email: user.primaryEmail,
480
+ AppId: app.id,
481
+ UserId: user.id,
482
+ role: 'Manager',
483
+ name: user.name,
484
+ });
485
+ await authorizeCLI('groups:write', testApp);
486
+ await expect(() => updateMember({
487
+ appId: app.id,
488
+ remote: testApp.defaults.baseURL,
489
+ user: user.id,
490
+ role: 'GroupMembersManager',
491
+ id: group.id,
492
+ })).rejects.toThrow('Request failed with status code 404');
537
493
  });
538
- const { id: groupMemberId } = await GroupMember.create({
539
- GroupId: group.id,
540
- AppMemberId: member2.id,
541
- });
542
- await deleteMember({
543
- id: group.id,
544
- appId: app.id,
545
- user: groupMemberId,
546
- remote: testApp.defaults.baseURL,
547
- });
548
- const foundGroupMember = await GroupMember.findByPk(groupMemberId);
549
- expect(foundGroupMember).toBeNull();
550
494
  });
551
- it('should throw an error if the GroupMember does not exist', async () => {
552
- const app = await App.create({
553
- definition: {
554
- name: 'Test App',
555
- defaultPage: 'Test Page',
556
- security: {
557
- groups: {
558
- join: 'anyone',
559
- invite: [],
495
+ describe('deleteMember', () => {
496
+ it('should delete a group member', async () => {
497
+ const app = await App.create({
498
+ definition: {
499
+ name: 'Test App',
500
+ defaultPage: 'Test Page',
501
+ security: {
502
+ groups: {
503
+ join: 'anyone',
504
+ invite: [],
505
+ },
506
+ default: {
507
+ role: 'Reader',
508
+ policy: 'everyone',
509
+ },
510
+ roles: {
511
+ Reader: {},
512
+ },
560
513
  },
561
- default: {
562
- role: 'Reader',
563
- policy: 'everyone',
564
- },
565
- roles: {
566
- Reader: {},
514
+ },
515
+ path: 'test-app',
516
+ vapidPublicKey: 'a',
517
+ vapidPrivateKey: 'b',
518
+ OrganizationId: organization.id,
519
+ });
520
+ const group = await Group.create({
521
+ AppId: app.id,
522
+ name: 'test',
523
+ });
524
+ const member = await AppMember.create({
525
+ email: user.primaryEmail,
526
+ AppId: app.id,
527
+ UserId: user.id,
528
+ role: 'Maintainer',
529
+ name: user.name,
530
+ });
531
+ await authorizeCLI('groups:write', testApp);
532
+ await createTestUser('test2@example.com');
533
+ const member2 = await createTestAppMember(app.id, 'test2@example.com');
534
+ await GroupMember.create({
535
+ GroupId: group.id,
536
+ AppMemberId: member.id,
537
+ });
538
+ const { id: groupMemberId } = await GroupMember.create({
539
+ GroupId: group.id,
540
+ AppMemberId: member2.id,
541
+ });
542
+ await deleteMember({
543
+ id: group.id,
544
+ appId: app.id,
545
+ user: groupMemberId,
546
+ remote: testApp.defaults.baseURL,
547
+ });
548
+ const foundGroupMember = await GroupMember.findByPk(groupMemberId);
549
+ expect(foundGroupMember).toBeNull();
550
+ });
551
+ it('should throw an error if the GroupMember does not exist', async () => {
552
+ const app = await App.create({
553
+ definition: {
554
+ name: 'Test App',
555
+ defaultPage: 'Test Page',
556
+ security: {
557
+ groups: {
558
+ join: 'anyone',
559
+ invite: [],
560
+ },
561
+ default: {
562
+ role: 'Reader',
563
+ policy: 'everyone',
564
+ },
565
+ roles: {
566
+ Reader: {},
567
+ },
567
568
  },
568
569
  },
569
- },
570
- path: 'test-app',
571
- vapidPublicKey: 'a',
572
- vapidPrivateKey: 'b',
573
- OrganizationId: organization.id,
574
- });
575
- const group = await Group.create({
576
- AppId: app.id,
577
- name: 'test',
570
+ path: 'test-app',
571
+ vapidPublicKey: 'a',
572
+ vapidPrivateKey: 'b',
573
+ OrganizationId: organization.id,
574
+ });
575
+ const group = await Group.create({
576
+ AppId: app.id,
577
+ name: 'test',
578
+ });
579
+ await AppMember.create({
580
+ email: user.primaryEmail,
581
+ AppId: app.id,
582
+ UserId: user.id,
583
+ role: 'Manager',
584
+ name: user.name,
585
+ });
586
+ await authorizeCLI('groups:write', testApp);
587
+ await expect(() => deleteMember({
588
+ appId: app.id,
589
+ remote: testApp.defaults.baseURL,
590
+ user: user.id,
591
+ id: group.id,
592
+ })).rejects.toThrow('Request failed with status code 404');
578
593
  });
579
- await AppMember.create({
580
- email: user.primaryEmail,
581
- AppId: app.id,
582
- UserId: user.id,
583
- role: 'Manager',
584
- name: user.name,
585
- });
586
- await authorizeCLI('groups:write', testApp);
587
- await expect(() => deleteMember({
588
- appId: app.id,
589
- remote: testApp.defaults.baseURL,
590
- user: user.id,
591
- id: group.id,
592
- })).rejects.toThrow('Request failed with status code 404');
593
594
  });
594
- });
595
- describe('resolveAnnotations', () => {
596
- it('should resolve group annotations', () => {
597
- const unresolvedAnnotations = ['foo=bar', 'hello=world'];
598
- const annotations = resolveAnnotations(unresolvedAnnotations);
599
- expect(annotations).toMatchObject({
600
- foo: 'bar',
601
- hello: 'world',
595
+ describe('resolveAnnotations', () => {
596
+ it('should resolve group annotations', () => {
597
+ const unresolvedAnnotations = ['foo=bar', 'hello=world'];
598
+ const annotations = resolveAnnotations(unresolvedAnnotations);
599
+ expect(annotations).toMatchObject({
600
+ foo: 'bar',
601
+ hello: 'world',
602
+ });
603
+ });
604
+ it('should throw an error if annotations are not in right format', () => {
605
+ const unresolvedAnnotations = ['foo:bar', 'hello.world'];
606
+ expect(() => resolveAnnotations(unresolvedAnnotations)).toThrow('One of the annotations did not follow the pattern of key=value');
602
607
  });
603
608
  });
604
- it('should throw an error if annotations are not in right format', () => {
605
- const unresolvedAnnotations = ['foo:bar', 'hello.world'];
606
- expect(() => resolveAnnotations(unresolvedAnnotations)).toThrow('One of the annotations did not follow the pattern of key=value');
607
- });
608
609
  });
609
610
  //# sourceMappingURL=group.test.js.map