Skip to content

Commit 8f28483

Browse files
committed
First working test for sessions
1 parent 513c984 commit 8f28483

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

tests/services/session.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { getActiveProxyAddresses } from "../../src/services/session.service"
2+
import { listParticipantConversations } from "../../src/utils"
3+
import { mockListParticipantsResponse } from "../support/testSupport"
4+
5+
jest.mock('../../src/utils/listParticipantConversations.util')
6+
const mockedListParticipantConversations = jest.mocked(listParticipantConversations, true)
7+
8+
9+
describe('session service', () => {
10+
describe('getActiveProxyAdresses', () => {
11+
12+
it('receives a list of numbers and returns a keyed object with proxy address arrays', async () => {
13+
mockedListParticipantConversations.mockResolvedValue(mockListParticipantsResponse as any)
14+
const result = await getActiveProxyAddresses(['+1112223333', '+2223334444'])
15+
16+
expect(result).toEqual({"+1112223333": ["+3334445555", "+4445556666"], "+2223334444": ["+3334445555", "+4445556666"]})
17+
})
18+
19+
it('returns key with empty array if no active conversations', async () => {
20+
mockedListParticipantConversations.mockResolvedValue([] as any)
21+
const result = await getActiveProxyAddresses(['+1112223333', '+2223334444'])
22+
23+
expect(result).toEqual({"+1112223333": [], "+2223334444": []})
24+
})
25+
})
26+
27+
describe('matchAvailableProxyAddresses', () => {
28+
29+
})
30+
31+
describe('retryParticipantAdd', () => {
32+
33+
})
34+
35+
describe('addParticipantsToConversation', () => {
36+
37+
})
38+
})

tests/support/testSupport.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
export const mockListParticipantsResponse = [{
2+
accountSid: "ACXXX",
3+
chatServiceSid: "ISXXX",
4+
conversationState: "active",
5+
conversationTimers: {},
6+
conversationUniqueName: null,
7+
links: {
8+
conversation: "https://conversations.twilio.com/v1/Conversations/CH82681a28cddf4475afda30a2d94d9b29",
9+
participant: "https://conversations.twilio.com/v1/Conversations/CH82681a28cddf4475afda30a2d94d9b29/Participants/MB2d794fc4f4af4ee49ddcc1bdd8be6b94"
10+
},
11+
participantIdentity: null,
12+
participantMessagingBinding: {
13+
name: null,
14+
level: null,
15+
type: "sms",
16+
proxy_address: "+3334445555",
17+
address: "+2223334444",
18+
projected_address: null
19+
},
20+
participantSid: "MB2d794fc4f4af4ee49ddcc1bdd8be6b94",
21+
participantUserSid: null
22+
}, {
23+
accountSid: "ACXXX",
24+
chatServiceSid: "ISXXX",
25+
conversationState: "active",
26+
conversationTimers: {},
27+
conversationUniqueName: null,
28+
links: {
29+
conversation: "https://conversations.twilio.com/v1/Conversations/CH82681a28cddf4475afda30a2d94d9b29",
30+
participant: "https://conversations.twilio.com/v1/Conversations/CH82681a28cddf4475afda30a2d94d9b29/Participants/MB2d794fc4f4af4ee49ddcc1bdd8be6b94"
31+
},
32+
participantIdentity: null,
33+
participantMessagingBinding: {
34+
name: null,
35+
level: null,
36+
type: "sms",
37+
proxy_address: "+4445556666",
38+
address: "+2223334444",
39+
projected_address: null
40+
},
41+
participantSid: "MB2d794fc4f4af4ee49ddcc1bdd8be6b94",
42+
participantUserSid: null
43+
}]

0 commit comments

Comments
 (0)