diff --git a/src/__tests__/ScrapingService.test.ts b/src/__tests__/ScrapingService.test.ts index ac91c67..12ca3be 100644 --- a/src/__tests__/ScrapingService.test.ts +++ b/src/__tests__/ScrapingService.test.ts @@ -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); + }); }); }); \ No newline at end of file diff --git a/src/services/ScrapingService.ts b/src/services/ScrapingService.ts index a0e7c25..0424e58 100644 --- a/src/services/ScrapingService.ts +++ b/src/services/ScrapingService.ts @@ -19,4 +19,9 @@ export class ScrapingService { async saveFeedItem(feedData: Omit): Promise { return await this.feedRepository.create(feedData); } + + async feedExists(url: string): Promise { + const existingFeed = await this.feedRepository.findByUrl(url); + return existingFeed !== null; + } } \ No newline at end of file