Repository navigation
Expand file tree
/
Copy pathbasic.test.ts
More file actions
53 lines (40 loc) · 1.79 KB
/
Copy pathbasic.test.ts
File metadata and controls
53 lines (40 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { expect, test } from '@playwright/test';
import { appConfigs } from '../../presets';
import type { FakeUser } from '../../testUtils';
import { createTestUtils, testAgainstRunningApps } from '../../testUtils';
testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('basic tests for @express', ({ app }) => {
test.describe.configure({ mode: 'parallel' });
let fakeUser: FakeUser;
test.beforeAll(async () => {
const u = createTestUtils({ app });
fakeUser = u.services.users.createFakeUser(test);
await u.services.users.createBapiUser(fakeUser);
});
test.afterAll(async () => {
await fakeUser.deleteIfExists();
await app.teardown();
});
test('authenticates protected routes when user is signed in using getAuth()', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.page.goToRelative('/');
await u.po.signIn.waitForMounted();
await u.po.signIn.setIdentifier(fakeUser.email);
await u.po.signIn.continue();
await u.po.signIn.setPassword(fakeUser.password);
await u.po.signIn.continue();
await u.po.userButton.waitForMounted();
const url = new URL('/api/protected', app.serverUrl);
const res = await u.page.request.get(url.toString());
expect(res.status()).toBe(200);
expect(await res.text()).toBe('Protected API response');
});
test('rejects protected routes when user is not authenticated using getAuth()', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.page.goToRelative('/');
await u.po.signIn.waitForMounted();
const url = new URL('/api/protected', app.serverUrl);
const res = await u.page.request.get(url.toString());
expect(res.status()).toBe(401);
expect(await res.text()).toBe('Unauthorized');
});
});