Run immediate browsing sessions with enabled votes

This commit is contained in:
jjbrunton committed 2026-08-11 21:59:13 +01:00
1 parent 643c775813
commit 540590f43e
11 files changed
+40 -19

No files matched your search

+22 -4
View File
@@ -143,16 +143,34 @@ describe('AccountBrowsingSimulationService', () => {
]);
});
it('runs a requested simulation immediately without submitting a vote', async () => {
enable({ postWeight: 100, commentWeight: 0 });
const fixture = service();
it('runs a requested session immediately and follows the automatic-vote setting', async () => {
enable({ postWeight: 100, commentWeight: 0, autoVoteEnabled: true });
const voter = { upvote: vi.fn().mockResolvedValue({ status: 'submitted' }) };
const fixture = service({ voter });
const result = await fixture.instance.runNow();
expect(result).toMatchObject({
kind: 'simulated', decision: { thingFullname: 't3_one', voteSubmitted: false },
kind: 'simulated', decision: { thingFullname: 't3_one', voteSubmitted: true },
});
expect(fixture.getHotPosts).toHaveBeenCalledOnce();
expect(voter.upvote).toHaveBeenCalledWith('t3_one');
});
it('keeps an immediate session simulation-only in browser dry-run', async () => {
enable({ postWeight: 100, commentWeight: 0, autoVoteEnabled: true });
const voter = { upvote: vi.fn().mockResolvedValue({ status: 'submitted' }) };
const fixture = service({ voter });
fixture.instance = new AccountBrowsingSimulationService({
accountId: ACCOUNT, repository, growthSubreddits: () => [{ subreddit: 'AskUK', weight: 1 }] as never,
reddit: { getHotPosts: fixture.getHotPosts, getBrowsingComments: fixture.getBrowsingComments },
sink: repository, voter, logger: createMockLogger(), now: () => NOW, random: () => 0, dryRun: true,
});
await expect(fixture.instance.runNow()).resolves.toMatchObject({
kind: 'simulated', decision: { voteSubmitted: false },
});
expect(voter.upvote).not.toHaveBeenCalled();
});
it('honours comment weighting when eligible comments exist', async () => {