init: базовая структура АТ
This commit is contained in:
74
utils/mailTmApi.ts
Normal file
74
utils/mailTmApi.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
// utils/mailTmApi.ts
|
||||
|
||||
import axios from 'axios';
|
||||
|
||||
const MAIL_TM_BASE = 'https://api.mail.tm';
|
||||
|
||||
export async function createTempEmail() {
|
||||
const timestamp = Date.now();
|
||||
|
||||
// Получаем доступный домен
|
||||
const domainRes = await axios.get(`${MAIL_TM_BASE}/domains`);
|
||||
const domain = domainRes.data['hydra:member'][0].domain;
|
||||
|
||||
const email = `testuser${timestamp}@${domain}`;
|
||||
const password = 'QwEr!1234567';
|
||||
|
||||
// Регистрируем
|
||||
await axios.post(`${MAIL_TM_BASE}/accounts`, {
|
||||
address: email,
|
||||
password,
|
||||
});
|
||||
|
||||
// Авторизуемся
|
||||
const tokenRes = await axios.post(`${MAIL_TM_BASE}/token`, {
|
||||
address: email,
|
||||
password,
|
||||
});
|
||||
|
||||
const token = tokenRes.data.token;
|
||||
|
||||
return { email, password, token };
|
||||
}
|
||||
|
||||
|
||||
export async function waitForConfirmationCode(token: string, timeout = 60000) {
|
||||
const start = Date.now();
|
||||
|
||||
while (Date.now() - start < timeout) {
|
||||
const res = await axios.get(`${MAIL_TM_BASE}/messages`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
await new Promise(res => setTimeout(res, 2000)); // Пауза 2 сек
|
||||
}
|
||||
|
||||
throw new Error('Код подтверждения не получен');
|
||||
}
|
||||
|
||||
45
utils/userGenerator.ts
Normal file
45
utils/userGenerator.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
// utils/userGenerator.ts
|
||||
|
||||
// Список русских имён, фамилий, отчеств
|
||||
const firstNames = ['Алексей', 'Игорь', 'Иван', 'Владислав', 'Дмитрий', 'Константин', 'Сергей', 'Всеволод'];
|
||||
const lastNames = ['Иванов', 'Петров', 'Сидоров', 'Кузнецов', 'Смирнов', 'Попов', 'Фёдоров'];
|
||||
const middleNames = ['Алексеевич', 'Иванович', 'Дмитриевич', 'Андреевич', 'Сергеевич', 'Олегович'];
|
||||
|
||||
function getRandomFromArray(array: string[]): string {
|
||||
return array[Math.floor(Math.random() * array.length)];
|
||||
}
|
||||
|
||||
export function generateFirstName(): string {
|
||||
return getRandomFromArray(firstNames);
|
||||
}
|
||||
|
||||
export function generateLastName(): string {
|
||||
return getRandomFromArray(lastNames);
|
||||
}
|
||||
|
||||
export function generateMiddleName(): string {
|
||||
return getRandomFromArray(middleNames);
|
||||
}
|
||||
|
||||
export function generateRandomString(length: number): string {
|
||||
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
let result = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += chars[Math.floor(Math.random() * chars.length)];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function generateEmail(): string {
|
||||
const timestamp = Date.now();
|
||||
return `test_user_${timestamp}@mail.tm`;
|
||||
}
|
||||
|
||||
export function generateLogin(): string {
|
||||
return `user_${generateRandomString(6)}`;
|
||||
}
|
||||
|
||||
export function generatePhone(): string {
|
||||
const random = Math.floor(100000000 + Math.random() * 900000000); // 9 цифр
|
||||
return `+790${random}`; // +79012345678
|
||||
}
|
||||
Reference in New Issue
Block a user