Gate bot logic on full account authentication

This commit is contained in:
jjbrunton committed 2026-08-08 16:01:06 +01:00
1 parent 4db6de8bf5
commit 2fd92bf82c
22 files changed
+635 -65

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
import { describe, expect, it, vi } from 'vitest';
import os from 'node:os';
import path from 'node:path';
import { ChatService } from '../src/services/chat/service.js';
import { ChatCache } from '../src/services/chat/cache.js';
import { MatrixClient } from '../src/services/chat/matrix/client.js';
import { createMockLogger } from './mockLogger.js';
describe('ChatService account authentication gate', () => {
it('does not make Matrix requests before full account authentication', async () => {
const logger = createMockLogger();
const matrix = new MatrixClient({
homeserver: 'https://matrix.example.test',
accessToken: 'cached-but-unverified',
userId: '@t2_account:reddit.com',
capturedAt: 1,
}, logger, { minRequestIntervalMs: 0 });
matrix.sync = vi.fn();
const cache = new ChatCache(
logger,
path.join(os.tmpdir(), `chat-auth-${Date.now()}-${Math.random()}.json`),
);
const auth = { isFullyAuthenticated: vi.fn(() => false) };
const service = new ChatService(
matrix,
logger,
undefined,
undefined,
undefined,
undefined,
cache,
undefined,
undefined,
auth,
);
await service.refreshTopChats();
expect(matrix.sync).not.toHaveBeenCalled();
});
});