feat: добавил тесты скрейптинга медиа
This commit is contained in:
88
apps/backend/src/tests/e2e/scraper.test.ts
Normal file
88
apps/backend/src/tests/e2e/scraper.test.ts
Normal 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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user