M: Setup testing mocks
Some checks failed
Frontend CI / build (22.x) (push) Waiting to run
Backend CI / build (3.12) (push) Has been cancelled

This commit is contained in:
Ivan 2025-03-02 19:42:19 +03:00
parent 32f83c4122
commit 66fde1bd0e
7 changed files with 121 additions and 16 deletions

View File

@ -77,18 +77,6 @@ class AuthSerializer(serializers.Serializer):
}
class UserInfoSerializer(serializers.ModelSerializer):
''' Serializer: User data. '''
class Meta:
''' serializer metadata. '''
model = models.User
fields = [
'id',
'first_name',
'last_name',
]
class UserSerializer(serializers.ModelSerializer):
''' Serializer: User data. '''
id = serializers.IntegerField(read_only=True)

View File

@ -20,7 +20,7 @@ export default [
ecmaVersion: 'latest',
sourceType: 'module',
globals: { ...globals.browser, ...globals.es2020, ...globals.jest },
project: ['./tsconfig.json', './tsconfig.node.json'],
project: ['./tsconfig.json', './tsconfig.vite.json', './tsconfig.test.json'],
projectService: true
}
}

View File

@ -1,9 +1,44 @@
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: { id: null } });
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 });
});
}

View File

@ -0,0 +1,73 @@
import { type Page } from '@playwright/test';
import {
type IUpdateProfileDTO,
type IUserInfo,
type IUserProfile,
type IUserSignupDTO
} from '@/features/users/backend/types';
import { BACKEND_URL } from '../constants';
const dataActiveUsers: IUserInfo[] = [
{
id: 1,
first_name: 'Admin',
last_name: 'User'
},
{
id: 2,
first_name: 'User',
last_name: 'User'
}
];
let dataUserProfile: IUserProfile = {
id: 1,
username: 'user',
email: 'user@example.com',
first_name: 'User',
last_name: 'User'
};
export async function setupUsers(page: Page) {
await page.route(`${BACKEND_URL}/users/api/active-users`, async route => {
await route.fulfill({ json: dataActiveUsers });
});
}
export async function setupUserProfile(page: Page) {
await page.route(`${BACKEND_URL}/users/api/profile`, async route => {
await route.fulfill({ json: dataUserProfile });
});
}
export async function setupUserSignup(page: Page) {
await page.route(`${BACKEND_URL}/users/api/signup`, async route => {
const data = route.request().postDataJSON() as IUserSignupDTO;
const newID = dataActiveUsers.length + 1;
dataActiveUsers.push({
id: newID,
first_name: data.first_name,
last_name: data.last_name
});
dataUserProfile = {
id: newID,
username: data.username,
email: data.email,
first_name: data.first_name,
last_name: data.last_name
};
await route.fulfill({ json: dataUserProfile });
});
}
export async function setupUserProfileUpdate(page: Page) {
await page.route(`${BACKEND_URL}/users/api/profile`, async route => {
dataUserProfile = {
...dataUserProfile,
...(route.request().postDataJSON() as IUpdateProfileDTO)
};
await route.fulfill({ json: dataUserProfile });
});
}

View File

@ -28,5 +28,5 @@
},
"types": ["vite/client"],
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
"references": [{ "path": "./tsconfig.vite.json" }]
}

View File

@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"types": ["playwright/test"],
"isolatedModules": false
},
"include": ["tests"]
}

View File

@ -11,5 +11,5 @@
"@/*": ["*"]
}
},
"include": ["vite.config.ts", "package.json", "playwright.config.ts", "tests", "src"]
"include": ["vite.config.ts", "package.json", "playwright.config.ts"]
}