Files
supermarket/experiments/magnit-detail-endpoints/test-object-reviews-endpoint.ts
Mc Smog b8f170d83b fix: update import paths in debug scripts after reorganization
- Fix relative imports in experiments/ scripts (../ → ../../)
- Clean up tsconfig.json exclude list (remove non-existent paths)
- All debug scripts now work from their new location

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-22 02:02:52 +05:00

56 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dotenv/config';
import { chromium } from 'playwright';
import axios from 'axios';
import { Logger } from '../../utils/logger.js';
async function main() {
Logger.info('=== Тестирование API endpoint для деталей товара ===\n');
// Получаем cookies через Playwright
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://magnit.ru/', { waitUntil: 'domcontentloaded' });
const cookies = await context.cookies();
const cookieStr = cookies.map(c => `${c.name}=${c.value}`).join('; ');
const mgUdiCookie = cookies.find(c => c.name === 'mg_udi');
const deviceId = mgUdiCookie?.value || '';
await browser.close();
// Создаем HTTP клиент
const httpClient = axios.create({
baseURL: 'https://magnit.ru',
headers: {
'Content-Type': 'application/json',
'Accept': '*/*',
'Cookie': cookieStr,
'x-device-id': deviceId,
'x-client-name': 'magnit',
'x-device-platform': 'Web',
'x-new-magnit': 'true',
},
});
// Пробуем endpoint который нашел пользователь
const endpoint = '/webgate/v1/listing/object-reviews?service=dostavka&objectId=1000530495&objectType=product&page=0&size=10';
try {
Logger.info(`Запрос: ${endpoint}`);
const response = await httpClient.get(endpoint);
Logger.info(`✅ Status: ${response.status}`);
Logger.info(`\n=== ОТВЕТ API ===`);
console.log(JSON.stringify(response.data, null, 2));
} catch (error: any) {
Logger.error(`Ошибка: ${error.message}`);
if (error.response) {
Logger.error(`Status: ${error.response.status}`);
Logger.error(`Data:`, error.response.data);
}
}
}
main();