feat: replace browser login with imported Reddit sessions
This commit is contained in:
1 parent
2b0545afcf
commit
c483c7b8be
76 files changed
+2048
-2828
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { BrowserContext } from 'playwright';
|
||||
import { BrowserClient, type BrowserRuntime } from '../src/browser/client.js';
|
||||
import type { Logger } from '../src/utils/logger.js';
|
||||
import { getTestConfig } from './testUtils.js';
|
||||
|
||||
function createLogger(): Logger {
|
||||
return { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() } as unknown as Logger;
|
||||
}
|
||||
|
||||
describe('BrowserClient', () => {
|
||||
it('launches only the managed headless Playwright context', async () => {
|
||||
const context = { pages: () => [] } as unknown as BrowserContext;
|
||||
const runtime: BrowserRuntime = { launchPersistentContext: vi.fn().mockResolvedValue(context) };
|
||||
const client = new BrowserClient(getTestConfig(), createLogger(), runtime);
|
||||
|
||||
await expect(client.initialize()).resolves.toBe(context);
|
||||
expect(runtime.launchPersistentContext).toHaveBeenCalledWith(
|
||||
expect.stringContaining('browser-session'),
|
||||
expect.objectContaining({ headless: true }),
|
||||
);
|
||||
});
|
||||
|
||||
it('adds an imported session without logging cookie values', async () => {
|
||||
const addCookies = vi.fn().mockResolvedValue(undefined);
|
||||
const context = { pages: () => [], addCookies } as unknown as BrowserContext;
|
||||
const runtime: BrowserRuntime = { launchPersistentContext: vi.fn().mockResolvedValue(context) };
|
||||
const logger = createLogger();
|
||||
const client = new BrowserClient(getTestConfig(), logger, runtime);
|
||||
const cookies = [{ name: 'reddit_session', value: 'secret', domain: '.reddit.com', path: '/', expires: -1, httpOnly: true, secure: true, sameSite: 'Lax' as const }];
|
||||
|
||||
await client.importRedditCookies(cookies);
|
||||
|
||||
expect(addCookies).toHaveBeenCalledWith(cookies);
|
||||
expect(client.getSessionState()).toBe('unknown');
|
||||
expect(JSON.stringify(logger)).not.toContain('secret');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user