103 lines
3.8 KiB
JavaScript
103 lines
3.8 KiB
JavaScript
require('dotenv').config();
|
||
const { MatchingService } = require('../dist/services/matchingService');
|
||
const { ProfileService } = require('../dist/services/profileService');
|
||
|
||
// Функция для создания тестовых пользователей
|
||
async function createTestUsers() {
|
||
const profileService = new ProfileService();
|
||
|
||
console.log('Создание тестовых пользователей...');
|
||
|
||
// Создаем мужской профиль
|
||
const maleUserId = await profileService.ensureUser('123456', {
|
||
username: 'test_male',
|
||
first_name: 'Иван',
|
||
last_name: 'Тестов'
|
||
});
|
||
|
||
await profileService.createProfile(maleUserId, {
|
||
name: 'Иван',
|
||
age: 30,
|
||
gender: 'male',
|
||
interestedIn: 'female',
|
||
bio: 'Тестовый мужской профиль',
|
||
photos: ['photo1.jpg'],
|
||
city: 'Москва',
|
||
searchPreferences: {
|
||
minAge: 18,
|
||
maxAge: 45,
|
||
maxDistance: 50
|
||
}
|
||
});
|
||
console.log(`Создан мужской профиль: userId=${maleUserId}, telegramId=123456`);
|
||
|
||
// Создаем женский профиль
|
||
const femaleUserId = await profileService.ensureUser('654321', {
|
||
username: 'test_female',
|
||
first_name: 'Анна',
|
||
last_name: 'Тестова'
|
||
});
|
||
|
||
await profileService.createProfile(femaleUserId, {
|
||
name: 'Анна',
|
||
age: 28,
|
||
gender: 'female',
|
||
interestedIn: 'male',
|
||
bio: 'Тестовый женский профиль',
|
||
photos: ['photo2.jpg'],
|
||
city: 'Москва',
|
||
searchPreferences: {
|
||
minAge: 25,
|
||
maxAge: 40,
|
||
maxDistance: 30
|
||
}
|
||
});
|
||
console.log(`Создан женский профиль: userId=${femaleUserId}, telegramId=654321`);
|
||
|
||
console.log('Тестовые пользователи созданы успешно');
|
||
}
|
||
|
||
// Функция для тестирования подбора анкет
|
||
async function testMatching() {
|
||
console.log('\n===== ТЕСТИРОВАНИЕ ПОДБОРА АНКЕТ =====');
|
||
|
||
const matchingService = new MatchingService();
|
||
|
||
console.log('\nТест 1: Получение анкеты для мужского профиля (должна вернуться женская анкета)');
|
||
const femaleProfile = await matchingService.getNextCandidate('123456', true);
|
||
if (femaleProfile) {
|
||
console.log(`✓ Получена анкета: ${femaleProfile.name}, возраст: ${femaleProfile.age}, пол: ${femaleProfile.gender}`);
|
||
} else {
|
||
console.log('✗ Анкета не найдена');
|
||
}
|
||
|
||
console.log('\nТест 2: Получение анкеты для женского профиля (должна вернуться мужская анкета)');
|
||
const maleProfile = await matchingService.getNextCandidate('654321', true);
|
||
if (maleProfile) {
|
||
console.log(`✓ Получена анкета: ${maleProfile.name}, возраст: ${maleProfile.age}, пол: ${maleProfile.gender}`);
|
||
} else {
|
||
console.log('✗ Анкета не найдена');
|
||
}
|
||
|
||
console.log('\n===== ТЕСТИРОВАНИЕ ЗАВЕРШЕНО =====\n');
|
||
|
||
// Завершение работы скрипта
|
||
process.exit(0);
|
||
}
|
||
|
||
// Главная функция
|
||
async function main() {
|
||
try {
|
||
// Создаем тестовых пользователей
|
||
await createTestUsers();
|
||
|
||
// Тестируем подбор анкет
|
||
await testMatching();
|
||
} catch (error) {
|
||
console.error('Ошибка при выполнении тестов:', error);
|
||
process.exit(1);
|
||
}
|
||
}
|
||
|
||
main();
|