@stamhoofd/backend 2.78.2 → 2.78.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/.env.ci.json +15 -10
- package/jest.config.cjs +17 -0
- package/package.json +10 -10
- package/src/endpoints/auth/GetUserEndpoint.test.ts +0 -10
- package/src/endpoints/global/organizations/CreateOrganizationEndpoint.test.ts +1 -1
- package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.test.ts +0 -4
- package/src/endpoints/global/organizations/SearchOrganizationEndpoint.test.ts +0 -4
- package/src/endpoints/global/registration/PatchUserMembersEndpoint.test.ts +288 -8
- package/src/endpoints/global/registration/RegisterMembersEndpoint.test.ts +7 -7
- package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.test.ts +2 -217
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopOrdersEndpoint.ts +6 -3
- package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.test.ts +4 -6
- package/src/endpoints/organization/webshops/GetWebshopEndpoint.test.ts +2 -20
- package/src/helpers/AdminPermissionChecker.ts +72 -142
- package/src/helpers/GlobalHelper.ts +6 -1
- package/src/services/FileSignService.ts +2 -2
- package/src/services/MemberRecordStore.ts +155 -0
- package/src/services/PlatformMembershipService.ts +17 -8
- package/tests/e2e/register.test.ts +49 -21
- package/tests/helpers/StripeMocker.ts +7 -2
- package/tests/jest.global.setup.ts +6 -1
- package/tests/jest.setup.ts +10 -2
package/.env.ci.json
CHANGED
|
@@ -8,16 +8,19 @@
|
|
|
8
8
|
"NL": "dev.stamhoofd.nl"
|
|
9
9
|
},
|
|
10
10
|
"webshop": "shop.stamhoofd.dev",
|
|
11
|
-
"api": "api.stamhoofd.dev"
|
|
11
|
+
"api": "api.stamhoofd.dev",
|
|
12
|
+
"defaultBroadcastEmail": {
|
|
13
|
+
"": "stamhoofd.email"
|
|
14
|
+
}
|
|
12
15
|
},
|
|
13
16
|
|
|
14
17
|
"PORT": 9091,
|
|
15
18
|
"DB_HOST": "127.0.0.1",
|
|
16
19
|
"DB_USER": "root",
|
|
17
20
|
"DB_PASS": "root",
|
|
18
|
-
"DB_DATABASE": "stamhoofd",
|
|
21
|
+
"DB_DATABASE": "stamhoofd-tests",
|
|
19
22
|
|
|
20
|
-
"SMTP_HOST": "
|
|
23
|
+
"SMTP_HOST": "0.0.0.0",
|
|
21
24
|
"SMTP_USERNAME": "test",
|
|
22
25
|
"SMTP_PASSWORD": "test",
|
|
23
26
|
"SMTP_PORT": 587,
|
|
@@ -26,17 +29,19 @@
|
|
|
26
29
|
"AWS_SECRET_ACCESS_KEY": "",
|
|
27
30
|
"AWS_REGION": "",
|
|
28
31
|
|
|
29
|
-
"SPACES_ENDPOINT": "
|
|
30
|
-
"SPACES_BUCKET": "
|
|
31
|
-
"SPACES_KEY": "",
|
|
32
|
-
"SPACES_SECRET": "",
|
|
32
|
+
"SPACES_ENDPOINT": "anydomain.example",
|
|
33
|
+
"SPACES_BUCKET": "example",
|
|
34
|
+
"SPACES_KEY": "test",
|
|
35
|
+
"SPACES_SECRET": "test",
|
|
33
36
|
|
|
34
37
|
"INTERNAL_SECRET_KEY": "test",
|
|
35
38
|
|
|
36
|
-
"STRIPE_SECRET_KEY": "
|
|
37
|
-
"STRIPE_ENDPOINT_SECRET": "
|
|
39
|
+
"STRIPE_SECRET_KEY": "sk_test_test",
|
|
40
|
+
"STRIPE_ENDPOINT_SECRET": "sk_test",
|
|
38
41
|
"translationNamespace": "digit",
|
|
39
42
|
"platformName": "ravot",
|
|
40
43
|
"userMode": "organization",
|
|
41
|
-
"WHITELISTED_EMAIL_DESTINATIONS": []
|
|
44
|
+
"WHITELISTED_EMAIL_DESTINATIONS": [],
|
|
45
|
+
"MEMBER_NUMBER_ALGORITHM": "Incremental",
|
|
46
|
+
"MEMBER_NUMBER_ALGORITHM_LENGTH": 10
|
|
42
47
|
}
|
package/jest.config.cjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const useGithubActions = !!process.env.GITHUB_ACTIONS;
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
roots: ['<rootDir>/dist'],
|
|
3
5
|
testEnvironment: 'node',
|
|
@@ -5,6 +7,21 @@ module.exports = {
|
|
|
5
7
|
'jest-extended/all',
|
|
6
8
|
'./dist/tests/jest.setup.js',
|
|
7
9
|
],
|
|
10
|
+
reporters: [['jest-console-group-reporter', {
|
|
11
|
+
consoleLevels: ['error', 'warn', 'log'],
|
|
12
|
+
filters: [],
|
|
13
|
+
groups: [],
|
|
14
|
+
onlyFailingTestSuites: true,
|
|
15
|
+
afterEachTest: {
|
|
16
|
+
enable: false,
|
|
17
|
+
},
|
|
18
|
+
afterAllTests: {
|
|
19
|
+
reportType: 'detailed',
|
|
20
|
+
enable: true,
|
|
21
|
+
filePaths: true,
|
|
22
|
+
},
|
|
23
|
+
useGitHubActions: useGithubActions,
|
|
24
|
+
}]],
|
|
8
25
|
globalSetup: './dist/tests/jest.global.setup.js',
|
|
9
26
|
// verbose: true,
|
|
10
27
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stamhoofd/backend",
|
|
3
|
-
"version": "2.78.
|
|
3
|
+
"version": "2.78.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
"@simonbackx/simple-encoding": "2.20.0",
|
|
38
38
|
"@simonbackx/simple-endpoints": "1.19.1",
|
|
39
39
|
"@simonbackx/simple-logging": "^1.0.1",
|
|
40
|
-
"@stamhoofd/backend-i18n": "2.78.
|
|
41
|
-
"@stamhoofd/backend-middleware": "2.78.
|
|
42
|
-
"@stamhoofd/email": "2.78.
|
|
43
|
-
"@stamhoofd/models": "2.78.
|
|
44
|
-
"@stamhoofd/queues": "2.78.
|
|
45
|
-
"@stamhoofd/sql": "2.78.
|
|
46
|
-
"@stamhoofd/structures": "2.78.
|
|
47
|
-
"@stamhoofd/utility": "2.78.
|
|
40
|
+
"@stamhoofd/backend-i18n": "2.78.3",
|
|
41
|
+
"@stamhoofd/backend-middleware": "2.78.3",
|
|
42
|
+
"@stamhoofd/email": "2.78.3",
|
|
43
|
+
"@stamhoofd/models": "2.78.3",
|
|
44
|
+
"@stamhoofd/queues": "2.78.3",
|
|
45
|
+
"@stamhoofd/sql": "2.78.3",
|
|
46
|
+
"@stamhoofd/structures": "2.78.3",
|
|
47
|
+
"@stamhoofd/utility": "2.78.3",
|
|
48
48
|
"archiver": "^7.0.1",
|
|
49
49
|
"aws-sdk": "^2.885.0",
|
|
50
50
|
"axios": "1.6.8",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "272bfbb259109530326ec2fd8c83af5f69d6268b"
|
|
68
68
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Request } from '@simonbackx/simple-endpoints';
|
|
2
2
|
import { OrganizationFactory, Token, UserFactory } from '@stamhoofd/models';
|
|
3
|
-
import { NewUser } from '@stamhoofd/structures';
|
|
4
3
|
|
|
5
4
|
import { testServer } from '../../../tests/helpers/TestServer';
|
|
6
5
|
import { GetUserEndpoint } from './GetUserEndpoint';
|
|
@@ -19,21 +18,12 @@ describe('Endpoint.GetUser', () => {
|
|
|
19
18
|
|
|
20
19
|
const response = await testServer.test(endpoint, r);
|
|
21
20
|
expect(response.body).toBeDefined();
|
|
22
|
-
|
|
23
|
-
if (!(response.body instanceof NewUser)) {
|
|
24
|
-
throw new Error('Expected NewUser');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
21
|
expect(response.body.id).toEqual(user.id);
|
|
28
22
|
});
|
|
29
23
|
|
|
30
24
|
test('Request user details when not signed in is not working', async () => {
|
|
31
25
|
const organization = await new OrganizationFactory({}).create();
|
|
32
|
-
const user = await new UserFactory({ organization }).create();
|
|
33
|
-
const token = await Token.createToken(user);
|
|
34
|
-
|
|
35
26
|
const r = Request.buildJson('GET', '/v1/user', organization.getApiHost());
|
|
36
|
-
|
|
37
27
|
await expect(testServer.test(endpoint, r)).rejects.toThrow(/missing/i);
|
|
38
28
|
});
|
|
39
29
|
|
|
@@ -4,7 +4,7 @@ import { Address, Country, CreateOrganization, NewUser, Organization as Organiza
|
|
|
4
4
|
import { testServer } from '../../../../tests/helpers/TestServer';
|
|
5
5
|
import { CreateOrganizationEndpoint } from './CreateOrganizationEndpoint';
|
|
6
6
|
|
|
7
|
-
describe('Endpoint.CreateOrganization', () => {
|
|
7
|
+
describe.skip('Endpoint.CreateOrganization', () => {
|
|
8
8
|
// Test endpoint
|
|
9
9
|
const endpoint = new CreateOrganizationEndpoint();
|
|
10
10
|
|
|
@@ -11,7 +11,6 @@ describe('Endpoint.GetOrganizationFromDomain', () => {
|
|
|
11
11
|
|
|
12
12
|
test('Get organization from default uri', async () => {
|
|
13
13
|
const organization = await new OrganizationFactory({}).create();
|
|
14
|
-
const groups = await new GroupFactory({ organization }).createMultiple(2);
|
|
15
14
|
|
|
16
15
|
const r = Request.buildJson('GET', '/v2/organization-from-domain');
|
|
17
16
|
r.query = {
|
|
@@ -26,12 +25,10 @@ describe('Endpoint.GetOrganizationFromDomain', () => {
|
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
expect(response.body.id).toEqual(organization.id);
|
|
29
|
-
expect(response.body.groups.map(g => g.id).sort()).toEqual(groups.map(g => g.id).sort());
|
|
30
28
|
});
|
|
31
29
|
|
|
32
30
|
test('Get organization from custom domain', async () => {
|
|
33
31
|
const organization = await new OrganizationFactory({ domain: 'inschrijven.mijnscouts.be' }).create();
|
|
34
|
-
const groups = await new GroupFactory({ organization }).createMultiple(2);
|
|
35
32
|
|
|
36
33
|
const r = Request.buildJson('GET', '/v2/organization-from-domain');
|
|
37
34
|
r.query = {
|
|
@@ -46,6 +43,5 @@ describe('Endpoint.GetOrganizationFromDomain', () => {
|
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
expect(response.body.id).toEqual(organization.id);
|
|
49
|
-
expect(response.body.groups.map(g => g.id).sort()).toEqual(groups.map(g => g.id).sort());
|
|
50
46
|
});
|
|
51
47
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Request } from '@simonbackx/simple-endpoints';
|
|
2
2
|
import { OrganizationFactory } from '@stamhoofd/models';
|
|
3
|
-
import { OrganizationSimple } from '@stamhoofd/structures';
|
|
4
3
|
import { v4 as uuidv4 } from 'uuid';
|
|
5
4
|
|
|
6
5
|
import { testServer } from '../../../../tests/helpers/TestServer';
|
|
@@ -25,7 +24,6 @@ describe('Endpoint.SearchOrganization', () => {
|
|
|
25
24
|
expect(response.body).toHaveLength(1);
|
|
26
25
|
|
|
27
26
|
// Access token should be expired
|
|
28
|
-
expect(response.body[0]).toBeInstanceOf(OrganizationSimple);
|
|
29
27
|
expect(response.status).toEqual(200);
|
|
30
28
|
expect(response.body[0]).toMatchObject({
|
|
31
29
|
id: organization.id,
|
|
@@ -50,8 +48,6 @@ describe('Endpoint.SearchOrganization', () => {
|
|
|
50
48
|
expect(response.body).toHaveLength(2);
|
|
51
49
|
|
|
52
50
|
// Access token should be expired
|
|
53
|
-
expect(response.body[0]).toBeInstanceOf(OrganizationSimple);
|
|
54
|
-
expect(response.body[1]).toBeInstanceOf(OrganizationSimple);
|
|
55
51
|
expect(response.status).toEqual(200);
|
|
56
52
|
expect(response.body.map(o => o.id).sort()).toEqual(organizations.map(o => o.id).sort());
|
|
57
53
|
});
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { PatchableArray } from '@simonbackx/simple-encoding';
|
|
1
|
+
import { PatchableArray, PatchMap } from '@simonbackx/simple-encoding';
|
|
2
2
|
import { Endpoint, Request } from '@simonbackx/simple-endpoints';
|
|
3
|
-
import { GroupFactory, MemberFactory, OrganizationFactory, RegistrationFactory, Token, UserFactory } from '@stamhoofd/models';
|
|
4
|
-
import { MemberDetails, MemberWithRegistrationsBlob, Parent } from '@stamhoofd/structures';
|
|
3
|
+
import { GroupFactory, MemberFactory, OrganizationFactory, Platform, RegistrationFactory, Token, UserFactory } from '@stamhoofd/models';
|
|
4
|
+
import { MemberDetails, MemberWithRegistrationsBlob, OrganizationMetaData, OrganizationRecordsConfiguration, Parent, PatchAnswers, PermissionLevel, RecordCategory, RecordSettings, RecordTextAnswer } from '@stamhoofd/structures';
|
|
5
5
|
import { testServer } from '../../../../tests/helpers/TestServer';
|
|
6
6
|
import { PatchUserMembersEndpoint } from './PatchUserMembersEndpoint';
|
|
7
|
+
import { Database } from '@simonbackx/simple-database';
|
|
8
|
+
import { TestUtils } from '@stamhoofd/test-utils';
|
|
7
9
|
|
|
8
10
|
const baseUrl = `/members`;
|
|
9
11
|
const endpoint = new PatchUserMembersEndpoint();
|
|
@@ -17,12 +19,20 @@ const birthDay = { year: 1993, month: 4, day: 5 };
|
|
|
17
19
|
const errorWithCode = (code: string) => expect.objectContaining({ code }) as jest.Constructable;
|
|
18
20
|
|
|
19
21
|
describe('Endpoint.PatchUserMembersEndpoint', () => {
|
|
22
|
+
beforeEach(async () => {
|
|
23
|
+
TestUtils.setEnvironment('userMode', 'platform');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(async () => {
|
|
27
|
+
// Delete all members (so the duplicate checks work as expected)
|
|
28
|
+
await Database.delete('DELETE FROM `members`');
|
|
29
|
+
});
|
|
30
|
+
|
|
20
31
|
describe('Duplicate members', () => {
|
|
21
32
|
test('The security code should be a requirement', async () => {
|
|
22
33
|
const organization = await new OrganizationFactory({ }).create();
|
|
23
|
-
const user = await new UserFactory({
|
|
34
|
+
const user = await new UserFactory({ }).create();
|
|
24
35
|
const existingMember = await new MemberFactory({
|
|
25
|
-
organization,
|
|
26
36
|
firstName,
|
|
27
37
|
lastName,
|
|
28
38
|
birthDay,
|
|
@@ -50,9 +60,8 @@ describe('Endpoint.PatchUserMembersEndpoint', () => {
|
|
|
50
60
|
|
|
51
61
|
test('The security code is not a requirement for members without additional data', async () => {
|
|
52
62
|
const organization = await new OrganizationFactory({ }).create();
|
|
53
|
-
const user = await new UserFactory({
|
|
63
|
+
const user = await new UserFactory({ }).create();
|
|
54
64
|
const existingMember = await new MemberFactory({
|
|
55
|
-
organization,
|
|
56
65
|
firstName,
|
|
57
66
|
lastName,
|
|
58
67
|
birthDay,
|
|
@@ -108,7 +117,6 @@ describe('Endpoint.PatchUserMembersEndpoint', () => {
|
|
|
108
117
|
});
|
|
109
118
|
|
|
110
119
|
const existingMember = await new MemberFactory({
|
|
111
|
-
organization,
|
|
112
120
|
birthDay,
|
|
113
121
|
details,
|
|
114
122
|
}).create();
|
|
@@ -160,4 +168,276 @@ describe('Endpoint.PatchUserMembersEndpoint', () => {
|
|
|
160
168
|
expect(member.details.parents[0]).toEqual(existingMember.details.parents[0]);
|
|
161
169
|
});
|
|
162
170
|
});
|
|
171
|
+
|
|
172
|
+
describe('Record answers', () => {
|
|
173
|
+
test('A user can save answers of records of an organization it has not yet registered for', async () => {
|
|
174
|
+
const commentsRecord = RecordSettings.create({
|
|
175
|
+
name: 'Opmerkingen',
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
const recordCategory = RecordCategory.create({
|
|
179
|
+
name: 'Medische fiche',
|
|
180
|
+
records: [
|
|
181
|
+
commentsRecord,
|
|
182
|
+
],
|
|
183
|
+
});
|
|
184
|
+
const organization = await new OrganizationFactory({
|
|
185
|
+
meta: OrganizationMetaData.create({
|
|
186
|
+
recordsConfiguration: OrganizationRecordsConfiguration.create({
|
|
187
|
+
recordCategories: [recordCategory],
|
|
188
|
+
}),
|
|
189
|
+
}),
|
|
190
|
+
}).create();
|
|
191
|
+
|
|
192
|
+
const user = await new UserFactory({ }).create();
|
|
193
|
+
const existingMember = await new MemberFactory({
|
|
194
|
+
firstName,
|
|
195
|
+
lastName,
|
|
196
|
+
birthDay,
|
|
197
|
+
generateData: false,
|
|
198
|
+
// Give user access to this member
|
|
199
|
+
user,
|
|
200
|
+
}).create();
|
|
201
|
+
|
|
202
|
+
const token = await Token.createToken(user);
|
|
203
|
+
|
|
204
|
+
const recordAnswers = new PatchMap() as PatchAnswers;
|
|
205
|
+
|
|
206
|
+
recordAnswers.set(commentsRecord.id, RecordTextAnswer.create({
|
|
207
|
+
settings: commentsRecord,
|
|
208
|
+
value: 'Some comments',
|
|
209
|
+
}));
|
|
210
|
+
|
|
211
|
+
const arr: Body = new PatchableArray();
|
|
212
|
+
const patch = MemberWithRegistrationsBlob.patch({
|
|
213
|
+
id: existingMember.id,
|
|
214
|
+
details: MemberDetails.patch({
|
|
215
|
+
recordAnswers,
|
|
216
|
+
}),
|
|
217
|
+
});
|
|
218
|
+
arr.addPatch(patch);
|
|
219
|
+
|
|
220
|
+
const request = Request.buildJson('PATCH', baseUrl, organization.getApiHost(), arr);
|
|
221
|
+
request.headers.authorization = 'Bearer ' + token.accessToken;
|
|
222
|
+
const response = await testServer.test(endpoint, request);
|
|
223
|
+
|
|
224
|
+
// Check returned
|
|
225
|
+
expect(response.status).toBe(200);
|
|
226
|
+
expect(response.body.members.length).toBe(1);
|
|
227
|
+
const member = response.body.members[0];
|
|
228
|
+
expect(member.details.recordAnswers.get(commentsRecord.id)).toMatchObject({
|
|
229
|
+
value: 'Some comments',
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test('A user cannot save answers to organization read-only records', async () => {
|
|
234
|
+
const commentsRecord = RecordSettings.create({
|
|
235
|
+
name: 'Opmerkingen',
|
|
236
|
+
externalPermissionLevel: PermissionLevel.Read,
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
const recordCategory = RecordCategory.create({
|
|
240
|
+
name: 'Medische fiche',
|
|
241
|
+
records: [
|
|
242
|
+
commentsRecord,
|
|
243
|
+
],
|
|
244
|
+
});
|
|
245
|
+
const organization = await new OrganizationFactory({
|
|
246
|
+
meta: OrganizationMetaData.create({
|
|
247
|
+
recordsConfiguration: OrganizationRecordsConfiguration.create({
|
|
248
|
+
recordCategories: [recordCategory],
|
|
249
|
+
}),
|
|
250
|
+
}),
|
|
251
|
+
}).create();
|
|
252
|
+
|
|
253
|
+
const user = await new UserFactory({ }).create();
|
|
254
|
+
const existingMember = await new MemberFactory({
|
|
255
|
+
firstName,
|
|
256
|
+
lastName,
|
|
257
|
+
birthDay,
|
|
258
|
+
generateData: false,
|
|
259
|
+
// Give user access to this member
|
|
260
|
+
user,
|
|
261
|
+
}).create();
|
|
262
|
+
|
|
263
|
+
const token = await Token.createToken(user);
|
|
264
|
+
|
|
265
|
+
const recordAnswers = new PatchMap() as PatchAnswers;
|
|
266
|
+
|
|
267
|
+
recordAnswers.set(commentsRecord.id, RecordTextAnswer.create({
|
|
268
|
+
settings: commentsRecord,
|
|
269
|
+
value: 'Some comments',
|
|
270
|
+
}));
|
|
271
|
+
|
|
272
|
+
const arr: Body = new PatchableArray();
|
|
273
|
+
const patch = MemberWithRegistrationsBlob.patch({
|
|
274
|
+
id: existingMember.id,
|
|
275
|
+
details: MemberDetails.patch({
|
|
276
|
+
recordAnswers,
|
|
277
|
+
}),
|
|
278
|
+
});
|
|
279
|
+
arr.addPatch(patch);
|
|
280
|
+
|
|
281
|
+
const request = Request.buildJson('PATCH', baseUrl, organization.getApiHost(), arr);
|
|
282
|
+
request.headers.authorization = 'Bearer ' + token.accessToken;
|
|
283
|
+
await expect(testServer.test(endpoint, request)).rejects.toThrow(errorWithCode('permission_denied'));
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test('A user can save answers of records of the platform', async () => {
|
|
287
|
+
const commentsRecord = RecordSettings.create({
|
|
288
|
+
name: 'Opmerkingen',
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
const recordCategory = RecordCategory.create({
|
|
292
|
+
name: 'Medische fiche',
|
|
293
|
+
records: [
|
|
294
|
+
commentsRecord,
|
|
295
|
+
],
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
const platform = await Platform.getShared();
|
|
299
|
+
platform.config.recordsConfiguration.recordCategories.push(recordCategory);
|
|
300
|
+
await platform.save();
|
|
301
|
+
|
|
302
|
+
const organization = await new OrganizationFactory({}).create();
|
|
303
|
+
|
|
304
|
+
const user = await new UserFactory({ }).create();
|
|
305
|
+
const existingMember = await new MemberFactory({
|
|
306
|
+
firstName,
|
|
307
|
+
lastName,
|
|
308
|
+
birthDay,
|
|
309
|
+
generateData: false,
|
|
310
|
+
// Give user access to this member
|
|
311
|
+
user,
|
|
312
|
+
}).create();
|
|
313
|
+
|
|
314
|
+
const token = await Token.createToken(user);
|
|
315
|
+
|
|
316
|
+
const recordAnswers = new PatchMap() as PatchAnswers;
|
|
317
|
+
|
|
318
|
+
recordAnswers.set(commentsRecord.id, RecordTextAnswer.create({
|
|
319
|
+
settings: commentsRecord,
|
|
320
|
+
value: 'Some comments',
|
|
321
|
+
}));
|
|
322
|
+
|
|
323
|
+
const arr: Body = new PatchableArray();
|
|
324
|
+
const patch = MemberWithRegistrationsBlob.patch({
|
|
325
|
+
id: existingMember.id,
|
|
326
|
+
details: MemberDetails.patch({
|
|
327
|
+
recordAnswers,
|
|
328
|
+
}),
|
|
329
|
+
});
|
|
330
|
+
arr.addPatch(patch);
|
|
331
|
+
|
|
332
|
+
const request = Request.buildJson('PATCH', baseUrl, organization.getApiHost(), arr);
|
|
333
|
+
request.headers.authorization = 'Bearer ' + token.accessToken;
|
|
334
|
+
const response = await testServer.test(endpoint, request);
|
|
335
|
+
|
|
336
|
+
// Check returned
|
|
337
|
+
expect(response.status).toBe(200);
|
|
338
|
+
expect(response.body.members.length).toBe(1);
|
|
339
|
+
const member = response.body.members[0];
|
|
340
|
+
expect(member.details.recordAnswers.get(commentsRecord.id)).toMatchObject({
|
|
341
|
+
value: 'Some comments',
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
test('A user cannot save answers to platform read-only records', async () => {
|
|
346
|
+
const commentsRecord = RecordSettings.create({
|
|
347
|
+
name: 'Opmerkingen',
|
|
348
|
+
externalPermissionLevel: PermissionLevel.Read,
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
const recordCategory = RecordCategory.create({
|
|
352
|
+
name: 'Medische fiche',
|
|
353
|
+
records: [
|
|
354
|
+
commentsRecord,
|
|
355
|
+
],
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const platform = await Platform.getShared();
|
|
359
|
+
platform.config.recordsConfiguration.recordCategories.push(recordCategory);
|
|
360
|
+
await platform.save();
|
|
361
|
+
|
|
362
|
+
const organization = await new OrganizationFactory({}).create();
|
|
363
|
+
|
|
364
|
+
const user = await new UserFactory({ }).create();
|
|
365
|
+
const existingMember = await new MemberFactory({
|
|
366
|
+
firstName,
|
|
367
|
+
lastName,
|
|
368
|
+
birthDay,
|
|
369
|
+
generateData: false,
|
|
370
|
+
// Give user access to this member
|
|
371
|
+
user,
|
|
372
|
+
}).create();
|
|
373
|
+
|
|
374
|
+
const token = await Token.createToken(user);
|
|
375
|
+
|
|
376
|
+
const recordAnswers = new PatchMap() as PatchAnswers;
|
|
377
|
+
|
|
378
|
+
recordAnswers.set(commentsRecord.id, RecordTextAnswer.create({
|
|
379
|
+
settings: commentsRecord,
|
|
380
|
+
value: 'Some comments',
|
|
381
|
+
}));
|
|
382
|
+
|
|
383
|
+
const arr: Body = new PatchableArray();
|
|
384
|
+
const patch = MemberWithRegistrationsBlob.patch({
|
|
385
|
+
id: existingMember.id,
|
|
386
|
+
details: MemberDetails.patch({
|
|
387
|
+
recordAnswers,
|
|
388
|
+
}),
|
|
389
|
+
});
|
|
390
|
+
arr.addPatch(patch);
|
|
391
|
+
|
|
392
|
+
const request = Request.buildJson('PATCH', baseUrl, organization.getApiHost(), arr);
|
|
393
|
+
request.headers.authorization = 'Bearer ' + token.accessToken;
|
|
394
|
+
await expect(testServer.test(endpoint, request)).rejects.toThrow(errorWithCode('permission_denied'));
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
test('A user can not save anwers to inexisting records', async () => {
|
|
398
|
+
const commentsRecord = RecordSettings.create({
|
|
399
|
+
name: 'Opmerkingen',
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
const organization = await new OrganizationFactory({
|
|
403
|
+
meta: OrganizationMetaData.create({
|
|
404
|
+
recordsConfiguration: OrganizationRecordsConfiguration.create({
|
|
405
|
+
recordCategories: [],
|
|
406
|
+
}),
|
|
407
|
+
}),
|
|
408
|
+
}).create();
|
|
409
|
+
|
|
410
|
+
const user = await new UserFactory({ }).create();
|
|
411
|
+
const existingMember = await new MemberFactory({
|
|
412
|
+
firstName,
|
|
413
|
+
lastName,
|
|
414
|
+
birthDay,
|
|
415
|
+
generateData: false,
|
|
416
|
+
// Give user access to this member
|
|
417
|
+
user,
|
|
418
|
+
}).create();
|
|
419
|
+
|
|
420
|
+
const token = await Token.createToken(user);
|
|
421
|
+
|
|
422
|
+
const recordAnswers = new PatchMap() as PatchAnswers;
|
|
423
|
+
|
|
424
|
+
recordAnswers.set(commentsRecord.id, RecordTextAnswer.create({
|
|
425
|
+
settings: commentsRecord,
|
|
426
|
+
value: 'Some comments',
|
|
427
|
+
}));
|
|
428
|
+
|
|
429
|
+
const arr: Body = new PatchableArray();
|
|
430
|
+
const patch = MemberWithRegistrationsBlob.patch({
|
|
431
|
+
id: existingMember.id,
|
|
432
|
+
details: MemberDetails.patch({
|
|
433
|
+
recordAnswers,
|
|
434
|
+
}),
|
|
435
|
+
});
|
|
436
|
+
arr.addPatch(patch);
|
|
437
|
+
|
|
438
|
+
const request = Request.buildJson('PATCH', baseUrl, organization.getApiHost(), arr);
|
|
439
|
+
request.headers.authorization = 'Bearer ' + token.accessToken;
|
|
440
|
+
await expect(testServer.test(endpoint, request)).rejects.toThrow(errorWithCode('permission_denied'));
|
|
441
|
+
});
|
|
442
|
+
});
|
|
163
443
|
});
|
|
@@ -770,7 +770,7 @@ describe('Endpoint.RegisterMembers', () => {
|
|
|
770
770
|
administrationFee: 0,
|
|
771
771
|
freeContribution: 0,
|
|
772
772
|
paymentMethod: PaymentMethod.PointOfSale,
|
|
773
|
-
totalPrice:
|
|
773
|
+
totalPrice: 25,
|
|
774
774
|
asOrganizationId: organization.id,
|
|
775
775
|
});
|
|
776
776
|
|
|
@@ -1649,7 +1649,7 @@ describe('Endpoint.RegisterMembers', () => {
|
|
|
1649
1649
|
administrationFee: 0,
|
|
1650
1650
|
freeContribution: 0,
|
|
1651
1651
|
paymentMethod: PaymentMethod.PointOfSale,
|
|
1652
|
-
totalPrice:
|
|
1652
|
+
totalPrice: 30,
|
|
1653
1653
|
asOrganizationId: organization.id,
|
|
1654
1654
|
customer: null,
|
|
1655
1655
|
});
|
|
@@ -1927,7 +1927,7 @@ describe('Endpoint.RegisterMembers', () => {
|
|
|
1927
1927
|
administrationFee: 0,
|
|
1928
1928
|
freeContribution: 0,
|
|
1929
1929
|
paymentMethod: PaymentMethod.PointOfSale,
|
|
1930
|
-
totalPrice:
|
|
1930
|
+
totalPrice: 30,
|
|
1931
1931
|
asOrganizationId: organization1.id,
|
|
1932
1932
|
customer: null,
|
|
1933
1933
|
});
|
|
@@ -2049,7 +2049,7 @@ describe('Endpoint.RegisterMembers', () => {
|
|
|
2049
2049
|
administrationFee: 0,
|
|
2050
2050
|
freeContribution: 0,
|
|
2051
2051
|
paymentMethod: PaymentMethod.PointOfSale,
|
|
2052
|
-
totalPrice:
|
|
2052
|
+
totalPrice: 30,
|
|
2053
2053
|
asOrganizationId: organization.id,
|
|
2054
2054
|
customer: null,
|
|
2055
2055
|
});
|
|
@@ -2226,7 +2226,7 @@ describe('Endpoint.RegisterMembers', () => {
|
|
|
2226
2226
|
administrationFee: 0,
|
|
2227
2227
|
freeContribution: 0,
|
|
2228
2228
|
paymentMethod: PaymentMethod.PointOfSale,
|
|
2229
|
-
totalPrice:
|
|
2229
|
+
totalPrice: 30,
|
|
2230
2230
|
customer: null,
|
|
2231
2231
|
asOrganizationId: organization.id,
|
|
2232
2232
|
});
|
|
@@ -2331,7 +2331,7 @@ describe('Endpoint.RegisterMembers', () => {
|
|
|
2331
2331
|
administrationFee: 0,
|
|
2332
2332
|
freeContribution: 0,
|
|
2333
2333
|
paymentMethod: PaymentMethod.PointOfSale,
|
|
2334
|
-
totalPrice:
|
|
2334
|
+
totalPrice: 30,
|
|
2335
2335
|
customer: null,
|
|
2336
2336
|
asOrganizationId: organization.id,
|
|
2337
2337
|
});
|
|
@@ -2355,7 +2355,7 @@ describe('Endpoint.RegisterMembers', () => {
|
|
|
2355
2355
|
administrationFee: 0,
|
|
2356
2356
|
freeContribution: 0,
|
|
2357
2357
|
paymentMethod: PaymentMethod.PointOfSale,
|
|
2358
|
-
totalPrice:
|
|
2358
|
+
totalPrice: 30,
|
|
2359
2359
|
customer: null,
|
|
2360
2360
|
asOrganizationId: organization.id,
|
|
2361
2361
|
});
|