Skip to content

Commit 3c4bedd

Browse files
committed
add create users test
1 parent 56a5034 commit 3c4bedd

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

testing/e2e/src/global/global.setup.spec.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type { $LoginCredentials } from '@opendatacapture/schemas/auth';
22

3-
import { groups, initAppOptions } from '../helpers/data';
3+
import { groups, initAppOptions, users } from '../helpers/data';
44
import { expect, test } from '../helpers/fixtures';
55

6+
import type { TestDataMap } from '../helpers/types';
7+
68
test.describe.serial(() => {
79
test.describe.serial('setup', () => {
810
test('should initially not be setup', async ({ request }) => {
@@ -48,9 +50,26 @@ test.describe.serial(() => {
4850

4951
test.describe.serial('creating groups', () => {
5052
test('creating groups', async ({ request }) => {
51-
for (const key in groups) {
53+
const createdGroupIds = {} as TestDataMap<string>;
54+
for (const browser in groups) {
5255
const response = await request.post('/api/v1/groups', {
53-
data: groups[key as keyof typeof groups],
56+
data: groups[browser as keyof typeof groups],
57+
headers: {
58+
Authorization: `Bearer ${process.env.ADMIN_ACCESS_TOKEN}`
59+
}
60+
});
61+
expect(response.status()).toBe(201);
62+
const data = await response.json();
63+
expect(data).toMatchObject({ id: expect.any(String) });
64+
createdGroupIds[browser as keyof typeof groups] = data.id;
65+
}
66+
67+
for (const key in users) {
68+
const response = await request.post('/api/v1/users', {
69+
data: {
70+
...users[key as keyof typeof groups],
71+
groupIds: [createdGroupIds[key as keyof typeof users]]
72+
},
5473
headers: {
5574
Authorization: `Bearer ${process.env.ADMIN_ACCESS_TOKEN}`
5675
}

testing/e2e/src/helpers/data.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
import type { CreateGroupData } from '@opendatacapture/schemas/group';
12
import type { InitAppOptions } from '@opendatacapture/schemas/setup';
3+
import type { CreateUserData } from '@opendatacapture/schemas/user';
4+
5+
import type { TestDataMap } from './types';
26

37
export const initAppOptions = {
48
admin: {
@@ -12,3 +16,31 @@ export const initAppOptions = {
1216
initDemo: true,
1317
recordsPerSubject: 10
1418
} satisfies InitAppOptions;
19+
20+
export const groups: TestDataMap<CreateGroupData> = {
21+
'Desktop Chrome': {
22+
name: 'Clinical Group',
23+
type: 'CLINICAL'
24+
},
25+
'Desktop Firefox': {
26+
name: 'Research Group',
27+
type: 'RESEARCH'
28+
}
29+
};
30+
31+
export const users: TestDataMap<Omit<CreateUserData, 'groupIds'>> = {
32+
'Desktop Chrome': {
33+
basePermissionLevel: 'GROUP_MANAGER',
34+
firstName: 'John',
35+
lastName: 'Smith',
36+
password: 'DataCapture2026_User1',
37+
username: 'john_smith'
38+
},
39+
'Desktop Firefox': {
40+
basePermissionLevel: 'GROUP_MANAGER',
41+
firstName: 'Jane',
42+
lastName: 'Doe',
43+
password: 'DataCapture2026_User2',
44+
username: 'jane_doe'
45+
}
46+
};

0 commit comments

Comments
 (0)