import { Kysely, type DatabaseConnection } from 'kysely'; import { makeMockWarehouseDialect } from '../../test/stubs/makeMockWarehouseKyselyDialect.js'; import { makeMockPgDialect, type MockPgExecute, } from '../../test/stubs/KyselyPg.js'; import { type UserStatisticsServiceWarehouse } from './dbTypes.js'; import { type makeFetchUserActionStatistics } from './fetchUserActionStatistics.js'; import { type makeFetchUserSubmissionStatistics } from './fetchUserSubmissionStatistics.js'; import { internalMakeUserStatisticsService } from './userStatisticsService.js'; describe('UserStatisticsService', () => { describe('refreshUserScoresCache', () => { test.todo('should fetch stats w/ batching and update accordingly'); test('is a no-op without warehouse change streams', async () => { const warehouseMock = jest .fn() .mockImplementation(async (_query) => { return { rows: [] }; }); const pgReadMock = jest .fn() .mockResolvedValue({ rows: [], command: 'SELECT', rowCount: 0 }); const pgWriteMock = jest .fn() .mockResolvedValue({ rows: [], command: 'SELECT', rowCount: 0 }); const fetchUserActionStatisticsMock = jest .fn>() .mockResolvedValue([]); const fetchUserSubmissionStatisticsMock = jest .fn>() .mockResolvedValue([]); const warehouseKysely = new Kysely({ dialect: makeMockWarehouseDialect(warehouseMock), }); const sut = internalMakeUserStatisticsService( new Kysely({ dialect: makeMockPgDialect(pgWriteMock) }), new Kysely({ dialect: makeMockPgDialect(pgReadMock) }), warehouseKysely, fetchUserActionStatisticsMock, fetchUserSubmissionStatisticsMock, ); await sut.refreshUserScoresCache(async () => []); expect(pgWriteMock).not.toHaveBeenCalled(); expect(warehouseMock).not.toHaveBeenCalled(); expect(fetchUserActionStatisticsMock).not.toHaveBeenCalled(); expect(fetchUserSubmissionStatisticsMock).not.toHaveBeenCalled(); }); }); });