refactor: reorganize scripts - move debug code to experiments/
- Move debug/test scripts from src/scripts/ to experiments/ - Remove test-detail-endpoint from package.json - Delete temp-product-page.html - Move E2E_GUIDE.md to docs/ - Add experiments/README.md with documentation - Keep only production scripts in src/scripts/ - Clean up tsconfig.json exclude list (experiments are now outside src/) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
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();
|
||||
Reference in New Issue
Block a user