Improve seller account filtering
This commit is contained in:
1 parent
d819a0f1e6
commit
f4e8fdc42f
5 files changed
+178
-52
No files matched your search
@@ -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',
|
||||
|
||||
@@ -242,6 +242,38 @@ describe('RedditApiClient', () => {
|
||||
});
|
||||
|
||||
describe('isSellerProfile', () => {
|
||||
it('returns true for a seller signal in the current post without fetching the profile', async () => {
|
||||
const get = vi.fn();
|
||||
vi.mocked(axios.create).mockReturnValue({ get } as any);
|
||||
const client2 = new RedditApiClient(getTestConfig(), logger);
|
||||
const post = {
|
||||
id: 'post-1', name: 't3_post-1', subreddit: 'test', author: 'testuser',
|
||||
title: 'Come and subscribe', selftext: 'My page is at https://onlyfans.com/example',
|
||||
url: 'https://reddit.com/post-1', permalink: '/r/test/post-1', thumbnail: '',
|
||||
is_self: true, created_utc: 1, over_18: true, spoiler: false,
|
||||
};
|
||||
|
||||
await expect(client2.isSellerProfile('testuser', ['onlyfans'], ['onlyfans.com'], post))
|
||||
.resolves.toBe(true);
|
||||
expect(get).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('detects seller signals in recent profile activity when the bio is clean', async () => {
|
||||
const get = vi.fn()
|
||||
.mockResolvedValueOnce({ data: { data: { subreddit: { public_description: 'Just me' } } } })
|
||||
.mockResolvedValueOnce({
|
||||
data: { data: { children: [{ data: { title: 'New content', subreddit: 'OnlyFansPromotions' } }] } },
|
||||
});
|
||||
vi.mocked(axios.create).mockReturnValue({ get } as any);
|
||||
const client2 = new RedditApiClient(getTestConfig(), logger);
|
||||
|
||||
await expect(client2.isSellerProfile('testuser', ['onlyfans'])).resolves.toBe(true);
|
||||
expect(get).toHaveBeenNthCalledWith(2, '/user/testuser/overview.json', {
|
||||
params: { limit: 25, raw_json: 1 },
|
||||
headers: {},
|
||||
});
|
||||
});
|
||||
|
||||
it('returns true when seller keyword matches', async () => {
|
||||
const mockResponse = {
|
||||
data: {
|
||||
|
||||
Reference in new issue
Block a user