@@ -13,20 +13,21 @@ const mockClient = jest.fn(() => ({
1313 } ,
1414} ) ) ;
1515
16+ const mockContext = {
17+ ACCOUNT_SID : '1234' ,
18+ AUTH_TOKEN : '2345' ,
19+ getTwilioClient : ( ) => mockClient ( ) ,
20+ } ;
21+
1622jest . mock ( 'twilio' ) ;
1723twilio . mockImplementation ( mockClient ) ;
1824
1925describe ( 'the recordingrules function' , ( ) => {
2026 it ( 'should correctly respond when a room update is successful' , async ( ) => {
2127 const mockCallback = jest . fn ( ) ;
2228
23- await handler (
24- { ACCOUNT_SID : '1234' , AUTH_TOKEN : '2345' } ,
25- { room_sid : 'mockRoomSid' , rules : 'mockRules' } ,
26- mockCallback
27- ) ;
29+ await handler ( mockContext , { room_sid : 'mockRoomSid' , rules : 'mockRules' } , mockCallback ) ;
2830
29- expect ( mockClient ) . toHaveBeenCalledWith ( '1234' , '2345' ) ;
3031 expect ( mockCallback ) . toHaveBeenCalledWith ( null , {
3132 body : 'mockSuccessResponse' ,
3233 headers : { 'Content-Type' : 'application/json' } ,
@@ -39,11 +40,7 @@ describe('the recordingrules function', () => {
3940 const mockError = { message : 'mockErrorMesage' , code : 123 } ;
4041 mockUpdateFn . mockImplementationOnce ( ( ) => Promise . reject ( mockError ) ) ;
4142
42- await handler (
43- { ACCOUNT_SID : '1234' , AUTH_TOKEN : '2345' } ,
44- { room_sid : 'mockRoomSid' , rules : 'mockRules' } ,
45- mockCallback
46- ) ;
43+ await handler ( mockContext , { room_sid : 'mockRoomSid' , rules : 'mockRules' } , mockCallback ) ;
4744
4845 expect ( mockCallback ) . toHaveBeenCalledWith ( null , {
4946 body : { error : mockError } ,
@@ -55,7 +52,7 @@ describe('the recordingrules function', () => {
5552 it ( 'should return a "missing room_sid" error when the room_sid is absent' , async ( ) => {
5653 const mockCallback = jest . fn ( ) ;
5754
58- await handler ( { ACCOUNT_SID : '1234' , AUTH_TOKEN : '2345' } , { rules : 'mockRules' } , mockCallback ) ;
55+ await handler ( mockContext , { rules : 'mockRules' } , mockCallback ) ;
5956
6057 expect ( mockCallback ) . toHaveBeenCalledWith ( null , {
6158 body : {
@@ -72,7 +69,7 @@ describe('the recordingrules function', () => {
7269 it ( 'should return a "missing rules" error when the rules array is absent' , async ( ) => {
7370 const mockCallback = jest . fn ( ) ;
7471
75- await handler ( { ACCOUNT_SID : '1234' , AUTH_TOKEN : '2345' } , { room_sid : 'mockSid' } , mockCallback ) ;
72+ await handler ( mockContext , { room_sid : 'mockSid' } , mockCallback ) ;
7673
7774 expect ( mockCallback ) . toHaveBeenCalledWith ( null , {
7875 body : {
0 commit comments