Добавлен UI тест для позитивной проверки восстановления пароля, также добавлена фильтрация писем для почтового сервиса

This commit is contained in:
Vlad Smykov
2026-01-30 15:25:19 +03:00
parent 257a53c97e
commit 5c40d43990
12 changed files with 127 additions and 27 deletions

View File

@@ -32,7 +32,8 @@ export async function createTempEmail() {
}
export async function waitForConfirmationCode(token: string, timeout = 60000) {
export async function waitForConfirmationCode(email: string, token: string, type: 'register' | 'recover', timeout = 60000) {
console.log('📧 Ожидаем код для:', email);
const start = Date.now();
while (Date.now() - start < timeout) {
@@ -42,33 +43,49 @@ export async function waitForConfirmationCode(token: string, timeout = 60000) {
const messages = res.data['hydra:member'];
// ✅ Логируем полученные письма
if (messages.length === 0) {
console.log('⏳ Письма пока не пришли...');
} else {
console.log(`📬 Получено ${messages.length} писем:`);
}
for (const message of messages) {
console.log('🔖 Тема письма:', message.subject);
const msg = await axios.get(`${MAIL_TM_BASE}/messages/${message.id}`, {
headers: { Authorization: `Bearer ${token}` },
});
const body = msg.data.text || msg.data.html;
console.log('📩 Тело письма:', body);
const match = body.match(/\b\d{6}\b/);
if (match) {
console.log('✅ Код подтверждения найден:', match[0]);
return match[0];
for (const m of messages) {
console.log(`🧾 Письмо: id=${m.id}, тема="${m.subject}"`);
}
}
await new Promise(res => setTimeout(res, 2000)); // Пауза 2 сек
for (const message of messages) {
console.log('🔖 Тема письма:', message.subject);
// 🔴 ФИЛЬТРАЦИЯ ЗДЕСЬ
if (
type === 'register' &&
!message.subject.toLowerCase().includes('подтверж')
) {
continue;
}
if (
type === 'recover' &&
!message.subject.toLowerCase().includes('сброс')
) {
continue;
}
// ⬇️ ТОЛЬКО НУЖНОЕ ПИСЬМО ДОХОДИТ СЮДА
const msg = await axios.get(`${MAIL_TM_BASE}/messages/${message.id}`, {
headers: { Authorization: `Bearer ${token}` },
});
const body = msg.data.text || msg.data.html;
const match = body.match(/\b\d{6}\b/);
if (match) {
console.log('✅ Код найден:', match[0]);
return match[0];
}
}
await new Promise(res => setTimeout(res, 2000));
}
throw new Error('Код подтверждения не получен');
}
}