feat: persist settings and enrich conversation context
This commit is contained in:
1 parent
a36723a325
commit
2c100d72b6
84 files changed
+2248
-644
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { BrowserContext } from 'playwright';
|
||||
import type { BrowserContext, Page } from 'playwright';
|
||||
import { BrowserClient, type BrowserRuntime } from '../src/browser/client.js';
|
||||
import type { Logger } from '../src/utils/logger.js';
|
||||
import { getTestConfig } from './testUtils.js';
|
||||
@@ -35,4 +35,25 @@ describe('BrowserClient', () => {
|
||||
expect(client.getSessionState()).toBe('unknown');
|
||||
expect(JSON.stringify(logger)).not.toContain('secret');
|
||||
});
|
||||
|
||||
it('reads the username from Reddit\'s nested me.json account response', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ kind: 't2', data: { name: 'bot-account' } }),
|
||||
});
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
const page = {
|
||||
evaluate: async (pageFunction: () => Promise<string | null>) => pageFunction(),
|
||||
} as unknown as Page;
|
||||
const context = { pages: () => [page] } as unknown as BrowserContext;
|
||||
const runtime: BrowserRuntime = { launchPersistentContext: vi.fn().mockResolvedValue(context) };
|
||||
const client = new BrowserClient(getTestConfig(), createLogger(), runtime);
|
||||
|
||||
await expect(client.getAuthenticatedUsername()).resolves.toBe('bot-account');
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
'https://www.reddit.com/api/me.json',
|
||||
{ credentials: 'include' },
|
||||
);
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user