test to return null when saving existing feed

This commit is contained in:
albert
2025-07-29 01:21:59 +02:00
parent 5ed38dcc98
commit 1c86ba9dc3

View File

@ -115,5 +115,25 @@ describe('ScrapingService', () => {
expect(mockFeedRepository.create).toHaveBeenCalledWith(feedData);
expect(result).toEqual(savedFeed);
});
test('should return null when trying to save existing feed', async () => {
const feedData = {
title: 'Existing News',
description: 'Existing description',
url: 'https://example.com/existing-news',
source: 'El País' as any,
publishedAt: new Date(),
isManual: false
};
const existingFeed = { _id: '1', ...feedData };
mockFeedRepository.findByUrl.mockResolvedValue(existingFeed);
const result = await scrapingService.saveIfNotExists(feedData);
expect(mockFeedRepository.findByUrl).toHaveBeenCalledWith(feedData.url);
expect(mockFeedRepository.create).not.toHaveBeenCalled();
expect(result).toBeNull();
});
});
});