ConceptPortal-public/rsconcept/frontend/tests/mocks/auth.ts

45 lines
999 B
TypeScript
Raw Normal View History

2025-02-22 14:04:01 +03:00
import { type Page } from '@playwright/test';
2025-01-27 16:12:41 +03:00
2025-03-02 19:42:19 +03:00
import { type ICurrentUser } from '@/features/auth/backend/types';
2025-01-27 16:12:41 +03:00
import { BACKEND_URL } from '../constants';
2025-03-02 19:42:19 +03:00
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]
};
2025-01-27 16:12:41 +03:00
export async function authAnonymous(page: Page) {
await page.route(`${BACKEND_URL}/users/api/auth`, async route => {
2025-03-02 19:42:19 +03:00
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 });
2025-01-27 16:12:41 +03:00
});
}