2023-09-18 15:05:17 +02:00
|
|
|
import { createTestConfig } from '../../../test/config/test-config';
|
2023-01-12 11:26:59 +01:00
|
|
|
import { InstanceStatsService } from './instance-stats-service';
|
2023-09-18 15:05:17 +02:00
|
|
|
import createStores from '../../../test/fixtures/store';
|
|
|
|
import VersionService from '../../services/version-service';
|
|
|
|
import { createFakeGetActiveUsers } from './getActiveUsers';
|
2023-01-12 11:26:59 +01:00
|
|
|
|
|
|
|
let instanceStatsService: InstanceStatsService;
|
|
|
|
let versionService: VersionService;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const config = createTestConfig();
|
|
|
|
const stores = createStores();
|
|
|
|
versionService = new VersionService(stores, config);
|
|
|
|
instanceStatsService = new InstanceStatsService(
|
|
|
|
stores,
|
|
|
|
config,
|
|
|
|
versionService,
|
2023-09-18 15:05:17 +02:00
|
|
|
createFakeGetActiveUsers(),
|
2023-01-12 11:26:59 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
jest.spyOn(instanceStatsService, 'refreshStatsSnapshot');
|
|
|
|
jest.spyOn(instanceStatsService, 'getStats');
|
|
|
|
|
|
|
|
// validate initial state without calls to these methods
|
|
|
|
expect(instanceStatsService.refreshStatsSnapshot).toBeCalledTimes(0);
|
|
|
|
expect(instanceStatsService.getStats).toBeCalledTimes(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('get snapshot should not call getStats', async () => {
|
|
|
|
await instanceStatsService.refreshStatsSnapshot();
|
|
|
|
expect(instanceStatsService.getStats).toBeCalledTimes(1);
|
|
|
|
|
|
|
|
// subsequent calls to getStatsSnapshot don't call getStats
|
|
|
|
for (let i = 0; i < 3; i++) {
|
|
|
|
const stats = instanceStatsService.getStatsSnapshot();
|
2023-08-30 14:51:46 +02:00
|
|
|
expect(stats?.clientApps).toStrictEqual([
|
2023-01-12 11:26:59 +01:00
|
|
|
{ range: 'allTime', count: 0 },
|
|
|
|
{ range: '30d', count: 0 },
|
|
|
|
{ range: '7d', count: 0 },
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// after querying the stats snapshot no call to getStats should be issued
|
|
|
|
expect(instanceStatsService.getStats).toBeCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('before the snapshot is refreshed we can still get the appCount', async () => {
|
|
|
|
expect(instanceStatsService.refreshStatsSnapshot).toBeCalledTimes(0);
|
|
|
|
expect(instanceStatsService.getAppCountSnapshot('7d')).toBeUndefined();
|
|
|
|
});
|