Skip to content

Commit b47eace

Browse files
committed
refactor(tom-server): fixes uid only test for user info service
Signed-off-by: Pierre 'McFly' Marty <[email protected]>
1 parent abf465d commit b47eace

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

packages/tom-server/src/user-info-api/tests/service.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,37 @@ describe('user info service', () => {
314314

315315
it('returns null when only uid is present in the result', async () => {
316316
;(matrixDBMock.get as jest.Mock).mockResolvedValueOnce([{}])
317-
;(userDb.db.get as jest.Mock).mockResolvedValueOnce([])
317+
318+
const getSpy = jest.spyOn(userDb.db as any, 'get').mockResolvedValueOnce([])
319+
318320
const user = await service.get('@dwho:docker.localhost')
319321
expect(user).toBeNull()
322+
323+
getSpy.mockRestore()
324+
})
325+
326+
it('passes the exact matrix id to the usersettings query', async () => {
327+
// Create a service instance with the common‑settings feature turned ON
328+
const cfg = {
329+
...config,
330+
features: { common_settings: { enabled: true } }
331+
} as unknown as Config
332+
333+
const svc = new UserInfoService(
334+
userDb,
335+
twakeDBMock as unknown as TwakeDB,
336+
matrixDBMock as unknown as MatrixDB,
337+
cfg,
338+
logger
339+
)
340+
341+
// spy on the DB mock (twakeDBMock.get is already a jest.fn)
342+
const spy = jest.spyOn(twakeDBMock, 'get')
343+
await svc.get('@dwho:docker.localhost')
344+
expect(spy).toHaveBeenCalledWith('usersettings', ['*'], {
345+
matrix_id: '@dwho:docker.localhost'
346+
})
347+
spy.mockRestore()
320348
})
321349

322350
it('re‑throws a wrapped error when an internal query fails', async () => {

0 commit comments

Comments
 (0)