|
1 | 1 | import type { $LoginCredentials } from '@opendatacapture/schemas/auth'; |
2 | 2 |
|
3 | | -import { initAppOptions } from '../helpers/data'; |
| 3 | +import { groups, initAppOptions, users } from '../helpers/data'; |
4 | 4 | import { expect, test } from '../helpers/fixtures'; |
5 | 5 |
|
| 6 | +import type { TestDataMap } from '../helpers/types'; |
| 7 | + |
6 | 8 | test.describe.serial(() => { |
7 | 9 | test.describe.serial('setup', () => { |
8 | 10 | test('should initially not be setup', async ({ request }) => { |
9 | 11 | const response = await request.get('/api/v1/setup'); |
10 | 12 | expect(response.status()).toBe(200); |
11 | 13 | await expect(response.json()).resolves.toMatchObject({ isSetup: false }); |
12 | 14 | }); |
13 | | - test('should successfully setup', async ({ setupPage }) => { |
| 15 | + test('should successfully setup', async ({ getPageModel }) => { |
| 16 | + const setupPage = getPageModel('/setup'); |
| 17 | + await setupPage.goto('/setup'); |
14 | 18 | await setupPage.fillSetupForm(initAppOptions); |
15 | 19 | await setupPage.expect.toHaveURL('/auth/login'); |
16 | 20 | }); |
@@ -44,4 +48,35 @@ test.describe.serial(() => { |
44 | 48 | process.env.ADMIN_PASSWORD = password; |
45 | 49 | }); |
46 | 50 | }); |
| 51 | + |
| 52 | + test.describe.serial('creating groups', () => { |
| 53 | + test('creating groups', async ({ request }) => { |
| 54 | + const createdGroupIds = {} as TestDataMap<string>; |
| 55 | + for (const browser in groups) { |
| 56 | + const response = await request.post('/api/v1/groups', { |
| 57 | + data: groups[browser as keyof typeof groups], |
| 58 | + headers: { |
| 59 | + Authorization: `Bearer ${process.env.ADMIN_ACCESS_TOKEN}` |
| 60 | + } |
| 61 | + }); |
| 62 | + expect(response.status()).toBe(201); |
| 63 | + const data = await response.json(); |
| 64 | + expect(data).toMatchObject({ id: expect.any(String) }); |
| 65 | + createdGroupIds[browser as keyof typeof groups] = data.id; |
| 66 | + } |
| 67 | + |
| 68 | + for (const key in users) { |
| 69 | + const response = await request.post('/api/v1/users', { |
| 70 | + data: { |
| 71 | + ...users[key as keyof typeof groups], |
| 72 | + groupIds: [createdGroupIds[key as keyof typeof users]] |
| 73 | + }, |
| 74 | + headers: { |
| 75 | + Authorization: `Bearer ${process.env.ADMIN_ACCESS_TOKEN}` |
| 76 | + } |
| 77 | + }); |
| 78 | + expect(response.status()).toBe(201); |
| 79 | + } |
| 80 | + }); |
| 81 | + }); |
47 | 82 | }); |
0 commit comments