The DailyNews backend ships with a suite of automated tests written with Jest and SuperTest. The tests are split into four files that collectively cover the full request lifecycle — from HTTP routing through the service layer down to individual scraper parsers. No real network calls or database connections are made during testing: the MongoDB layer and theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/miikorz/DailyNews/llms.txt
Use this file to discover all available pages before exploring further.
fetch API are fully mocked, so the suite runs entirely in-process and offline.
Test Structure
feedController.test.ts
Integration tests that mount the real Express
app and fire HTTP requests via SuperTest. Mocks FeedService entirely so no database or scraping logic runs.FeedService.test.ts
Unit tests for every public method on
FeedService. Both FeedRepositoryInterface and ScrapperService are replaced with jest.fn() mocks.ElPaisScrapperRepository.test.ts
Unit tests for the El País scraper.
global.fetch is replaced with a Jest mock that returns hand-crafted HTML fixtures to verify CSS selector targeting.ElMundoScrapperRepository.test.ts
Unit tests for the El Mundo scraper. Same fetch-mocking pattern, with a dedicated fixture for articles missing a
href to verify that link-less entries are skipped.Running Tests
Jest Configuration
The project usests-jest so TypeScript source is compiled on-the-fly without a separate build step. Tests are discovered by matching **/tests/**/*.test.ts — i.e., any .test.ts file inside a tests/ directory anywhere in the tree.
Unit Test Example
TheFeedService.test.ts file demonstrates the standard mocking pattern used across the test suite. FeedRepositoryInterface is mocked with jest.fn() on every method, and ScrapperService is module-mocked at the top level so that ScrapperService.prototype.getTopNews can be controlled per-test.
Integration Test Example
feedController.test.ts uses SuperTest to send real HTTP requests against the Express app instance. FeedService is mocked at the module level so the tests exercise routing, request parsing, and response formatting without touching the database or network.
Coverage
The four test files collectively verify the following:feedController.test.ts — HTTP routing and response shapes
feedController.test.ts — HTTP routing and response shapes
GET /feedreturns200with{ data: Feed[], error: null }GET /feed/:idreturns200with the matched feed, or404whengetFeedByIdreturnsnullPOST /feedreturns200with the created feed, or400whentitleorlinkis missing from the bodyPUT /feed/:idreturns200with the updated feed, or404whenupdateFeedreturnsnullDELETE /feed/:idreturns204on success, or404whendeleteFeedreturnsnull- Any unregistered route returns
404
FeedService.test.ts — service orchestration
FeedService.test.ts — service orchestration
getAllFeedscallsScrapperService.getTopNews, passes the results tosaveScrappedFeeds, and then callsfindAllcreateFeedcallsfeedRepository.createwith the correct payloadgetFeedByIddelegates tofindByIdand propagatesnullwhen the feed does not existupdateFeeddelegates torepository.updateand propagatesnullfor missing IDsdeleteFeeddelegates torepository.deleteand propagatesnullfor missing IDs
ElPaisScrapperRepository.test.ts — scraper parsing
ElPaisScrapperRepository.test.ts — scraper parsing
getTopNewscorrectly extractstitle,description,author,link,portrait, andnewsletterfrom a mock HTML page containing<article>elements with El País’s CSS class structure- Returns an empty array when the HTML contains no
<article>elements
ElMundoScrapperRepository.test.ts — scraper parsing
ElMundoScrapperRepository.test.ts — scraper parsing
getTopNewscorrectly extracts all fields from El Mundo’s CSS class structure (ue-c-cover-content__byline-name,ue-c-cover-content__footer,ue-c-cover-content__image)- Skips articles where
header a[href]is empty, returning an empty array for a page containing only link-less articles