Skip to content

Commit

Permalink
test: ts-ignore in private method mocks
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <gentilester@gmail.com>
  • Loading branch information
genaris committed Nov 24, 2022
1 parent 15133b1 commit 55d9a23
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
9 changes: 9 additions & 0 deletions packages/core/src/agent/__tests__/MessageSender.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import type { ConnectionRecord } from '../../modules/connections'
import type { ResolvedDidCommService } from '../../modules/didcomm'
import type { DidDocumentService } from '../../modules/dids'
Expand Down Expand Up @@ -365,10 +366,12 @@ describe('MessageSender', () => {
test('call send message on session when there is a session for a given connection', async () => {
messageSender.registerOutboundTransport(outboundTransport)
const sendMessageSpy = jest.spyOn(outboundTransport, 'sendMessage')
//@ts-ignore
const sendToServiceSpy = jest.spyOn(messageSender, 'sendToService')

await messageSender.sendMessage(outboundMessageContext)

//@ts-ignore
const [[sendMessage]] = sendToServiceSpy.mock.calls

expect(eventListenerMock).toHaveBeenCalledWith({
Expand All @@ -394,9 +397,12 @@ describe('MessageSender', () => {
},
})

//@ts-ignore
expect(sendMessage.serviceParams.senderKey.publicKeyBase58).toEqual(
'EoGusetSxDJktp493VCyh981nUnzMamTRjvBaHZAy68d'
)

//@ts-ignore
expect(sendMessage.serviceParams.service.recipientKeys.map((key) => key.publicKeyBase58)).toEqual([
'EoGusetSxDJktp493VCyh981nUnzMamTRjvBaHZAy68d',
])
Expand Down Expand Up @@ -427,6 +433,7 @@ describe('MessageSender', () => {
},
})

//@ts-ignore
const [, [sendMessage]] = sendToServiceSpy.mock.calls

expect(sendMessage).toMatchObject({
Expand All @@ -443,9 +450,11 @@ describe('MessageSender', () => {
},
})

//@ts-ignore
expect(sendMessage.serviceParams.senderKey.publicKeyBase58).toEqual(
'EoGusetSxDJktp493VCyh981nUnzMamTRjvBaHZAy68d'
)
//@ts-ignore
expect(sendMessage.serviceParams.service.recipientKeys.map((key) => key.publicKeyBase58)).toEqual([
'EoGusetSxDJktp493VCyh981nUnzMamTRjvBaHZAy68d',
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('V2MessagePickupService', () => {
messageCount: 0,
})
)
expect(messageRepository.getAvailableMessageCount).toHaveBeenCalledWith(connection.id)
expect(messageRepository.getAvailableMessageCount).toHaveBeenCalledWith(mockConnection.id)
})

test('multiple messages in queue', async () => {
Expand All @@ -89,7 +89,7 @@ describe('V2MessagePickupService', () => {
messageCount: 5,
})
)
expect(messageRepository.getAvailableMessageCount).toHaveBeenCalledWith(connection.id)
expect(messageRepository.getAvailableMessageCount).toHaveBeenCalledWith(mockConnection.id)
})

test('status request specifying recipient key', async () => {
Expand Down Expand Up @@ -125,7 +125,7 @@ describe('V2MessagePickupService', () => {
messageCount: 0,
})
)
expect(messageRepository.takeFromQueue).toHaveBeenCalledWith(connection.id, 10, true)
expect(messageRepository.takeFromQueue).toHaveBeenCalledWith(mockConnection.id, 10, true)
})

test('less messages in queue than limit', async () => {
Expand All @@ -152,7 +152,7 @@ describe('V2MessagePickupService', () => {
)
)
)
expect(messageRepository.takeFromQueue).toHaveBeenCalledWith(connection.id, 10, true)
expect(messageRepository.takeFromQueue).toHaveBeenCalledWith(mockConnection.id, 10, true)
})

test('more messages in queue than limit', async () => {
Expand All @@ -179,7 +179,7 @@ describe('V2MessagePickupService', () => {
)
)
)
expect(messageRepository.takeFromQueue).toHaveBeenCalledWith(connection.id, 2, true)
expect(messageRepository.takeFromQueue).toHaveBeenCalledWith(mockConnection.id, 2, true)
})

test('delivery request specifying recipient key', async () => {
Expand Down Expand Up @@ -219,8 +219,8 @@ describe('V2MessagePickupService', () => {
messageCount: 4,
})
)
expect(messageRepository.getAvailableMessageCount).toHaveBeenCalledWith(connection.id)
expect(messageRepository.takeFromQueue).toHaveBeenCalledWith(connection.id, 2)
expect(messageRepository.getAvailableMessageCount).toHaveBeenCalledWith(mockConnection.id)
expect(messageRepository.takeFromQueue).toHaveBeenCalledWith(mockConnection.id, 2)
})

test('all messages have been received', async () => {
Expand All @@ -244,8 +244,8 @@ describe('V2MessagePickupService', () => {
})
)

expect(messageRepository.getAvailableMessageCount).toHaveBeenCalledWith(connection.id)
expect(messageRepository.takeFromQueue).toHaveBeenCalledWith(connection.id, 2)
expect(messageRepository.getAvailableMessageCount).toHaveBeenCalledWith(mockConnection.id)
expect(messageRepository.takeFromQueue).toHaveBeenCalledWith(mockConnection.id, 2)
})
})
})

0 comments on commit 55d9a23

Please sign in to comment.