1 import metrics from '@proton/metrics'
2 import { MetricService } from './MetricService'
3 import type { Api } from '@proton/shared/lib/interfaces'
5 jest.mock('@proton/metrics')
7 describe('MetricService', () => {
8 let metricService: MetricService
11 const api = {} as unknown as Api
13 metricService = new MetricService(api)
21 metricService.destroy()
24 describe('initialize', () => {
25 it('should heartbeat once immediately', () => {
26 const spy = jest.spyOn(metricService, 'heartbeat')
28 metricService.initialize()
30 expect(spy).toHaveBeenCalled()
33 it('should heartbeat every 60 seconds', () => {
34 const spy = jest.spyOn(metricService, 'heartbeat')
36 metricService.initialize()
38 expect(spy).toHaveBeenCalledTimes(1)
40 jest.advanceTimersByTime(60_000)
42 expect(spy).toHaveBeenCalledTimes(2)
46 describe('heartbeat', () => {
47 it('should increment the docs_open_documents_heartbeat_total metric', () => {
48 metricService.heartbeat()
50 expect(metrics.docs_open_documents_heartbeat_total.increment).toHaveBeenCalled()