Добавлен позитивный API тест для проверки восстановления пароля
This commit is contained in:
42
tests/api/auth/recover-password.api.spec.ts
Normal file
42
tests/api/auth/recover-password.api.spec.ts
Normal 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);
|
||||
});
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user