File tree Expand file tree Collapse file tree 2 files changed +40
-46
lines changed Expand file tree Collapse file tree 2 files changed +40
-46
lines changed Original file line number Diff line number Diff line change 1+ import { addParticipant } from "../../src/utils" ;
2+ import client from '../../src/twilioClient' ;
3+
4+ import { ParticipantInstance , ParticipantListInstanceCreateOptions } from "twilio/lib/rest/conversations/v1/conversation/participant" ;
5+
6+
7+ jest . mock ( '../../src/twilioClient' )
8+ let mockedClient = jest . mocked ( client , true )
9+
10+ const mockParticipant : Partial < ParticipantListInstanceCreateOptions > = {
11+ identity : "+1234" ,
12+ }
13+
14+ describe ( 'addParticipant util' , ( ) => {
15+ beforeEach ( ( ) => {
16+ jest . resetAllMocks ( )
17+ } )
18+
19+
20+ it ( 'it adds participant to conversation' , async ( ) => {
21+
22+ let createSpy = jest . fn ( ( options ) => { return options } ) ;
23+ let participantsSpy = jest . fn ( ( ) => { return { create :createSpy } } ) ;
24+ const conversationsSpy = jest . fn ( ( options ) => { return participantsSpy } ) ;
25+
26+ mockedClient [ 'conversations' ] = {
27+ conversations : conversationsSpy
28+ } as any
29+
30+
31+ const result = await addParticipant ( "myConversationSid" , mockParticipant ) ;
32+ expect ( conversationsSpy ) . toBeCalledWith ( "myConversationSid" ) ;
33+ expect ( participantsSpy ) . toBeCalled ( ) ;
34+ expect ( createSpy ) . toBeCalledWith ( mockParticipant ) ;
35+ expect ( result ) . not . toBeNull ( ) ;
36+
37+ } )
38+
39+
40+ } )
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments