ConceptPortal-public/rsconcept/frontend/tests/mocks/auth.ts
Ivan 1c904f965c
Some checks are pending
Frontend CI / build (22.x) (push) Waiting to run
R: Setup testing environment and mocks
2025-03-02 21:23:34 +03:00

44 lines
1006 B
TypeScript

import { type Page } from '@playwright/test';
import { type ICurrentUser } from '../../src/features/auth/backend/types';
import { BACKEND_URL } from '../constants';
const dataAnonymousAuth: ICurrentUser = {
id: null,
username: '',
is_staff: false,
editor: []
};
const dataAdminAuth: ICurrentUser = {
id: 1,
username: 'admin',
is_staff: true,
editor: []
};
const dataUserAuth: ICurrentUser = {
id: 2,
username: 'user',
is_staff: false,
editor: [2]
};
export async function authAnonymous(page: Page) {
await page.route(`${BACKEND_URL}/users/api/auth`, async route => {
await route.fulfill({ json: dataAnonymousAuth });
});
}
export async function authAdmin(page: Page) {
await page.route(`${BACKEND_URL}/users/api/auth`, async route => {
await route.fulfill({ json: dataAdminAuth });
});
}
export async function authUser(page: Page) {
await page.route(`${BACKEND_URL}/users/api/auth`, async route => {
await route.fulfill({ json: dataUserAuth });
});
}