Добавлен позитивный API тест для проверки восстановления пароля

This commit is contained in:
Vlad Smykov
2026-02-04 14:58:02 +03:00
parent 5c40d43990
commit 96394f726b
11 changed files with 56 additions and 14 deletions

View File

@@ -15,7 +15,7 @@
"keywords": [],
"author": "Vlad Smykov",
"license": "ISC",
"type": "commonjs",
"type": "module",
"devDependencies": {
"@playwright/test": "^1.57.0",
"@types/node": "^25.1.0",

View File

@@ -14,7 +14,7 @@ export default defineConfig({
use: {
headless: false,
launchOptions: {
slowMo: 900,
slowMo: 300,
},
viewport: { width: 1280, height: 720 },
ignoreHTTPSErrors: true,

View File

@@ -1 +1 @@
{"email":"testuser1769775617223@virgilian.com","password":"!Test123456","mailToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE3Njk3NzU2MTgsInJvbGVzIjpbIlJPTEVfVVNFUiJdLCJhZGRyZXNzIjoidGVzdHVzZXIxNzY5Nzc1NjE3MjIzQHZpcmdpbGlhbi5jb20iLCJpZCI6IjY5N2NhMjAxM2ExZjhmNWE1MDA3MTEyNSIsIm1lcmN1cmUiOnsic3Vic2NyaWJlIjpbIi9hY2NvdW50cy82OTdjYTIwMTNhMWY4ZjVhNTAwNzExMjUiXX19.t8gDCA6xtLYnAex_f3OYj5aYJgls4g8IQs2K37gc6HiqdaKkZveB1ckB31_hhYJag23Ekdi6RW9CNm0RCLsDDQ"}
{"email":"testuser1770028019439@virgilian.com","password":"!Test123456","mailToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE3NzAwMjgwMjAsInJvbGVzIjpbIlJPTEVfVVNFUiJdLCJhZGRyZXNzIjoidGVzdHVzZXIxNzcwMDI4MDE5NDM5QHZpcmdpbGlhbi5jb20iLCJpZCI6IjY5ODA3YmY0NmFiNTlkMDJiMzBhMzNhOCIsIm1lcmN1cmUiOnsic3Vic2NyaWJlIjpbIi9hY2NvdW50cy82OTgwN2JmNDZhYjU5ZDAyYjMwYTMzYTgiXX19.xWXF4bN07584CE0AGiuUfH7XpNLNKFRp7DnLQbbf1jhzRHPgQuHaqh39_lShcFSl5GU1Hxqdk41s9yJMBFkuYw"}

View File

@@ -0,0 +1,42 @@
import { test, expect } from '@playwright/test';
import axios from 'axios';
import fs from 'fs';
const BASE_URL = 'https://rumc.dev.rdcenter.ru/api';
const NEW_PASSWORD = '!Test123456';
const user = JSON.parse(fs.readFileSync('temp/user.json', 'utf-8'));
test('API: восстановление пароля', async () => {
const email = user.email;
const sendResetRes = await axios.post(`${BASE_URL}/auth/resetPassword?type=reset`, {
email,
});
expect(sendResetRes.status).toBe(201);
console.log('📬 Письмо с кодом отправлено');
const { waitForConfirmationCode } = await import('../../../utils/mailTmApi');
const code = await waitForConfirmationCode(email, user.mailToken, 'recover', 60000);
expect(code).toMatch(/^\d{6}$/);
console.log('✅ Код подтверждения:', code);
const confirmRes = await axios.post(`${BASE_URL}/auth/confirmReset`, {
email,
code
});
expect(confirmRes.status).toBe(201);
const resetTokenRaw = confirmRes.data.resetTokenRaw;
console.log('🔑 Получен resetToken:', resetTokenRaw);
const recoveryRes = await axios.post(`${BASE_URL}/auth/recovery`, {
email,
resetToken: resetTokenRaw,
passwordReset: NEW_PASSWORD
});
expect(recoveryRes.status).toBe(201);
const accessToken = recoveryRes.data.access_token;
console.log('🪪 Новый access_token:', accessToken);
});

View File

@@ -16,6 +16,7 @@ import {
const BASE_URL = 'https://rumc.dev.rdcenter.ru/api';
test('API: регистрация абитуриента + подтверждение почты', async () => {
await new Promise(r => setTimeout(r, 3000));
const { email, token: mailToken } = await createTempEmail();
const surname = generateLastName();

View File

@@ -15,6 +15,7 @@ import {
const BASE_URL = 'https://rumc.dev.rdcenter.ru/api';
test('API: регистрация выпускника + подтверждение почты', async () => {
await new Promise(r => setTimeout(r, 3000));
const { email, token: mailToken } = await createTempEmail();
const surname = generateLastName();

View File

@@ -19,6 +19,7 @@ import {
const BASE_URL = 'https://rumc.dev.rdcenter.ru/api';
test('API: регистрация организации + подтверждение почты', async () => {
await new Promise(r => setTimeout(r, 3000));
const { email, token: mailToken } = await createTempEmail();
const surname = generateLastName();

View File

@@ -6,39 +6,33 @@ import {
} from '../../../utils/mailTmApi';
test('UI: восстановление пароля', async ({ page }) => {
// Загружаем email пользователя из файла temp/user.json
const loginPage = new LoginPage(page);
const user = JSON.parse(fs.readFileSync('temp/user.json', 'utf-8'));
const newPassword = '!Test12345678';
// Переход на главную
await loginPage.goto();
// Нажимаем "Забыли пароль?"
await page.getByText('Забыли пароль?').click();
await expect(page).toHaveURL(/.*confirmation-code/);
// Вводим почту
await page.fill('input[name="email"]', user.email);
await page.getByRole('button', { name: 'Далее' }).click();
// Получаем код из почты
const code = await waitForConfirmationCode(user.email, user.mailToken, 'recover');
expect(code).toMatch(/^\d{6}$/);
console.log('✅ Код получен:', code);
// Вводим код
await page.fill('input[name="code"]', code);
await page.getByRole('button', { name: 'Далее' }).click();
// Вводим новый пароль
await page.fill('input[name="password"]', newPassword);
await page.fill('input[name="passwordRepeat"]', newPassword);
await page.getByRole('button', { name: 'Далее' }).click();
// Проверяем успешную авторизацию
await expect(page).toHaveURL(/.*\/account\/profile/);
// (необязательно) обновляем сохранённый пароль
//user.password = newPassword;
//fs.writeFileSync('temp/user.json', JSON.stringify(user));
});

View File

@@ -20,6 +20,7 @@ import {
} from '../../../utils/mailTmApi';
test('Полная регистрация абитуриента с подтверждением почты', async ({ page }) => {
await new Promise(r => setTimeout(r, 3000));
const registerPage = new RegisterPage(page);
const { email, token } = await createTempEmail();

View File

@@ -10,6 +10,7 @@ import {
import { createTempEmail, waitForConfirmationCode } from '../../../utils/mailTmApi';
test('Полная регистрация выпускника с подтверждением почты', async ({ page }) => {
await new Promise(r => setTimeout(r, 3000));
// Создаём временный email
const { email, token } = await createTempEmail();

View File

@@ -24,6 +24,7 @@ import {
} from '../../../utils/mailTmApi';
test('Полная регистрация организации с подтверждением почты', async ({ page }) => {
await new Promise(r => setTimeout(r, 3000));
const registerPage = new RegisterPage(page);
const { email, token } = await createTempEmail();