Skip to content

Commit 2138296

Browse files
committed
added getConversationByAddressPair test
1 parent ba2beca commit 2138296

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/utils/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./addParticipant.util";
22
export * from "./createConversation.util";
33
export * from "./deleteConversation.util";
4-
export * from "./listParticipantConversations.util"
4+
export * from "./listParticipantConversations.util";
5+
export * from "./getConversationByAddressPair.util";
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { getConversationByAddressPair } from "../../src/utils";
2+
import client from '../../src/twilioClient';
3+
import { ParticipantConversationInstance } from 'twilio/lib/rest/conversations/v1/participantConversation';
4+
5+
jest.mock('../../src/twilioClient')
6+
let mockedClient = jest.mocked(client, true)
7+
8+
describe('GetConversationByAddressPair util', () => {
9+
beforeEach(() => {
10+
jest.resetAllMocks()
11+
})
12+
13+
it('it gets Conversation by address pair', async () => {
14+
const mockParticipants = [{
15+
conversationState: "closed",
16+
conversationSid: "myConversationSid",
17+
participantMessagingBinding: {
18+
proxy_address: "+5678"
19+
}
20+
}]
21+
22+
const createSpy = jest.fn((options) => { return mockParticipants })
23+
mockedClient['conversations'] = {
24+
v1:{
25+
participantConversations: {
26+
list: (options) => createSpy(options)
27+
}
28+
}
29+
} as any
30+
31+
const result = await getConversationByAddressPair("+1234","+5678");
32+
expect(createSpy).toBeCalledWith({"address":"+1234"});
33+
expect(result).not.toBeNull();
34+
// ToDo: add proper mocked response with ParticipantConversationInstance
35+
})
36+
})
37+

0 commit comments

Comments
 (0)