1 import { CommentController } from './CommentController'
2 import type { DocumentKeys, NodeMeta } from '@proton/drive-store'
3 import type { LoggerInterface } from '@proton/utils/logs'
4 import type { InternalEventBusInterface } from '@proton/docs-shared'
6 import type { PrivateKeyReference, SessionKey } from '@proton/crypto'
7 import type { WebsocketServiceInterface } from '../Websockets/WebsocketServiceInterface'
8 import type { DocsApi } from '../../Api/DocsApi'
9 import type { EncryptComment } from '../../UseCase/EncryptComment'
10 import type { CreateThread } from '../../UseCase/CreateThread'
11 import type { CreateComment } from '../../UseCase/CreateComment'
12 import type { LoadThreads } from '../../UseCase/LoadThreads'
13 import type { HandleRealtimeCommentsEvent } from '../../UseCase/HandleRealtimeCommentsEvent'
14 import { WebsocketConnectionEvent } from '../../Realtime/WebsocketEvent/WebsocketConnectionEvent'
15 import type { MetricService } from '../Metrics/MetricService'
16 import type { UnleashClient } from '@proton/unleash'
18 describe('CommentController', () => {
19 let controller: CommentController
21 let encryptComment: EncryptComment
22 let createThread: CreateThread
23 let createComment: CreateComment
24 let loadThreads: LoadThreads
26 let websocketService: WebsocketServiceInterface
27 let eventBus: InternalEventBusInterface
29 let logger: LoggerInterface
30 let document: NodeMeta
31 let keys: DocumentKeys
32 let handleRealtimeCommentsEvent: HandleRealtimeCommentsEvent
35 document = { linkId: 'link-id-123', volumeId: 'volume-id-456' } as NodeMeta
38 documentContentKey: 'key-123' as unknown as SessionKey,
39 userAddressPrivateKey: 'private-key-123' as unknown as PrivateKeyReference,
40 userOwnAddress: 'foo',
43 websocketService = {} as unknown as jest.Mocked<WebsocketServiceInterface>
45 api = {} as unknown as jest.Mocked<DocsApi>
48 addEventHandler: jest.fn(),
49 } as unknown as jest.Mocked<InternalEventBusInterface>
55 } as unknown as jest.Mocked<LoggerInterface>
59 } as unknown as jest.Mocked<EncryptComment>
63 } as unknown as jest.Mocked<CreateThread>
67 } as unknown as jest.Mocked<CreateComment>
71 } as unknown as jest.Mocked<LoadThreads>
73 handleRealtimeCommentsEvent = {
75 } as unknown as jest.Mocked<HandleRealtimeCommentsEvent>
77 const metricService = {} as unknown as jest.Mocked<MetricService>
79 const getLatestDocumentName = jest.fn()
81 const unleashClient = {
84 } as unknown as jest.Mocked<UnleashClient>
86 controller = new CommentController(
96 handleRealtimeCommentsEvent,
97 getLatestDocumentName,
104 it('should refetch all comments upon websocket reconnection', async () => {
105 controller.fetchAllComments = jest.fn()
107 await controller.handleEvent({
108 type: WebsocketConnectionEvent.ConnectionEstablishedButNotYetReady,
112 expect(controller.fetchAllComments).toHaveBeenCalled()