42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
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();
|
|
});
|
|
});
|