test Scraping Service adding item to repo

This commit is contained in:
albert
2025-07-29 01:16:40 +02:00
parent b936697659
commit 580dae0c4d
2 changed files with 24 additions and 0 deletions

View File

@ -55,5 +55,24 @@ describe('ScrapingService', () => {
await expect(scrapingService.getFeedCount()).rejects.toThrow(errorMessage);
expect(mockFeedRepository.count).toHaveBeenCalled();
});
test('should save feed item to repository', async () => {
const feedData = {
title: 'Test News',
description: 'Test description',
url: 'https://example.com/news',
source: 'El País' as any,
publishedAt: new Date(),
isManual: false
};
const savedFeed = { _id: '1', ...feedData };
mockFeedRepository.create.mockResolvedValue(savedFeed);
const result = await scrapingService.saveFeedItem(feedData);
expect(mockFeedRepository.create).toHaveBeenCalledWith(feedData);
expect(result).toEqual(savedFeed);
});
});
});

View File

@ -1,4 +1,5 @@
import { IFeedRepository } from '../repositories/FeedRepository';
import { IFeed } from '../types/Feed';
export class ScrapingService {
constructor(private feedRepository: IFeedRepository) {}
@ -14,4 +15,8 @@ export class ScrapingService {
async getFeedCount(): Promise<number> {
return await this.feedRepository.count();
}
async saveFeedItem(feedData: Omit<IFeed, '_id' | 'createdAt' | 'updatedAt'>): Promise<IFeed> {
return await this.feedRepository.create(feedData);
}
}