@@ -27,6 +27,10 @@ const { VoiceResponse, MessagingResponse, FaxResponse } = twiml;
2727const mockResponse = ( new MockResponse ( ) as unknown ) as ExpressResponse ;
2828mockResponse . type = jest . fn ( ( ) => mockResponse ) ;
2929
30+ function asExpressRequest ( req : { query ?: { } ; body ?: { } } ) : ExpressRequest {
31+ return ( req as unknown ) as ExpressRequest ;
32+ }
33+
3034describe ( 'handleError function' , ( ) => {
3135 test ( 'returns string error' , ( ) => {
3236 const mockRequest = ( new MockRequest ( ) as unknown ) as ExpressRequest ;
@@ -101,57 +105,67 @@ describe('handleError function', () => {
101105
102106describe ( 'constructEvent function' , ( ) => {
103107 test ( 'merges query and body' , ( ) => {
104- const event = constructEvent ( {
105- body : {
106- Body : 'Hello' ,
107- } ,
108- query : {
109- index : 5 ,
110- } ,
111- } as ExpressRequest ) ;
108+ const event = constructEvent (
109+ asExpressRequest ( {
110+ body : {
111+ Body : 'Hello' ,
112+ } ,
113+ query : {
114+ index : 5 ,
115+ } ,
116+ } )
117+ ) ;
112118 expect ( event ) . toEqual ( { Body : 'Hello' , index : 5 } ) ;
113119 } ) ;
114120
115121 test ( 'overrides query with body' , ( ) => {
116- const event = constructEvent ( {
117- body : {
118- Body : 'Bye' ,
119- } ,
120- query : {
121- Body : 'Hello' ,
122- From : '+123456789' ,
123- } ,
124- } as ExpressRequest ) ;
122+ const event = constructEvent (
123+ asExpressRequest ( {
124+ body : {
125+ Body : 'Bye' ,
126+ } ,
127+ query : {
128+ Body : 'Hello' ,
129+ From : '+123456789' ,
130+ } ,
131+ } )
132+ ) ;
125133 expect ( event ) . toEqual ( { Body : 'Bye' , From : '+123456789' } ) ;
126134 } ) ;
127135
128136 test ( 'handles empty body' , ( ) => {
129- const event = constructEvent ( {
130- body : { } ,
131- query : {
132- Body : 'Hello' ,
133- From : '+123456789' ,
134- } ,
135- } as ExpressRequest ) ;
137+ const event = constructEvent (
138+ asExpressRequest ( {
139+ body : { } ,
140+ query : {
141+ Body : 'Hello' ,
142+ From : '+123456789' ,
143+ } ,
144+ } )
145+ ) ;
136146 expect ( event ) . toEqual ( { Body : 'Hello' , From : '+123456789' } ) ;
137147 } ) ;
138148
139149 test ( 'handles empty query' , ( ) => {
140- const event = constructEvent ( {
141- body : {
142- Body : 'Hello' ,
143- From : '+123456789' ,
144- } ,
145- query : { } ,
146- } as ExpressRequest ) ;
150+ const event = constructEvent (
151+ asExpressRequest ( {
152+ body : {
153+ Body : 'Hello' ,
154+ From : '+123456789' ,
155+ } ,
156+ query : { } ,
157+ } )
158+ ) ;
147159 expect ( event ) . toEqual ( { Body : 'Hello' , From : '+123456789' } ) ;
148160 } ) ;
149161
150162 test ( 'handles both empty' , ( ) => {
151- const event = constructEvent ( {
152- body : { } ,
153- query : { } ,
154- } as ExpressRequest ) ;
163+ const event = constructEvent (
164+ asExpressRequest ( {
165+ body : { } ,
166+ query : { } ,
167+ } )
168+ ) ;
155169 expect ( event ) . toEqual ( { } ) ;
156170 } ) ;
157171} ) ;
0 commit comments