feat: replace browser login with imported Reddit sessions

This commit is contained in:
jjbrunton committed 2026-08-08 16:48:59 +01:00
1 parent 2b0545afcf
commit c483c7b8be
76 files changed
+2048 -2828

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
import { describe, expect, it, vi } from 'vitest';
import { currentHourlySendCount, startNonOverlappingSchedule } from '../src/main-loop.js';
describe('startNonOverlappingSchedule', () => {
it('does not begin a second response check until the prior check settles', async () => {
vi.useFakeTimers();
let finishFirst: (() => void) | undefined;
const check = vi
.fn<() => Promise<void>>()
.mockImplementationOnce(() => new Promise<void>((resolve) => { finishFirst = resolve; }))
.mockResolvedValue(undefined);
const schedule = startNonOverlappingSchedule(check, 1_000);
expect(check).toHaveBeenCalledTimes(1);
await vi.advanceTimersByTimeAsync(10_000);
expect(check).toHaveBeenCalledTimes(1);
finishFirst?.();
await Promise.resolve();
await vi.advanceTimersByTimeAsync(1_000);
expect(check).toHaveBeenCalledTimes(2);
schedule.stop();
vi.useRealTimers();
});
it('does not schedule another check after stop', async () => {
vi.useFakeTimers();
const check = vi.fn<() => Promise<void>>().mockResolvedValue(undefined);
const schedule = startNonOverlappingSchedule(check, 1_000);
await Promise.resolve();
schedule.stop();
await vi.advanceTimersByTimeAsync(10_000);
expect(check).toHaveBeenCalledTimes(1);
vi.useRealTimers();
});
});
describe('currentHourlySendCount', () => {
it('uses the post-send limiter count without adding an extra message', () => {
expect(currentHourlySendCount({ getStats: () => ({ messagesThisHour: 1 }) })).toBe(1);
});
});