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
@@ -70,6 +70,73 @@ describe('ChatService username persistence', () => {
|
||||
expect(svc.resolveSenderDisplay('@t2_unknown:reddit.com')).toBe('t2_unknown');
|
||||
});
|
||||
|
||||
it('starts a conversation with the t2 ID supplied by the Reddit listing', async () => {
|
||||
const logger = createMockLogger();
|
||||
const matrix = buildMatrix();
|
||||
matrix.sendInitialDirectMessage = vi.fn().mockResolvedValue({
|
||||
roomId: '!room:reddit.com',
|
||||
eventId: '$event',
|
||||
});
|
||||
const usernameResolver = {
|
||||
resolveT2Ids: vi.fn().mockResolvedValue({}),
|
||||
resolveUsernameToT2: vi.fn().mockRejectedValue(new Error('profile lookup returned 403')),
|
||||
};
|
||||
const svc = new ChatService(
|
||||
matrix,
|
||||
logger,
|
||||
undefined, undefined, undefined, usernameResolver,
|
||||
tmpCache(logger),
|
||||
undefined,
|
||||
undefined,
|
||||
authenticatedAccountAuth,
|
||||
);
|
||||
|
||||
const chat = await svc.startConversation('alice', 'hello', 't2_abc123');
|
||||
|
||||
expect(chat?.username).toBe('alice');
|
||||
expect(usernameResolver.resolveUsernameToT2).not.toHaveBeenCalled();
|
||||
expect(matrix.sendInitialDirectMessage).toHaveBeenCalledWith(
|
||||
'@t2_abc123:reddit.com',
|
||||
'hello',
|
||||
);
|
||||
});
|
||||
|
||||
it('uses the durable username mapping before a live profile lookup', async () => {
|
||||
const db = new Database(':memory:');
|
||||
runMigrations(db);
|
||||
const repo = new RedditUsersRepository(db);
|
||||
repo.upsert({ t2Id: 't2_cached', username: 'alice' });
|
||||
const logger = createMockLogger();
|
||||
const matrix = buildMatrix();
|
||||
matrix.sendInitialDirectMessage = vi.fn().mockResolvedValue({
|
||||
roomId: '!room:reddit.com',
|
||||
eventId: '$event',
|
||||
});
|
||||
const usernameResolver = {
|
||||
resolveT2Ids: vi.fn().mockResolvedValue({}),
|
||||
resolveUsernameToT2: vi.fn().mockRejectedValue(new Error('profile lookup returned 403')),
|
||||
};
|
||||
const svc = new ChatService(
|
||||
matrix,
|
||||
logger,
|
||||
undefined, undefined, undefined, usernameResolver,
|
||||
tmpCache(logger),
|
||||
undefined,
|
||||
repo,
|
||||
authenticatedAccountAuth,
|
||||
);
|
||||
|
||||
const chat = await svc.startConversation('ALICE', 'hello');
|
||||
|
||||
expect(chat?.username).toBe('ALICE');
|
||||
expect(usernameResolver.resolveUsernameToT2).not.toHaveBeenCalled();
|
||||
expect(matrix.sendInitialDirectMessage).toHaveBeenCalledWith(
|
||||
'@t2_cached:reddit.com',
|
||||
'hello',
|
||||
);
|
||||
db.close();
|
||||
});
|
||||
|
||||
it('upgrades cached chats with t2_ usernames from the db map on loadCache', async () => {
|
||||
const db = new Database(':memory:');
|
||||
runMigrations(db);
|
||||
|
||||
Reference in new issue
Block a user