This commit is contained in:
77
e2e/api/app-questionnaires.spec.ts
Normal file
77
e2e/api/app-questionnaires.spec.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
|
||||
|
||||
const API = '/api';
|
||||
|
||||
const PASSWORD = 'testpass123';
|
||||
|
||||
|
||||
|
||||
async function login(request: import('@playwright/test').APIRequestContext, username: string) {
|
||||
|
||||
const res = await request.post(`${API}/auth/login`, {
|
||||
|
||||
data: { username, password: PASSWORD },
|
||||
|
||||
});
|
||||
|
||||
const json = await res.json();
|
||||
|
||||
expect(json.ok).toBe(true);
|
||||
|
||||
return json.data.token as string;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
test.describe('Android API – app_questionnaires (HTTP smoke)', () => {
|
||||
|
||||
test('list active questionnaires over HTTP', async ({ request }) => {
|
||||
|
||||
const token = await login(request, 'testcoach1');
|
||||
|
||||
const res = await request.get(`${API}/app_questionnaires`, {
|
||||
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
|
||||
});
|
||||
|
||||
expect(res.ok()).toBeTruthy();
|
||||
|
||||
const json = await res.json();
|
||||
|
||||
expect(json.ok).toBe(true);
|
||||
|
||||
expect(json.data.some((q: { id: string }) => q.id === 'questionnaire_test_demo')).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
test('missing bearer returns 401', async ({ request }) => {
|
||||
|
||||
const res = await request.get(`${API}/app_questionnaires`);
|
||||
|
||||
expect(res.status()).toBe(401);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
test('password change flow', async ({ request }) => {
|
||||
|
||||
const loginRes = await request.post(`${API}/auth/login`, {
|
||||
|
||||
data: { username: 'testmustchange', password: PASSWORD },
|
||||
|
||||
});
|
||||
|
||||
const loginJson = await loginRes.json();
|
||||
|
||||
expect(loginJson.data.mustChangePassword).toBe(true);
|
||||
|
||||
const tempToken = loginJson.data.token as string;
|
||||
|
||||
let fullToken: string | undefined;
|
||||
25
e2e/api/auth.spec.ts
Normal file
25
e2e/api/auth.spec.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
const API = '/api';
|
||||
|
||||
test.describe('Android API – auth', () => {
|
||||
test('login returns token', async ({ request }) => {
|
||||
const res = await request.post(`${API}/auth/login`, {
|
||||
data: { username: 'testadmin', password: 'testpass123' },
|
||||
});
|
||||
expect(res.ok()).toBeTruthy();
|
||||
const json = await res.json();
|
||||
expect(json.ok).toBe(true);
|
||||
expect(json.data.token).toBeTruthy();
|
||||
expect(json.data.role).toBe('admin');
|
||||
});
|
||||
|
||||
test('bad password returns error', async ({ request }) => {
|
||||
const res = await request.post(`${API}/auth/login`, {
|
||||
data: { username: 'testadmin', password: 'wrong' },
|
||||
});
|
||||
expect(res.status()).toBe(401);
|
||||
const json = await res.json();
|
||||
expect(json.ok).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user