Fix chat visibility and conversation sync
This commit is contained in:
1 parent
f4e8fdc42f
commit
34ae532cdd
10 files changed
+416
-23
No files matched your search
@@ -0,0 +1,67 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import type { RedditUsersRepository } from '../src/database/repositories.js';
|
||||
import { ChatCache } from '../src/services/chat/cache.js';
|
||||
import { ChatService } from '../src/services/chat/service.js';
|
||||
import { MatrixClient } from '../src/services/chat/matrix/client.js';
|
||||
import { createMockLogger } from './mockLogger.js';
|
||||
import { authenticatedAccountAuth } from './testUtils.js';
|
||||
|
||||
const creds = {
|
||||
homeserver: 'https://matrix.example.test',
|
||||
accessToken: 'tok',
|
||||
userId: '@t2_me:reddit.com',
|
||||
capturedAt: Date.now(),
|
||||
};
|
||||
|
||||
describe('ChatService direct-room repair', () => {
|
||||
it('repairs cached outbound rooms during delta sync', async () => {
|
||||
const logger = createMockLogger();
|
||||
const matrix = new MatrixClient(creds, logger, {
|
||||
minRequestIntervalMs: 0,
|
||||
fetchImpl: vi.fn(),
|
||||
});
|
||||
matrix.sync = vi.fn().mockResolvedValue({ next_batch: 'next', rooms: { join: {} } });
|
||||
matrix.repairDirectRoomMappings = vi.fn().mockResolvedValue(1);
|
||||
|
||||
const users = {
|
||||
getAll: () => [{ t2Id: 't2_alice', username: 'alice' }],
|
||||
getByUsername: () => ({ t2Id: 't2_alice', username: 'alice' }),
|
||||
upsert: vi.fn(),
|
||||
} as unknown as RedditUsersRepository;
|
||||
|
||||
const cache = new ChatCache(
|
||||
logger,
|
||||
path.join(os.tmpdir(), `chat-direct-repair-${Date.now()}-${Math.random()}.json`),
|
||||
);
|
||||
cache.set([{
|
||||
username: 'alice',
|
||||
roomName: 'alice',
|
||||
lastMessageTime: Date.now(),
|
||||
lastMessageSnippet: 'hello',
|
||||
isFromUs: true,
|
||||
unread: false,
|
||||
url: 'https://chat.reddit.com/room/room',
|
||||
roomId: '!room:reddit.com',
|
||||
messages: [],
|
||||
}]);
|
||||
|
||||
const service = new ChatService(
|
||||
matrix,
|
||||
logger,
|
||||
undefined, undefined, undefined, undefined,
|
||||
cache,
|
||||
undefined,
|
||||
users,
|
||||
authenticatedAccountAuth,
|
||||
);
|
||||
|
||||
await service.refreshTopChats();
|
||||
|
||||
expect(matrix.repairDirectRoomMappings).toHaveBeenCalledWith([{
|
||||
recipientMxid: '@t2_alice:reddit.com',
|
||||
roomId: '!room:reddit.com',
|
||||
}]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user