Browse Source

fix(news): repair regression test broken by merge conflict resolution

When PR #11080 (input-validation) was merged into this branch, the
"Accept Both" conflict resolution dropped the closing of the regression
test's mock fetch (lines around the boundary between the regression
test and the new size-limit test) and pasted that test's tail into the
"should skip when response body is not valid JSON" test. Repair both:

- Restore the regression test's `await service.executeJob()` and
  `expect(...deleteItemsNotInFeed).toHaveBeenCalledWith([...])` block.
- Switch the regression test's fetch mock to the post-input-validation
  `mockResponse(...)` helper so it exercises `response.text()` + zod.
- Trim the JSON-parse failure test back to its intended assertion.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Ryotaro Nagahara 2 weeks ago
parent
commit
d5a23e07c0
1 changed files with 15 additions and 12 deletions
  1. 15 12
      apps/app/src/features/news/server/services/news-cron-service.spec.ts

+ 15 - 12
apps/app/src/features/news/server/services/news-cron-service.spec.ts

@@ -261,9 +261,21 @@ describe('NewsCronService', () => {
           },
         ],
       };
-      mocks.mockFetch.mockResolvedValue({
-        ok: true,
-        json: () => Promise.resolve(feed),
+      mocks.mockFetch.mockResolvedValue(mockResponse(feed));
+
+      await service.executeJob();
+
+      // The argument is the *full* feed externalId list, not the
+      // version-matched subset. Items absent from this list (e.g. an
+      // earlier `removed-from-feed` item still in the DB) will be
+      // deleted by the service via `$nin`.
+      expect(mocks.deleteItemsNotInFeed).toHaveBeenCalledWith([
+        'still-present-1',
+        'still-present-2',
+        'version-filtered',
+      ]);
+    });
+
     test('should skip when response body exceeds size limit (5 MiB)', async () => {
       process.env.NEWS_FEED_URL = 'https://example.com/feed.json';
       // Build a string that exceeds 5 MiB
@@ -324,15 +336,6 @@ describe('NewsCronService', () => {
 
       await service.executeJob();
 
-      // The argument is the *full* feed externalId list, not the
-      // version-matched subset. Items absent from this list (e.g. an
-      // earlier `removed-from-feed` item still in the DB) will be
-      // deleted by the service via `$nin`.
-      expect(mocks.deleteItemsNotInFeed).toHaveBeenCalledWith([
-        'still-present-1',
-        'still-present-2',
-        'version-filtered',
-      ]);
       expect(mocks.upsertNewsItems).not.toHaveBeenCalled();
     });
   });