Improve seller account filtering

This commit is contained in:
jjbrunton committed 2026-08-08 19:15:05 +01:00
1 parent d819a0f1e6
commit f4e8fdc42f
5 files changed
+178 -52

No files matched your search

+25
View File
@@ -105,6 +105,31 @@ describe('MonitorService', () => {
expect(messagesRepo.hasSentTo).toHaveBeenCalledWith('already_msgd');
});
it('records seller posts as processed and continues to a clean candidate', async () => {
const sellerPost: RedditPost = {
id: 't3_seller', subreddit: 'sub1', author: 'seller', title: 'My page',
selftext: 'OnlyFans in bio', url: 'http://example.com/1.jpg', permalink: '/r/sub1/1', thumbnail: '',
is_self: false, created_utc: 2, over_18: true, spoiler: false,
};
const cleanPost: RedditPost = {
id: 't3_clean', subreddit: 'sub1', author: 'clean', title: 'Hello',
url: 'http://example.com/2.jpg', permalink: '/r/sub1/2', thumbnail: '',
is_self: false, created_utc: 1, over_18: true, spoiler: false,
};
const redditApi = createMockRedditApi([sellerPost, cleanPost]);
vi.mocked(redditApi.isSellerProfile).mockImplementation(async (username) => username === 'seller');
const postsRepo = createMockPostsRepo();
const config = getTestConfig({ reddit: { subreddits: [{ name: 'sub1', type: 'image' }] } });
monitor = new MonitorService(redditApi, postsRepo, createMockMessagesRepo(), config, logger, 0);
await expect(monitor.getUnprocessedPosts()).resolves.toEqual([cleanPost]);
expect(redditApi.isSellerProfile).toHaveBeenCalledWith(
'seller', config.reddit.sellerKeywords, config.reddit.sellerDomains, sellerPost,
);
expect(postsRepo.insert).toHaveBeenCalledWith(expect.objectContaining({ id: 't3_seller' }));
expect(postsRepo.setError).toHaveBeenCalledWith('t3_seller', 'Seller signals detected');
});
it('returns newest post when multiple valid posts exist', async () => {
const post1: RedditPost = {
id: 't3_1', subreddit: 'sub1', author: 'user1', title: 'Older',