Files
supermarket/experiments/magnit-detail-endpoints/test-all-detail-endpoints.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

85 lines
2.7 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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('=== Тестирование всех endpoints для деталей товара ===\n');
// Получаем cookies
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 || '';
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',
},
});
await browser.close();
const endpoints = [
{
name: '🔍 user-reviews-and-object-info (ДЕТАЛИ ТОВАРА)',
url: '/webgate/v1/listing/user-reviews-and-object-info?service=dostavka&objectType=product&objectId=1000530495',
},
{
name: '🏷️ promotions/type',
url: '/webgate/v1/promotions/type?adult=true&type=19&limit=10&storeCode=996609',
},
{
name: '🏪 goods/{id}/stores/{storeCode}',
url: '/webgate/v2/goods/1000530495/stores/996609?storetype=2&catalogtype=1',
},
];
for (const { name, url } of endpoints) {
try {
Logger.info(`\n${name}`);
Logger.info(`URL: ${url}`);
const response = await httpClient.get(url);
Logger.info(`✅ Status: ${response.status}`);
const data = response.data;
const json = JSON.stringify(data, null, 2);
// Показываем только ключевые поля
if (json.length < 2000) {
Logger.info(`Response:\n${json}`);
} else {
Logger.info(`Response (превью):`);
console.log(json.substring(0, 800) + '...');
}
// Проверяем наличие ключевых полей
const hasDetails = data.brand || data.description || data.weight || data.unit ||
data.objectInfo?.brand || data.objectInfo?.description ||
data.product?.brand || data.product?.description;
if (hasDetails) {
Logger.info(`\n⭐ НАЙДЕНЫ ДЕТАЛИ ТОВАРА! ⭐️⭐️`);
}
} catch (error: any) {
Logger.info(`❌ Error: ${error.response?.status || error.message}`);
}
}
}
main();