@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.
@@ -1,5 +1,5 @@
1
1
  import { createFixtureStream, readFixture } from '@appsemble/node-utils';
2
- import { createServer, createTestUser, models, setArgv, useTestDatabase } from '@appsemble/server';
2
+ import { createServer, createTestUser, models, setArgv } from '@appsemble/server';
3
3
  import { PredefinedOrganizationRole } from '@appsemble/types';
4
4
  import { setTestApp } from 'axios-test-instance';
5
5
  import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -10,85 +10,85 @@ const argv = { host: 'http://localhost', secret: 'test', aesSecret: 'testSecret'
10
10
  let user;
11
11
  let testApp;
12
12
  const { Organization, OrganizationMember } = models;
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
- });
26
- afterAll(() => {
27
- vi.useRealTimers();
28
- });
29
- describe('createOrganization', () => {
30
- it('should create a new organization', async () => {
31
- await authorizeCLI('organizations:write', testApp);
32
- await createOrganization({
33
- description: 'test description',
34
- id: 'test',
35
- name: 'Test',
36
- email: 'test@example.com',
37
- icon: createFixtureStream('apps/tux.png'),
38
- website: 'https://example.com',
39
- });
40
- const organization = await Organization.findOne();
41
- expect(organization).toMatchObject({
42
- description: 'test description',
43
- email: 'test@example.com',
44
- icon: await readFixture('apps/tux.png'),
45
- id: 'test',
46
- name: 'Test',
47
- website: 'https://example.com',
48
- });
13
+ describe('organization', () => {
14
+ beforeAll(() => {
15
+ vi.useFakeTimers();
16
+ setArgv(argv);
49
17
  });
50
- it('should not create a new organization with duplicate id', async () => {
51
- const organization = await Organization.create({
52
- id: 'test',
53
- name: 'Test',
54
- });
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
+ });
26
+ afterAll(() => {
55
27
  vi.useRealTimers();
56
- await authorizeCLI('organizations:write', testApp);
57
- await expect(() => createOrganization({
58
- description: 'test description',
59
- id: organization.id,
60
- name: 'Test',
61
- email: 'test@example.com',
62
- icon: null,
63
- website: 'https://example.com',
64
- })).rejects.toThrow('Request failed with status code 409');
65
- vi.useFakeTimers();
66
28
  });
67
- });
68
- describe('updateOrganization', () => {
69
- it('should update an existing organization', async () => {
70
- const organization = await Organization.create({
71
- id: 'test',
72
- name: 'Test',
73
- });
74
- await OrganizationMember.create({
75
- OrganizationId: organization.id,
76
- UserId: user.id,
77
- role: PredefinedOrganizationRole.Owner,
29
+ describe('createOrganization', () => {
30
+ it('should create a new organization', async () => {
31
+ await authorizeCLI('organizations:write', testApp);
32
+ await createOrganization({
33
+ description: 'test description',
34
+ id: 'test',
35
+ name: 'Test',
36
+ email: 'test@example.com',
37
+ icon: createFixtureStream('apps/tux.png'),
38
+ website: 'https://example.com',
39
+ });
40
+ const organization = await Organization.findOne();
41
+ expect(organization).toMatchObject({
42
+ description: 'test description',
43
+ email: 'test@example.com',
44
+ icon: await readFixture('apps/tux.png'),
45
+ id: 'test',
46
+ name: 'Test',
47
+ website: 'https://example.com',
48
+ });
49
+ });
50
+ it('should not create a new organization with duplicate id', async () => {
51
+ const organization = await Organization.create({
52
+ id: 'test',
53
+ name: 'Test',
54
+ });
55
+ vi.useRealTimers();
56
+ await authorizeCLI('organizations:write', testApp);
57
+ await expect(() => createOrganization({
58
+ description: 'test description',
59
+ id: organization.id,
60
+ name: 'Test',
61
+ email: 'test@example.com',
62
+ icon: null,
63
+ website: 'https://example.com',
64
+ })).rejects.toThrow('Request failed with status code 409');
65
+ vi.useFakeTimers();
78
66
  });
79
- await authorizeCLI('organizations:write', testApp);
80
- await updateOrganization({
81
- id: organization.id,
82
- name: 'Test changed',
83
- description: 'Description Changed',
84
- email: 'test@example.com',
85
- website: null,
86
- icon: createFixtureStream('apps/tux.png'),
87
- });
88
- await organization.reload();
89
- expect(organization.dataValues).toMatchInlineSnapshot({
90
- icon: expect.any(Buffer),
91
- }, `
67
+ });
68
+ describe('updateOrganization', () => {
69
+ it('should update an existing organization', async () => {
70
+ const organization = await Organization.create({
71
+ id: 'test',
72
+ name: 'Test',
73
+ });
74
+ await OrganizationMember.create({
75
+ OrganizationId: organization.id,
76
+ UserId: user.id,
77
+ role: PredefinedOrganizationRole.Owner,
78
+ });
79
+ await authorizeCLI('organizations:write', testApp);
80
+ await updateOrganization({
81
+ id: organization.id,
82
+ name: 'Test changed',
83
+ description: 'Description Changed',
84
+ email: 'test@example.com',
85
+ website: null,
86
+ icon: createFixtureStream('apps/tux.png'),
87
+ });
88
+ await organization.reload();
89
+ expect(organization.dataValues).toMatchInlineSnapshot({
90
+ icon: expect.any(Buffer),
91
+ }, `
92
92
  {
93
93
  "created": 1970-01-01T00:00:00.000Z,
94
94
  "deleted": null,
@@ -101,120 +101,121 @@ describe('updateOrganization', () => {
101
101
  "website": null,
102
102
  }
103
103
  `);
104
- });
105
- it('should throw if the organization does not exist', async () => {
106
- const organization = await Organization.create({
107
- id: 'test',
108
- name: 'Test',
109
104
  });
110
- await OrganizationMember.create({
111
- OrganizationId: organization.id,
112
- UserId: user.id,
113
- role: PredefinedOrganizationRole.Owner,
105
+ it('should throw if the organization does not exist', async () => {
106
+ const organization = await Organization.create({
107
+ id: 'test',
108
+ name: 'Test',
109
+ });
110
+ await OrganizationMember.create({
111
+ OrganizationId: organization.id,
112
+ UserId: user.id,
113
+ role: PredefinedOrganizationRole.Owner,
114
+ });
115
+ await organization.destroy();
116
+ await authorizeCLI('organizations:write', testApp);
117
+ await expect(() => updateOrganization({
118
+ id: organization.id,
119
+ name: 'Test changed',
120
+ description: null,
121
+ email: 'test@example.com',
122
+ website: null,
123
+ icon: null,
124
+ })).rejects.toThrow('Request failed with status code 404');
125
+ });
126
+ it('should throw if the user is not authorized', async () => {
127
+ const organization = await Organization.create({
128
+ id: 'test',
129
+ name: 'Test',
130
+ });
131
+ await OrganizationMember.create({
132
+ OrganizationId: organization.id,
133
+ UserId: user.id,
134
+ role: PredefinedOrganizationRole.Owner,
135
+ });
136
+ await expect(() => updateOrganization({
137
+ id: organization.id,
138
+ name: 'Test changed',
139
+ description: null,
140
+ email: 'test@example.com',
141
+ website: null,
142
+ icon: null,
143
+ })).rejects.toThrow('Request failed with status code 401');
114
144
  });
115
- await organization.destroy();
116
- await authorizeCLI('organizations:write', testApp);
117
- await expect(() => updateOrganization({
118
- id: organization.id,
119
- name: 'Test changed',
120
- description: null,
121
- email: 'test@example.com',
122
- website: null,
123
- icon: null,
124
- })).rejects.toThrow('Request failed with status code 404');
125
145
  });
126
- it('should throw if the user is not authorized', async () => {
127
- const organization = await Organization.create({
128
- id: 'test',
129
- name: 'Test',
130
- });
131
- await OrganizationMember.create({
132
- OrganizationId: organization.id,
133
- UserId: user.id,
134
- role: PredefinedOrganizationRole.Owner,
135
- });
136
- await expect(() => updateOrganization({
137
- id: organization.id,
138
- name: 'Test changed',
139
- description: null,
140
- email: 'test@example.com',
141
- website: null,
142
- icon: null,
143
- })).rejects.toThrow('Request failed with status code 401');
144
- });
145
- });
146
- describe('upsertOrganization', () => {
147
- it('should create a new organization if doesn’t exist already', async () => {
148
- await authorizeCLI('organizations:write', testApp);
149
- await upsertOrganization({
150
- description: 'test description',
151
- id: 'test',
152
- name: 'Test',
153
- email: 'test@example.com',
154
- icon: null,
155
- website: 'https://example.com',
156
- });
157
- const organization = await Organization.findOne();
158
- expect(organization).toMatchObject({
159
- id: 'test',
160
- description: 'test description',
161
- name: 'Test',
162
- email: 'test@example.com',
163
- icon: null,
164
- website: 'https://example.com',
165
- });
166
- });
167
- it('should update an existing organization', async () => {
168
- const organization = await Organization.create({
169
- id: 'test',
170
- name: 'Test',
171
- });
172
- await OrganizationMember.create({
173
- OrganizationId: organization.id,
174
- UserId: user.id,
175
- role: PredefinedOrganizationRole.Owner,
176
- });
177
- await authorizeCLI('organizations:write', testApp);
178
- await upsertOrganization({
179
- id: organization.id,
180
- name: 'Test changed',
181
- description: null,
182
- email: 'test@example.com',
183
- website: null,
184
- icon: null,
185
- });
186
- expect(organization).toMatchObject({
187
- id: 'test',
188
- name: 'Test',
189
- });
190
- await organization.reload();
191
- expect(organization).toMatchObject({
192
- id: organization.id,
193
- name: 'Test changed',
194
- description: null,
195
- email: 'test@example.com',
196
- website: null,
197
- icon: null,
198
- });
199
- });
200
- it('should throw if there is an error', async () => {
201
- const organization = await Organization.create({
202
- id: 'test',
203
- name: 'Test',
204
- });
205
- await authorizeCLI('organizations:write', testApp);
206
- // Fails because the organization member does not exist.
207
- await expect(() => upsertOrganization({
208
- id: organization.id,
209
- name: 'Test changed',
210
- description: null,
211
- email: 'test@example.com',
212
- website: 'https://www.example.com',
213
- icon: null,
214
- })).rejects.toThrow('Request failed with status code 403');
215
- expect(organization).toMatchObject({
216
- id: 'test',
217
- name: 'Test',
146
+ describe('upsertOrganization', () => {
147
+ it('should create a new organization if doesn’t exist already', async () => {
148
+ await authorizeCLI('organizations:write', testApp);
149
+ await upsertOrganization({
150
+ description: 'test description',
151
+ id: 'test',
152
+ name: 'Test',
153
+ email: 'test@example.com',
154
+ icon: null,
155
+ website: 'https://example.com',
156
+ });
157
+ const organization = await Organization.findOne();
158
+ expect(organization).toMatchObject({
159
+ id: 'test',
160
+ description: 'test description',
161
+ name: 'Test',
162
+ email: 'test@example.com',
163
+ icon: null,
164
+ website: 'https://example.com',
165
+ });
166
+ });
167
+ it('should update an existing organization', async () => {
168
+ const organization = await Organization.create({
169
+ id: 'test',
170
+ name: 'Test',
171
+ });
172
+ await OrganizationMember.create({
173
+ OrganizationId: organization.id,
174
+ UserId: user.id,
175
+ role: PredefinedOrganizationRole.Owner,
176
+ });
177
+ await authorizeCLI('organizations:write', testApp);
178
+ await upsertOrganization({
179
+ id: organization.id,
180
+ name: 'Test changed',
181
+ description: null,
182
+ email: 'test@example.com',
183
+ website: null,
184
+ icon: null,
185
+ });
186
+ expect(organization).toMatchObject({
187
+ id: 'test',
188
+ name: 'Test',
189
+ });
190
+ await organization.reload();
191
+ expect(organization).toMatchObject({
192
+ id: organization.id,
193
+ name: 'Test changed',
194
+ description: null,
195
+ email: 'test@example.com',
196
+ website: null,
197
+ icon: null,
198
+ });
199
+ });
200
+ it('should throw if there is an error', async () => {
201
+ const organization = await Organization.create({
202
+ id: 'test',
203
+ name: 'Test',
204
+ });
205
+ await authorizeCLI('organizations:write', testApp);
206
+ // Fails because the organization member does not exist.
207
+ await expect(() => upsertOrganization({
208
+ id: organization.id,
209
+ name: 'Test changed',
210
+ description: null,
211
+ email: 'test@example.com',
212
+ website: 'https://www.example.com',
213
+ icon: null,
214
+ })).rejects.toThrow('Request failed with status code 403');
215
+ expect(organization).toMatchObject({
216
+ id: 'test',
217
+ name: 'Test',
218
+ });
218
219
  });
219
220
  });
220
221
  });