ConceptPortal-public/rsconcept/frontend/tests/mocks/auth.ts
Ivan 66fde1bd0e
Some checks failed
Frontend CI / build (22.x) (push) Waiting to run
Backend CI / build (3.12) (push) Has been cancelled
M: Setup testing mocks
2025-03-02 19:42:19 +03:00

45 lines
999 B
TypeScript

import { type Page } from '@playwright/test';
import { type ICurrentUser } from '@/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 });
});
}