Archived
1
0

feat: добавил тесты скрейптинга медиа

This commit is contained in:
Egor Mikheev
2025-11-25 07:16:40 +03:00
parent bebea4e374
commit ee5cd575bf

View File

@ -0,0 +1,88 @@
// apps/backend/src/tests/e2e/scraper.test.ts
// Path: apps/backend/src/tests/e2e/scraper.test.ts
import { describe, expect, test, beforeAll } from 'bun:test';
describe('E2E: Scraper Integration', () => {
let authCookie: string;
beforeAll(async () => {
const signUpResponse = await fetch('http://localhost:3000/auth/api/sign-up/email', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name: 'Scraper Test User',
email: `scraper-test-${Date.now()}@example.com`,
password: 'TestPassword123!',
}),
});
authCookie = signUpResponse.headers.get('set-cookie') || '';
});
test('should save from direct image URL', async () => {
const response = await fetch('http://localhost:3000/saves/external', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Cookie': authCookie,
},
body: JSON.stringify({
url: 'https://mrqiz.ru/',
name: 'Direct Image Test',
visibility: 'public',
}),
});
expect(response.status).toBe(200);
const data = await response.json();
expect(data.type).toBe('image');
expect(data.name).toBe('Direct Image Test');
});
// Эти тесты требуют реальных URL
test.skip('should save from Pinterest URL (manual test)', async () => {
// Замените на актуальный Pinterest URL
const pinterestUrl = 'https://www.pinterest.com/pin/ACTUAL_PIN_ID/';
const response = await fetch('http://localhost:3000/saves/external', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Cookie': authCookie,
},
body: JSON.stringify({
url: pinterestUrl,
visibility: 'link',
}),
});
expect(response.status).toBe(200);
const data = await response.json();
expect(['image', 'video', 'gif']).toContain(data.type);
});
test.skip('should save from Tenor GIF (manual test)', async () => {
// Замените на актуальный Tenor URL
const tenorUrl = 'https://tenor.com/view/ACTUAL_GIF_ID';
const response = await fetch('http://localhost:3000/saves/external', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Cookie': authCookie,
},
body: JSON.stringify({
url: tenorUrl,
visibility: 'link',
}),
});
expect(response.status).toBe(200);
const data = await response.json();
expect(data.type).toBe('gif');
});
});