Reduce Reddit profile screening requests
This commit is contained in:
1 parent
3d015c4e80
commit
1833e94a10
4 files changed
+97
-37
No files matched your search
@@ -152,6 +152,40 @@ describe('MonitorService', () => {
|
||||
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].id).toBe('t3_2');
|
||||
expect(redditApi.isSellerProfile).toHaveBeenCalledTimes(1);
|
||||
expect(redditApi.isSellerProfile).toHaveBeenCalledWith(
|
||||
'user2', config.reddit.sellerKeywords, config.reddit.sellerDomains, post2,
|
||||
);
|
||||
});
|
||||
|
||||
it('finishes the seller and gender checks for one candidate before moving to the next', async () => {
|
||||
const newer: RedditPost = {
|
||||
id: 't3_newer', subreddit: 'chat-sub', author: 'newer', title: '[30M] hello',
|
||||
url: '', permalink: '/r/chat-sub/newer', thumbnail: '', is_self: true,
|
||||
created_utc: 2, over_18: false, spoiler: false,
|
||||
};
|
||||
const eligible: RedditPost = {
|
||||
id: 't3_eligible', subreddit: 'chat-sub', author: 'eligible', title: '[25F] hello',
|
||||
url: '', permalink: '/r/chat-sub/eligible', thumbnail: '', is_self: true,
|
||||
created_utc: 1, over_18: false, spoiler: false,
|
||||
};
|
||||
const redditApi = createMockRedditApi([eligible, newer]);
|
||||
const config = getTestConfig({
|
||||
reddit: {
|
||||
subreddits: [{ name: 'chat-sub', type: 'chat' }],
|
||||
targetGenders: ['female'],
|
||||
},
|
||||
});
|
||||
const postsRepo = createMockPostsRepo();
|
||||
monitor = new MonitorService(
|
||||
redditApi, postsRepo, createMockMessagesRepo(), config, logger, 0,
|
||||
);
|
||||
|
||||
await expect(monitor.getUnprocessedPosts()).resolves.toEqual([eligible]);
|
||||
expect(vi.mocked(redditApi.isSellerProfile).mock.calls.map(([username]) => username))
|
||||
.toEqual(['newer', 'eligible']);
|
||||
expect(postsRepo.insert).toHaveBeenCalledWith(expect.objectContaining({ id: 't3_newer' }));
|
||||
expect(postsRepo.setError).toHaveBeenCalledWith('t3_newer', 'Gender tag "male" not targeted');
|
||||
});
|
||||
|
||||
it('tries next subreddit when first has no valid posts', async () => {
|
||||
|
||||
@@ -364,6 +364,18 @@ describe('RedditApiClient', () => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('propagates profile rate limits so the main loop backs off', async () => {
|
||||
const error = {
|
||||
isAxiosError: true,
|
||||
response: { status: 429, headers: { 'retry-after': '42' } },
|
||||
};
|
||||
vi.mocked(axios.create).mockReturnValue({ get: vi.fn().mockRejectedValue(error) } as any);
|
||||
|
||||
const client2 = new RedditApiClient(getTestConfig(), logger);
|
||||
await expect(client2.isSellerProfile('testuser', ['onlyfans']))
|
||||
.rejects.toMatchObject({ retryAfterMs: 42_000 });
|
||||
});
|
||||
|
||||
it('returns true when a domain in the bio matches sellerDomains', async () => {
|
||||
const mockResponse = {
|
||||
data: {
|
||||
|
||||
Reference in new issue
Block a user