@appsemble/cli 0.29.11 → 0.30.2
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 +10 -10
- package/commands/app/create.d.ts +1 -1
- package/commands/app/create.js +5 -5
- package/commands/{team → group}/create.d.ts +3 -3
- package/commands/{team → group}/create.js +5 -5
- package/commands/{team → group}/delete.d.ts +3 -3
- package/commands/{team → group}/delete.js +5 -5
- package/commands/{team → group}/index.d.ts +2 -2
- package/commands/{team → group}/index.js +4 -4
- package/commands/{team → group}/member/delete.d.ts +3 -3
- package/commands/{team → group}/member/delete.js +5 -5
- package/commands/{team → group}/member/index.d.ts +1 -1
- package/commands/{team → group}/member/index.js +1 -3
- package/commands/{team → group}/member/invite.d.ts +3 -3
- package/commands/{team → group}/member/invite.js +5 -5
- package/commands/{team → group}/update.d.ts +3 -3
- package/commands/{team → group}/update.js +7 -7
- package/commands/migrateAppDefinitions.d.ts +13 -0
- package/commands/migrateAppDefinitions.js +73 -0
- package/commands/serve.d.ts +1 -1
- package/commands/serve.js +16 -16
- package/index.js +4 -2
- package/lib/app.js +13 -3
- package/lib/app.test.js +1266 -1262
- package/lib/asset.js +4 -2
- package/lib/asset.test.js +70 -67
- package/lib/block.test.js +144 -142
- package/lib/config.test.js +205 -203
- package/lib/createServers.js +3 -1
- package/lib/group.d.ts +61 -0
- package/lib/group.js +55 -0
- package/lib/group.test.js +610 -0
- package/lib/organization.test.js +189 -187
- package/lib/resource.js +3 -1
- package/lib/resource.test.js +322 -320
- package/lib/serverImport.d.ts +1 -1
- package/package.json +8 -7
- package/server/argv.d.ts +4 -4
- package/server/argv.js +1 -1
- package/server/controllers/apps/actions/index.d.ts +5 -0
- package/server/controllers/apps/actions/index.js +6 -0
- package/server/controllers/apps/actions/proxyDelete.d.ts +2 -0
- package/server/controllers/apps/actions/proxyDelete.js +4 -0
- package/server/controllers/apps/actions/proxyGet.d.ts +2 -0
- package/server/controllers/apps/actions/proxyGet.js +4 -0
- package/server/controllers/apps/actions/proxyPatch.d.ts +2 -0
- package/server/controllers/apps/actions/proxyPatch.js +4 -0
- package/server/controllers/apps/actions/proxyPost.d.ts +2 -0
- package/server/controllers/apps/actions/proxyPost.js +4 -0
- package/server/controllers/apps/actions/proxyPut.d.ts +2 -0
- package/server/controllers/apps/actions/proxyPut.js +4 -0
- package/server/controllers/apps/index.d.ts +2 -0
- package/server/controllers/apps/index.js +3 -0
- package/server/controllers/apps/members/current/getCurrentAppMember.d.ts +2 -0
- package/server/controllers/apps/members/current/getCurrentAppMember.js +4 -0
- package/server/controllers/apps/members/current/index.d.ts +1 -0
- package/server/controllers/apps/members/current/index.js +2 -0
- package/server/controllers/apps/members/index.d.ts +1 -0
- package/server/controllers/apps/members/index.js +2 -0
- package/server/controllers/common/apps/assets/getAppAssetById.d.ts +2 -0
- package/server/controllers/common/apps/assets/getAppAssetById.js +4 -0
- package/server/controllers/common/apps/assets/index.d.ts +1 -0
- package/server/controllers/common/apps/assets/index.js +2 -0
- package/server/controllers/common/apps/groups/getAppGroups.d.ts +2 -0
- package/server/controllers/common/apps/groups/getAppGroups.js +4 -0
- package/server/controllers/common/apps/groups/index.d.ts +1 -0
- package/server/controllers/common/apps/groups/index.js +2 -0
- package/server/controllers/common/apps/index.d.ts +5 -0
- package/server/controllers/common/apps/index.js +6 -0
- package/server/controllers/common/apps/messages/getAppMessages.d.ts +2 -0
- package/server/controllers/common/apps/messages/getAppMessages.js +4 -0
- package/server/controllers/common/apps/messages/index.d.ts +1 -0
- package/server/controllers/common/apps/messages/index.js +2 -0
- package/server/controllers/common/apps/resources/countAppResources.d.ts +2 -0
- package/server/controllers/common/apps/resources/countAppResources.js +4 -0
- package/server/controllers/common/apps/resources/createAppResource.d.ts +2 -0
- package/server/controllers/common/apps/resources/createAppResource.js +4 -0
- package/server/controllers/common/apps/resources/deleteAppResource.d.ts +2 -0
- package/server/controllers/common/apps/resources/deleteAppResource.js +4 -0
- package/server/controllers/common/apps/resources/getAppResourceById.d.ts +2 -0
- package/server/controllers/common/apps/resources/getAppResourceById.js +4 -0
- package/server/controllers/common/apps/resources/index.d.ts +6 -0
- package/server/controllers/common/apps/resources/index.js +7 -0
- package/server/controllers/common/apps/resources/queryAppResources.d.ts +2 -0
- package/server/controllers/common/apps/resources/queryAppResources.js +4 -0
- package/server/controllers/common/apps/resources/updateAppResource.d.ts +2 -0
- package/server/controllers/common/apps/resources/updateAppResource.js +4 -0
- package/server/controllers/common/apps/variables/getAppVariables.js +4 -0
- package/server/controllers/common/apps/variables/index.d.ts +1 -0
- package/server/controllers/common/apps/variables/index.js +2 -0
- package/server/controllers/common/index.d.ts +1 -0
- package/server/controllers/common/index.js +2 -0
- package/server/controllers/index.d.ts +3 -8
- package/server/controllers/index.js +3 -8
- package/server/controllers/main/apps/assets/createAppAsset.d.ts +2 -0
- package/server/controllers/main/apps/assets/createAppAsset.js +4 -0
- package/server/controllers/main/apps/assets/index.d.ts +1 -0
- package/server/controllers/main/apps/assets/index.js +2 -0
- package/server/controllers/main/apps/index.d.ts +1 -0
- package/server/controllers/main/apps/index.js +2 -0
- package/server/controllers/main/index.d.ts +1 -0
- package/server/controllers/main/index.js +2 -0
- package/server/options/checkAppMemberAppPermissions.d.ts +1 -0
- package/server/options/checkAppMemberAppPermissions.js +4 -0
- package/server/options/checkAppPermissions.d.ts +1 -0
- package/server/options/checkAppPermissions.js +4 -0
- package/server/options/checkAuthSubjectAppPermissions.d.ts +1 -0
- package/server/options/checkAuthSubjectAppPermissions.js +4 -0
- package/server/options/checkUserOrganizationPermissions.d.ts +1 -0
- package/server/options/checkUserOrganizationPermissions.js +4 -0
- package/server/options/getAppGroups.d.ts +2 -0
- package/server/options/getAppGroups.js +4 -0
- package/server/options/getCurrentAppMember.d.ts +3 -0
- package/server/options/getCurrentAppMember.js +4 -0
- package/server/options/index.d.ts +6 -5
- package/server/options/index.js +6 -5
- package/server/options/options.js +7 -6
- package/templates/apps/empty/app-definition.yaml +2 -2
- package/templates/blocks/mini-jsx/package.json +1 -1
- package/templates/blocks/preact/package.json +2 -2
- package/templates/blocks/vanilla/package.json +1 -1
- package/vitest.setup.js +11 -0
- package/commands/team/member/update.d.ts +0 -16
- package/commands/team/member/update.js +0 -46
- package/lib/team.d.ts +0 -61
- package/lib/team.js +0 -83
- package/lib/team.test.js +0 -625
- package/server/controllers/action.d.ts +0 -6
- package/server/controllers/action.js +0 -8
- package/server/controllers/appMembers.d.ts +0 -2
- package/server/controllers/appMembers.js +0 -4
- package/server/controllers/appMessages.d.ts +0 -2
- package/server/controllers/appMessages.js +0 -4
- package/server/controllers/appVariables.js +0 -4
- package/server/controllers/assets.d.ts +0 -4
- package/server/controllers/assets.js +0 -6
- package/server/controllers/oauth2Provider.d.ts +0 -2
- package/server/controllers/oauth2Provider.js +0 -4
- package/server/controllers/resources.d.ts +0 -7
- package/server/controllers/resources.js +0 -9
- package/server/controllers/teams.d.ts +0 -2
- package/server/controllers/teams.js +0 -4
- package/server/options/checkRole.d.ts +0 -1
- package/server/options/checkRole.js +0 -2
- package/server/options/checkRole.test.d.ts +0 -1
- package/server/options/checkRole.test.js +0 -13
- package/server/options/getAppMembers.d.ts +0 -3
- package/server/options/getAppMembers.js +0 -4
- package/server/options/getAppTeams.d.ts +0 -2
- package/server/options/getAppTeams.js +0 -4
- package/server/options/getAppUserInfo.d.ts +0 -3
- package/server/options/getAppUserInfo.js +0 -4
- package/server/options/verifyResourceActionPermission.d.ts +0 -1
- package/server/options/verifyResourceActionPermission.js +0 -2
- /package/lib/{team.test.d.ts → group.test.d.ts} +0 -0
- /package/server/controllers/{appVariables.d.ts → common/apps/variables/getAppVariables.d.ts} +0 -0
package/lib/resource.test.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { resolveFixture } from '@appsemble/node-utils';
|
|
2
|
-
import { createServer, createTestUser, models, setArgv
|
|
2
|
+
import { createServer, createTestUser, models, setArgv } from '@appsemble/server';
|
|
3
|
+
import { PredefinedOrganizationRole } from '@appsemble/types';
|
|
3
4
|
import { setTestApp } from 'axios-test-instance';
|
|
4
5
|
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
6
|
import { initAxios } from './initAxios.js';
|
|
@@ -10,34 +11,102 @@ const argv = { host: 'http://localhost', secret: 'test', aesSecret: 'testSecret'
|
|
|
10
11
|
let user;
|
|
11
12
|
let organization;
|
|
12
13
|
let testApp;
|
|
13
|
-
|
|
14
|
-
beforeAll(() => {
|
|
15
|
-
|
|
16
|
-
|
|
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',
|
|
14
|
+
describe('resource', () => {
|
|
15
|
+
beforeAll(() => {
|
|
16
|
+
vi.useFakeTimers();
|
|
17
|
+
setArgv(argv);
|
|
28
18
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
19
|
+
beforeEach(async () => {
|
|
20
|
+
vi.clearAllTimers();
|
|
21
|
+
vi.setSystemTime(0);
|
|
22
|
+
const server = await createServer();
|
|
23
|
+
testApp = await setTestApp(server);
|
|
24
|
+
initAxios({ remote: testApp.defaults.baseURL });
|
|
25
|
+
user = await createTestUser();
|
|
26
|
+
organization = await Organization.create({
|
|
27
|
+
id: 'testorganization',
|
|
28
|
+
name: 'Test Organization',
|
|
29
|
+
});
|
|
30
|
+
await OrganizationMember.create({
|
|
31
|
+
OrganizationId: organization.id,
|
|
32
|
+
UserId: user.id,
|
|
33
|
+
role: PredefinedOrganizationRole.Owner,
|
|
34
|
+
});
|
|
35
|
+
await Organization.create({ id: 'appsemble', name: 'Appsemble' });
|
|
33
36
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
afterAll(() => {
|
|
38
|
+
vi.useRealTimers();
|
|
39
|
+
});
|
|
40
|
+
describe('publishResource', () => {
|
|
41
|
+
it('should publish resources from a file', async () => {
|
|
42
|
+
const resourceDefinition = {
|
|
43
|
+
roles: ['$public'],
|
|
44
|
+
schema: {
|
|
45
|
+
type: 'object',
|
|
46
|
+
additionalProperties: false,
|
|
47
|
+
required: ['name'],
|
|
48
|
+
properties: {
|
|
49
|
+
name: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
},
|
|
52
|
+
email: {
|
|
53
|
+
type: 'string',
|
|
54
|
+
format: 'email',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const app = await App.create({
|
|
60
|
+
path: 'test-app',
|
|
61
|
+
definition: {
|
|
62
|
+
resources: { test: resourceDefinition },
|
|
63
|
+
name: 'Test App',
|
|
64
|
+
defaultPage: 'Test Page',
|
|
65
|
+
},
|
|
66
|
+
vapidPublicKey: 'a',
|
|
67
|
+
vapidPrivateKey: 'b',
|
|
68
|
+
visibility: 'public',
|
|
69
|
+
OrganizationId: organization.id,
|
|
70
|
+
});
|
|
71
|
+
await authorizeCLI('resources:write', testApp);
|
|
72
|
+
await publishResource({
|
|
73
|
+
appId: app.id,
|
|
74
|
+
definition: resourceDefinition,
|
|
75
|
+
path: resolveFixture('resources/test.json'),
|
|
76
|
+
remote: testApp.defaults.baseURL,
|
|
77
|
+
type: 'test',
|
|
78
|
+
seed: false,
|
|
79
|
+
});
|
|
80
|
+
const resources = await Resource.findAll({
|
|
81
|
+
where: { AppId: app.id },
|
|
82
|
+
});
|
|
83
|
+
expect(resources.map((r) => r.toJSON())).toMatchInlineSnapshot(`
|
|
84
|
+
[
|
|
85
|
+
{
|
|
86
|
+
"$created": "1970-01-01T00:00:00.000Z",
|
|
87
|
+
"$updated": "1970-01-01T00:00:00.000Z",
|
|
88
|
+
"email": "test@example.com",
|
|
89
|
+
"id": 1,
|
|
90
|
+
"name": "John Doe",
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"$created": "1970-01-01T00:00:00.000Z",
|
|
94
|
+
"$updated": "1970-01-01T00:00:00.000Z",
|
|
95
|
+
"email": "test2@example.com",
|
|
96
|
+
"id": 2,
|
|
97
|
+
"name": "Jane Doe",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"$created": "1970-01-01T00:00:00.000Z",
|
|
101
|
+
"$updated": "1970-01-01T00:00:00.000Z",
|
|
102
|
+
"id": 3,
|
|
103
|
+
"name": "test name",
|
|
104
|
+
},
|
|
105
|
+
]
|
|
106
|
+
`);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
it('should throw if there is an error', async () => {
|
|
41
110
|
const resourceDefinition = {
|
|
42
111
|
roles: ['$public'],
|
|
43
112
|
schema: {
|
|
@@ -68,324 +137,257 @@ describe('publishResource', () => {
|
|
|
68
137
|
OrganizationId: organization.id,
|
|
69
138
|
});
|
|
70
139
|
await authorizeCLI('resources:write', testApp);
|
|
71
|
-
await
|
|
140
|
+
await app.destroy();
|
|
141
|
+
await expect(() => publishResource({
|
|
72
142
|
appId: app.id,
|
|
73
143
|
definition: resourceDefinition,
|
|
74
144
|
path: resolveFixture('resources/test.json'),
|
|
75
145
|
remote: testApp.defaults.baseURL,
|
|
76
146
|
type: 'test',
|
|
77
147
|
seed: false,
|
|
78
|
-
});
|
|
79
|
-
const resources = await Resource.findAll({
|
|
80
|
-
where: { AppId: app.id },
|
|
81
|
-
});
|
|
82
|
-
expect(resources.map((r) => r.toJSON())).toMatchInlineSnapshot(`
|
|
83
|
-
[
|
|
84
|
-
{
|
|
85
|
-
"$created": "1970-01-01T00:00:00.000Z",
|
|
86
|
-
"$updated": "1970-01-01T00:00:00.000Z",
|
|
87
|
-
"email": "test@example.com",
|
|
88
|
-
"id": 1,
|
|
89
|
-
"name": "John Doe",
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
"$created": "1970-01-01T00:00:00.000Z",
|
|
93
|
-
"$updated": "1970-01-01T00:00:00.000Z",
|
|
94
|
-
"email": "test2@example.com",
|
|
95
|
-
"id": 2,
|
|
96
|
-
"name": "Jane Doe",
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"$created": "1970-01-01T00:00:00.000Z",
|
|
100
|
-
"$updated": "1970-01-01T00:00:00.000Z",
|
|
101
|
-
"id": 3,
|
|
102
|
-
"name": "test name",
|
|
103
|
-
},
|
|
104
|
-
]
|
|
105
|
-
`);
|
|
148
|
+
})).rejects.toThrow('Request failed with status code 404');
|
|
106
149
|
});
|
|
107
|
-
|
|
108
|
-
it('should
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
150
|
+
describe('updateResource', () => {
|
|
151
|
+
it('should update existing resources', async () => {
|
|
152
|
+
const resourceDefinition = {
|
|
153
|
+
roles: ['$public'],
|
|
154
|
+
schema: {
|
|
155
|
+
type: 'object',
|
|
156
|
+
additionalProperties: false,
|
|
157
|
+
required: ['name'],
|
|
158
|
+
properties: {
|
|
159
|
+
name: {
|
|
160
|
+
type: 'string',
|
|
161
|
+
},
|
|
162
|
+
email: {
|
|
163
|
+
type: 'string',
|
|
164
|
+
format: 'email',
|
|
165
|
+
},
|
|
166
|
+
},
|
|
118
167
|
},
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
168
|
+
};
|
|
169
|
+
const app = await App.create({
|
|
170
|
+
path: 'test-app',
|
|
171
|
+
definition: {
|
|
172
|
+
resources: { test: resourceDefinition },
|
|
173
|
+
name: 'Test App',
|
|
174
|
+
defaultPage: 'Test Page',
|
|
122
175
|
},
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
visibility: 'public',
|
|
136
|
-
OrganizationId: organization.id,
|
|
137
|
-
});
|
|
138
|
-
await authorizeCLI('resources:write', testApp);
|
|
139
|
-
await app.destroy();
|
|
140
|
-
await expect(() => publishResource({
|
|
141
|
-
appId: app.id,
|
|
142
|
-
definition: resourceDefinition,
|
|
143
|
-
path: resolveFixture('resources/test.json'),
|
|
144
|
-
remote: testApp.defaults.baseURL,
|
|
145
|
-
type: 'test',
|
|
146
|
-
seed: false,
|
|
147
|
-
})).rejects.toThrow('Request failed with status code 404');
|
|
148
|
-
});
|
|
149
|
-
describe('updateResource', () => {
|
|
150
|
-
it('should update existing resources', async () => {
|
|
151
|
-
const resourceDefinition = {
|
|
152
|
-
roles: ['$public'],
|
|
153
|
-
schema: {
|
|
154
|
-
type: 'object',
|
|
155
|
-
additionalProperties: false,
|
|
156
|
-
required: ['name'],
|
|
157
|
-
properties: {
|
|
158
|
-
name: {
|
|
159
|
-
type: 'string',
|
|
176
|
+
vapidPublicKey: 'a',
|
|
177
|
+
vapidPrivateKey: 'b',
|
|
178
|
+
visibility: 'public',
|
|
179
|
+
OrganizationId: organization.id,
|
|
180
|
+
});
|
|
181
|
+
await Resource.bulkCreate([
|
|
182
|
+
{
|
|
183
|
+
id: 1,
|
|
184
|
+
type: 'test',
|
|
185
|
+
AppId: app.id,
|
|
186
|
+
data: {
|
|
187
|
+
name: 'Hello World',
|
|
160
188
|
},
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
id: 2,
|
|
192
|
+
type: 'test',
|
|
193
|
+
AppId: app.id,
|
|
194
|
+
data: {
|
|
195
|
+
name: 'World Hello',
|
|
196
|
+
email: 'hello@example.com',
|
|
164
197
|
},
|
|
165
198
|
},
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
},
|
|
175
|
-
vapidPublicKey: 'a',
|
|
176
|
-
vapidPrivateKey: 'b',
|
|
177
|
-
visibility: 'public',
|
|
178
|
-
OrganizationId: organization.id,
|
|
179
|
-
});
|
|
180
|
-
await Resource.bulkCreate([
|
|
181
|
-
{
|
|
182
|
-
id: 1,
|
|
183
|
-
type: 'test',
|
|
184
|
-
AppId: app.id,
|
|
185
|
-
data: {
|
|
186
|
-
name: 'Hello World',
|
|
199
|
+
{
|
|
200
|
+
id: 3,
|
|
201
|
+
type: 'test',
|
|
202
|
+
AppId: app.id,
|
|
203
|
+
data: {
|
|
204
|
+
name: 'Random name',
|
|
205
|
+
email: 'removed@example.com',
|
|
206
|
+
},
|
|
187
207
|
},
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
208
|
+
]);
|
|
209
|
+
await authorizeCLI('resources:write', testApp);
|
|
210
|
+
await updateResource({
|
|
211
|
+
appId: app.id,
|
|
212
|
+
resourceName: 'test',
|
|
213
|
+
remote: testApp.defaults.baseURL,
|
|
214
|
+
path: resolveFixture('resources/test-update.json'),
|
|
215
|
+
});
|
|
216
|
+
const resources = await Resource.findAll();
|
|
217
|
+
expect(resources.map((r) => r.toJSON())).toMatchInlineSnapshot(`
|
|
218
|
+
[
|
|
219
|
+
{
|
|
220
|
+
"$created": "1970-01-01T00:00:00.000Z",
|
|
221
|
+
"$updated": "1970-01-01T00:00:00.000Z",
|
|
222
|
+
"email": "test@example.com",
|
|
223
|
+
"id": 1,
|
|
224
|
+
"name": "John Doe",
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
"$created": "1970-01-01T00:00:00.000Z",
|
|
228
|
+
"$updated": "1970-01-01T00:00:00.000Z",
|
|
229
|
+
"email": "test2@example.com",
|
|
230
|
+
"id": 2,
|
|
231
|
+
"name": "Jane Doe",
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"$created": "1970-01-01T00:00:00.000Z",
|
|
235
|
+
"$updated": "1970-01-01T00:00:00.000Z",
|
|
236
|
+
"id": 3,
|
|
237
|
+
"name": "test name",
|
|
238
|
+
},
|
|
239
|
+
]
|
|
240
|
+
`);
|
|
241
|
+
});
|
|
242
|
+
it('should throw if the resource to be updated does not exist', async () => {
|
|
243
|
+
const resourceDefinition = {
|
|
244
|
+
roles: ['$public'],
|
|
245
|
+
schema: {
|
|
246
|
+
type: 'object',
|
|
247
|
+
additionalProperties: false,
|
|
248
|
+
required: ['name'],
|
|
249
|
+
properties: {
|
|
250
|
+
name: {
|
|
251
|
+
type: 'string',
|
|
252
|
+
},
|
|
253
|
+
email: {
|
|
254
|
+
type: 'string',
|
|
255
|
+
format: 'email',
|
|
256
|
+
},
|
|
257
|
+
},
|
|
196
258
|
},
|
|
197
|
-
}
|
|
198
|
-
{
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
email: 'removed@example.com',
|
|
259
|
+
};
|
|
260
|
+
const app = await App.create({
|
|
261
|
+
path: 'test-app',
|
|
262
|
+
definition: {
|
|
263
|
+
resources: { test: resourceDefinition },
|
|
264
|
+
name: 'Test App',
|
|
265
|
+
defaultPage: 'Test Page',
|
|
205
266
|
},
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
{
|
|
219
|
-
"$created": "1970-01-01T00:00:00.000Z",
|
|
220
|
-
"$updated": "1970-01-01T00:00:00.000Z",
|
|
221
|
-
"email": "test@example.com",
|
|
222
|
-
"id": 1,
|
|
223
|
-
"name": "John Doe",
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
"$created": "1970-01-01T00:00:00.000Z",
|
|
227
|
-
"$updated": "1970-01-01T00:00:00.000Z",
|
|
228
|
-
"email": "test2@example.com",
|
|
229
|
-
"id": 2,
|
|
230
|
-
"name": "Jane Doe",
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
"$created": "1970-01-01T00:00:00.000Z",
|
|
234
|
-
"$updated": "1970-01-01T00:00:00.000Z",
|
|
235
|
-
"id": 3,
|
|
236
|
-
"name": "test name",
|
|
237
|
-
},
|
|
238
|
-
]
|
|
239
|
-
`);
|
|
240
|
-
});
|
|
241
|
-
it('should throw if the resource to be updated does not exist', async () => {
|
|
242
|
-
const resourceDefinition = {
|
|
243
|
-
roles: ['$public'],
|
|
244
|
-
schema: {
|
|
245
|
-
type: 'object',
|
|
246
|
-
additionalProperties: false,
|
|
247
|
-
required: ['name'],
|
|
248
|
-
properties: {
|
|
249
|
-
name: {
|
|
250
|
-
type: 'string',
|
|
267
|
+
vapidPublicKey: 'a',
|
|
268
|
+
vapidPrivateKey: 'b',
|
|
269
|
+
visibility: 'public',
|
|
270
|
+
OrganizationId: organization.id,
|
|
271
|
+
});
|
|
272
|
+
await Resource.bulkCreate([
|
|
273
|
+
{
|
|
274
|
+
id: 1,
|
|
275
|
+
type: 'test',
|
|
276
|
+
AppId: app.id,
|
|
277
|
+
data: {
|
|
278
|
+
name: 'Hello World',
|
|
251
279
|
},
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
id: 2,
|
|
283
|
+
type: 'test',
|
|
284
|
+
AppId: app.id,
|
|
285
|
+
data: {
|
|
286
|
+
name: 'World Hello',
|
|
287
|
+
email: 'hello@example.com',
|
|
255
288
|
},
|
|
256
289
|
},
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
},
|
|
266
|
-
vapidPublicKey: 'a',
|
|
267
|
-
vapidPrivateKey: 'b',
|
|
268
|
-
visibility: 'public',
|
|
269
|
-
OrganizationId: organization.id,
|
|
290
|
+
]);
|
|
291
|
+
await authorizeCLI('resources:write', testApp);
|
|
292
|
+
await expect(() => updateResource({
|
|
293
|
+
appId: app.id,
|
|
294
|
+
resourceName: 'test',
|
|
295
|
+
remote: testApp.defaults.baseURL,
|
|
296
|
+
path: resolveFixture('resources/test-update.json'),
|
|
297
|
+
})).rejects.toThrow('Request failed with status code 404');
|
|
270
298
|
});
|
|
271
|
-
|
|
272
|
-
{
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
299
|
+
it('should not update if there are no IDs in resource file', async () => {
|
|
300
|
+
const resourceDefinition = {
|
|
301
|
+
roles: ['$public'],
|
|
302
|
+
schema: {
|
|
303
|
+
type: 'object',
|
|
304
|
+
additionalProperties: false,
|
|
305
|
+
required: ['name'],
|
|
306
|
+
properties: {
|
|
307
|
+
name: {
|
|
308
|
+
type: 'string',
|
|
309
|
+
},
|
|
310
|
+
email: {
|
|
311
|
+
type: 'string',
|
|
312
|
+
format: 'email',
|
|
313
|
+
},
|
|
314
|
+
},
|
|
278
315
|
},
|
|
279
|
-
}
|
|
280
|
-
{
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
email: 'hello@example.com',
|
|
316
|
+
};
|
|
317
|
+
const app = await App.create({
|
|
318
|
+
path: 'test-app',
|
|
319
|
+
definition: {
|
|
320
|
+
resources: { test: resourceDefinition },
|
|
321
|
+
name: 'Test App',
|
|
322
|
+
defaultPage: 'Test Page',
|
|
287
323
|
},
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
roles: ['$public'],
|
|
301
|
-
schema: {
|
|
302
|
-
type: 'object',
|
|
303
|
-
additionalProperties: false,
|
|
304
|
-
required: ['name'],
|
|
305
|
-
properties: {
|
|
306
|
-
name: {
|
|
307
|
-
type: 'string',
|
|
308
|
-
},
|
|
309
|
-
email: {
|
|
310
|
-
type: 'string',
|
|
311
|
-
format: 'email',
|
|
324
|
+
vapidPublicKey: 'a',
|
|
325
|
+
vapidPrivateKey: 'b',
|
|
326
|
+
visibility: 'public',
|
|
327
|
+
OrganizationId: organization.id,
|
|
328
|
+
});
|
|
329
|
+
await Resource.bulkCreate([
|
|
330
|
+
{
|
|
331
|
+
id: 1,
|
|
332
|
+
type: 'test',
|
|
333
|
+
AppId: app.id,
|
|
334
|
+
data: {
|
|
335
|
+
name: 'Hello World',
|
|
312
336
|
},
|
|
313
337
|
},
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
},
|
|
323
|
-
vapidPublicKey: 'a',
|
|
324
|
-
vapidPrivateKey: 'b',
|
|
325
|
-
visibility: 'public',
|
|
326
|
-
OrganizationId: organization.id,
|
|
327
|
-
});
|
|
328
|
-
await Resource.bulkCreate([
|
|
329
|
-
{
|
|
330
|
-
id: 1,
|
|
331
|
-
type: 'test',
|
|
332
|
-
AppId: app.id,
|
|
333
|
-
data: {
|
|
334
|
-
name: 'Hello World',
|
|
335
|
-
},
|
|
336
|
-
},
|
|
337
|
-
{
|
|
338
|
-
id: 2,
|
|
339
|
-
type: 'test',
|
|
340
|
-
AppId: app.id,
|
|
341
|
-
data: {
|
|
342
|
-
name: 'World Hello',
|
|
343
|
-
email: 'hello@example.com',
|
|
338
|
+
{
|
|
339
|
+
id: 2,
|
|
340
|
+
type: 'test',
|
|
341
|
+
AppId: app.id,
|
|
342
|
+
data: {
|
|
343
|
+
name: 'World Hello',
|
|
344
|
+
email: 'hello@example.com',
|
|
345
|
+
},
|
|
344
346
|
},
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
347
|
+
]);
|
|
348
|
+
await authorizeCLI('resources:write', testApp);
|
|
349
|
+
const resources = await Resource.findAll();
|
|
350
|
+
expect(resources.map((r) => r.toJSON())).toMatchInlineSnapshot(`
|
|
351
|
+
[
|
|
352
|
+
{
|
|
353
|
+
"$created": "1970-01-01T00:00:00.000Z",
|
|
354
|
+
"$updated": "1970-01-01T00:00:00.000Z",
|
|
355
|
+
"id": 1,
|
|
356
|
+
"name": "Hello World",
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
"$created": "1970-01-01T00:00:00.000Z",
|
|
360
|
+
"$updated": "1970-01-01T00:00:00.000Z",
|
|
361
|
+
"email": "hello@example.com",
|
|
362
|
+
"id": 2,
|
|
363
|
+
"name": "World Hello",
|
|
364
|
+
},
|
|
365
|
+
]
|
|
366
|
+
`);
|
|
367
|
+
await updateResource({
|
|
368
|
+
appId: app.id,
|
|
369
|
+
resourceName: 'test',
|
|
370
|
+
remote: testApp.defaults.baseURL,
|
|
371
|
+
path: resolveFixture('resources/test.json'),
|
|
372
|
+
});
|
|
373
|
+
expect(resources.map((r) => r.toJSON())).toMatchInlineSnapshot(`
|
|
374
|
+
[
|
|
375
|
+
{
|
|
376
|
+
"$created": "1970-01-01T00:00:00.000Z",
|
|
377
|
+
"$updated": "1970-01-01T00:00:00.000Z",
|
|
378
|
+
"id": 1,
|
|
379
|
+
"name": "Hello World",
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
"$created": "1970-01-01T00:00:00.000Z",
|
|
383
|
+
"$updated": "1970-01-01T00:00:00.000Z",
|
|
384
|
+
"email": "hello@example.com",
|
|
385
|
+
"id": 2,
|
|
386
|
+
"name": "World Hello",
|
|
387
|
+
},
|
|
388
|
+
]
|
|
389
|
+
`);
|
|
371
390
|
});
|
|
372
|
-
expect(resources.map((r) => r.toJSON())).toMatchInlineSnapshot(`
|
|
373
|
-
[
|
|
374
|
-
{
|
|
375
|
-
"$created": "1970-01-01T00:00:00.000Z",
|
|
376
|
-
"$updated": "1970-01-01T00:00:00.000Z",
|
|
377
|
-
"id": 1,
|
|
378
|
-
"name": "Hello World",
|
|
379
|
-
},
|
|
380
|
-
{
|
|
381
|
-
"$created": "1970-01-01T00:00:00.000Z",
|
|
382
|
-
"$updated": "1970-01-01T00:00:00.000Z",
|
|
383
|
-
"email": "hello@example.com",
|
|
384
|
-
"id": 2,
|
|
385
|
-
"name": "World Hello",
|
|
386
|
-
},
|
|
387
|
-
]
|
|
388
|
-
`);
|
|
389
391
|
});
|
|
390
392
|
});
|
|
391
393
|
//# sourceMappingURL=resource.test.js.map
|