testing if feed exists by URL

This commit is contained in:
albert
2025-07-29 01:17:56 +02:00
parent 580dae0c4d
commit f3fffa6f88
2 changed files with 25 additions and 0 deletions

View File

@ -74,5 +74,25 @@ describe('ScrapingService', () => {
expect(mockFeedRepository.create).toHaveBeenCalledWith(feedData);
expect(result).toEqual(savedFeed);
});
test('should check if feed exists by URL', async () => {
const testUrl = 'https://example.com/news';
const existingFeed = {
_id: '1',
title: 'Existing News',
description: 'Existing description',
url: testUrl,
source: 'El País' as any,
publishedAt: new Date(),
isManual: false
};
mockFeedRepository.findByUrl.mockResolvedValue(existingFeed);
const exists = await scrapingService.feedExists(testUrl);
expect(mockFeedRepository.findByUrl).toHaveBeenCalledWith(testUrl);
expect(exists).toBe(true);
});
});
});

View File

@ -19,4 +19,9 @@ export class ScrapingService {
async saveFeedItem(feedData: Omit<IFeed, '_id' | 'createdAt' | 'updatedAt'>): Promise<IFeed> {
return await this.feedRepository.create(feedData);
}
async feedExists(url: string): Promise<boolean> {
const existingFeed = await this.feedRepository.findByUrl(url);
return existingFeed !== null;
}
}