feat: support concurrent Reddit accounts
This commit is contained in:
1 parent
d819a0f1e6
commit
16a31335d0
51 files changed
+3241
-250
No files matched your search
@@ -54,7 +54,10 @@ function detailFixture(chat = alice) {
|
||||
};
|
||||
}
|
||||
|
||||
const server = setupServer();
|
||||
const server = setupServer(http.get('/api/accounts', () => HttpResponse.json([{
|
||||
accountId: '@t2_bot:reddit.com', redditUsername: 'bot-account', matrixUserId: '@t2_bot:reddit.com',
|
||||
isRunning: true, status: 'authenticated', createdAt: 1, updatedAt: 2, lastImportedAt: 2,
|
||||
}])));
|
||||
|
||||
function installConversationList() {
|
||||
server.use(
|
||||
|
||||
@@ -19,7 +19,7 @@ const config = {
|
||||
advanced: { openrouter: { chatModel: 'example/chat-model' } },
|
||||
};
|
||||
|
||||
const server = setupServer();
|
||||
const server = setupServer(http.get('/api/accounts', () => HttpResponse.json([])));
|
||||
|
||||
function installConfigApi() {
|
||||
server.use(http.get('/api/config', () => HttpResponse.json(config)));
|
||||
@@ -277,13 +277,20 @@ describe('settings and access', () => {
|
||||
? { ready: true, loggedIn: false, status: 'login-required' }
|
||||
: { ready: true, loggedIn: true, status: 'authenticated', username: 'example-account' });
|
||||
}),
|
||||
http.get('/api/accounts', () => HttpResponse.json([{
|
||||
accountId: '@t2_bot:reddit.com', redditUsername: 'example-account', matrixUserId: '@t2_bot:reddit.com',
|
||||
isRunning: true, status: 'authenticated', createdAt: 1, updatedAt: 2, lastImportedAt: 2,
|
||||
}])),
|
||||
http.post('/api/login/session-import', async ({ request }) => {
|
||||
expect(request.credentials).toBe('same-origin');
|
||||
const body = await request.json() as { cookies: unknown[]; matrix: { accessToken: string } };
|
||||
expect(body.cookies).toHaveLength(1);
|
||||
expect(body.matrix.accessToken).toBe('matrix-secret');
|
||||
importRequests += 1;
|
||||
return HttpResponse.json({ ok: true, status: 'authenticated' });
|
||||
return HttpResponse.json({ ok: true, status: 'authenticated', account: {
|
||||
accountId: '@t2_bot:reddit.com', redditUsername: 'example-account', matrixUserId: '@t2_bot:reddit.com',
|
||||
isRunning: true, status: 'authenticated', createdAt: 1, updatedAt: 2, lastImportedAt: 2,
|
||||
} });
|
||||
}),
|
||||
);
|
||||
const user = userEvent.setup();
|
||||
@@ -306,13 +313,13 @@ describe('settings and access', () => {
|
||||
expect(await screen.findByText('Reddit session imported and verified.')).toBeInTheDocument();
|
||||
expect(importRequests).toBe(1);
|
||||
expect(await screen.findByText('Authenticated')).toBeInTheDocument();
|
||||
expect(screen.getByText(/u\/example-account/)).toBeInTheDocument();
|
||||
expect(screen.getByRole('link', { name: 'u/example-account' })).toHaveAttribute(
|
||||
expect(screen.getAllByText(/u\/example-account/)).toHaveLength(2);
|
||||
expect(screen.getAllByRole('link', { name: 'u/example-account' })[0]).toHaveAttribute(
|
||||
'href',
|
||||
'https://www.reddit.com/u/example-account',
|
||||
);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Recheck session' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Recheck accounts' }));
|
||||
expect(statusRequests).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user