Run immediate browsing sessions with enabled votes
This commit is contained in:
1 parent
643c775813
commit
540590f43e
11 files changed
+40
-19
No files matched your search
@@ -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 () => {
|
||||
|
||||
@@ -240,7 +240,7 @@ describe('GrowthPage', () => {
|
||||
await waitFor(() => expect(requests).toContainEqual(expect.objectContaining({
|
||||
method: 'PATCH', body: { enabled: true },
|
||||
})));
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: 'Simulate session now' })).toBeEnabled());
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: 'Run session now' })).toBeEnabled());
|
||||
expect(requests[0].url).toContain('/api/growth/%40t2_grower%3Areddit.com/browsing');
|
||||
await user.click(screen.getByLabelText('Submit selected upvotes'));
|
||||
await waitFor(() => expect(requests).toContainEqual(expect.objectContaining({
|
||||
@@ -248,7 +248,7 @@ describe('GrowthPage', () => {
|
||||
})));
|
||||
});
|
||||
|
||||
it('runs an enabled browsing simulation immediately', async () => {
|
||||
it('runs an enabled browsing session immediately', async () => {
|
||||
const currentBrowsing = browsing(true);
|
||||
detailPayload = detail({
|
||||
browsing: {
|
||||
@@ -259,7 +259,7 @@ describe('GrowthPage', () => {
|
||||
renderGrowth();
|
||||
const user = userEvent.setup();
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Simulate session now' }));
|
||||
await user.click(await screen.findByRole('button', { name: 'Run session now' }));
|
||||
|
||||
await waitFor(() => expect(requests).toContainEqual(expect.objectContaining({
|
||||
method: 'POST', body: null,
|
||||
|
||||
@@ -290,14 +290,14 @@ describe('growth route', () => {
|
||||
});
|
||||
|
||||
describe('POST /api/growth/:accountId/browsing/run', () => {
|
||||
it('runs one immediate simulation through the active account runtime', async () => {
|
||||
it('runs one immediate session through the active account runtime', async () => {
|
||||
const { status, json } = await call(app, 'POST', `/api/growth/${ENCODED}/browsing/run`);
|
||||
|
||||
expect(status).toBe(200);
|
||||
GrowthAccountResponseSchema.parse(json);
|
||||
expect(runNow).toHaveBeenCalledOnce();
|
||||
expect(pushed).toContainEqual({
|
||||
level: 'info', message: 'Browsing simulation run manually for u/grower; no Reddit vote was submitted',
|
||||
level: 'info', message: 'Browsing session run manually for u/grower',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user