Disable unavailable subreddits after Reddit 404
This commit is contained in:
1 parent
664aa5c098
commit
dcf57273e2
13 files changed
+153
-12
No files matched your search
+25
-1
@@ -1,6 +1,11 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { MonitorService } from '../src/services/monitor.js';
|
||||
import { RedditRateLimitError, type RedditApiClient, type RedditPost } from '../src/reddit/api.js';
|
||||
import {
|
||||
RedditRateLimitError,
|
||||
RedditSubredditUnavailableError,
|
||||
type RedditApiClient,
|
||||
type RedditPost,
|
||||
} from '../src/reddit/api.js';
|
||||
import type { PostsRepository, MessagesRepository } from '../src/database/repositories.js';
|
||||
import { createMockLogger } from '../tests/mockLogger.js';
|
||||
import { getTestConfig } from '../tests/testUtils.js';
|
||||
@@ -87,6 +92,25 @@ describe('MonitorService', () => {
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
|
||||
it('disables a subreddit when Reddit returns a terminal listing 404', async () => {
|
||||
const redditApi = createMockRedditApi();
|
||||
vi.mocked(redditApi.getNewPosts).mockRejectedValueOnce(new RedditSubredditUnavailableError('banned-sub'));
|
||||
const pollingControl = {
|
||||
disableUnavailableSubreddit: vi.fn(),
|
||||
isSubredditEnabled: vi.fn(() => true),
|
||||
};
|
||||
const config = getTestConfig({ reddit: { subreddits: [{ name: 'banned-sub', type: 'image' }] } });
|
||||
monitor = new MonitorService(
|
||||
redditApi, createMockPostsRepo(), createMockMessagesRepo(), config, logger, 0, pollingControl,
|
||||
);
|
||||
|
||||
await expect(monitor.getUnprocessedPosts()).resolves.toEqual([]);
|
||||
expect(pollingControl.disableUnavailableSubreddit).toHaveBeenCalledWith('banned-sub');
|
||||
expect(logger.logs).toContainEqual(expect.objectContaining({
|
||||
level: 'warn', message: expect.stringContaining('Disabled r/banned-sub: Reddit returned HTTP 404'),
|
||||
}));
|
||||
});
|
||||
|
||||
it('uses shared post history so another account cannot rediscover a post', async () => {
|
||||
const post: RedditPost = {
|
||||
id: 't3_shared', subreddit: 'sub1', author: 'user1', title: 'Post',
|
||||
|
||||
Reference in new issue
Block a user