@@ -37,12 +37,12 @@ describe('[Call History]', () => {
3737 expect ( res . body ) . to . have . property ( 'count' , 4 ) ;
3838
3939 const historyIds = res . body . items . map ( ( item : any ) => item . _id ) ;
40- expect ( historyIds ) . to . include ( 'rocketchat.internal.history.test' ) ;
41- expect ( historyIds ) . to . include ( 'rocketchat.internal.history.test.2 ' ) ;
42- expect ( historyIds ) . to . include ( 'rocketchat.internal .history.test.3 ' ) ;
43- expect ( historyIds ) . to . include ( 'rocketchat.internal .history.test.4 ' ) ;
40+ expect ( historyIds ) . to . include ( 'rocketchat.internal.history.test.outbound ' ) ;
41+ expect ( historyIds ) . to . include ( 'rocketchat.internal.history.test.inbound ' ) ;
42+ expect ( historyIds ) . to . include ( 'rocketchat.external .history.test.outbound ' ) ;
43+ expect ( historyIds ) . to . include ( 'rocketchat.external .history.test.inbound ' ) ;
4444
45- const internalItem1 = res . body . items . find ( ( item : any ) => item . _id === 'rocketchat.internal.history.test' ) ;
45+ const internalItem1 = res . body . items . find ( ( item : any ) => item . _id === 'rocketchat.internal.history.test.outbound ' ) ;
4646 expect ( internalItem1 ) . to . have . property ( 'callId' , 'rocketchat.internal.call.test' ) ;
4747 expect ( internalItem1 ) . to . have . property ( 'state' , 'ended' ) ;
4848 expect ( internalItem1 ) . to . have . property ( 'type' , 'media-call' ) ;
@@ -51,26 +51,26 @@ describe('[Call History]', () => {
5151 expect ( internalItem1 ) . to . have . property ( 'direction' , 'outbound' ) ;
5252 expect ( internalItem1 ) . to . have . property ( 'contactId' ) ;
5353
54- const internalItem2 = res . body . items . find ( ( item : any ) => item . _id === 'rocketchat.internal.history.test.2 ' ) ;
54+ const internalItem2 = res . body . items . find ( ( item : any ) => item . _id === 'rocketchat.internal.history.test.inbound ' ) ;
5555 expect ( internalItem2 ) . to . have . property ( 'callId' , 'rocketchat.internal.call.test.2' ) ;
56- expect ( internalItem2 ) . to . have . property ( 'state' , 'ended ' ) ;
56+ expect ( internalItem2 ) . to . have . property ( 'state' , 'not-answered ' ) ;
5757 expect ( internalItem2 ) . to . have . property ( 'type' , 'media-call' ) ;
5858 expect ( internalItem2 ) . to . have . property ( 'duration' , 10 ) ;
5959 expect ( internalItem2 ) . to . have . property ( 'external' , false ) ;
6060 expect ( internalItem2 ) . to . have . property ( 'direction' , 'inbound' ) ;
6161 expect ( internalItem2 ) . to . have . property ( 'contactId' ) ;
6262
63- const externalItem1 = res . body . items . find ( ( item : any ) => item . _id === 'rocketchat.internal .history.test.3 ' ) ;
64- expect ( externalItem1 ) . to . have . property ( 'callId' , 'rocketchat.internal .call.test.3 ' ) ;
65- expect ( externalItem1 ) . to . have . property ( 'state' , 'ended ' ) ;
63+ const externalItem1 = res . body . items . find ( ( item : any ) => item . _id === 'rocketchat.external .history.test.outbound ' ) ;
64+ expect ( externalItem1 ) . to . have . property ( 'callId' , 'rocketchat.external .call.test.outbound ' ) ;
65+ expect ( externalItem1 ) . to . have . property ( 'state' , 'failed ' ) ;
6666 expect ( externalItem1 ) . to . have . property ( 'type' , 'media-call' ) ;
6767 expect ( externalItem1 ) . to . have . property ( 'duration' , 10 ) ;
6868 expect ( externalItem1 ) . to . have . property ( 'external' , true ) ;
6969 expect ( externalItem1 ) . to . have . property ( 'direction' , 'outbound' ) ;
7070 expect ( externalItem1 ) . to . have . property ( 'contactExtension' , '1001' ) ;
7171
72- const externalItem2 = res . body . items . find ( ( item : any ) => item . _id === 'rocketchat.internal .history.test.4 ' ) ;
73- expect ( externalItem2 ) . to . have . property ( 'callId' , 'rocketchat.internal .call.test.4 ' ) ;
72+ const externalItem2 = res . body . items . find ( ( item : any ) => item . _id === 'rocketchat.external .history.test.inbound ' ) ;
73+ expect ( externalItem2 ) . to . have . property ( 'callId' , 'rocketchat.external .call.test.inbound ' ) ;
7474 expect ( externalItem2 ) . to . have . property ( 'state' , 'ended' ) ;
7575 expect ( externalItem2 ) . to . have . property ( 'type' , 'media-call' ) ;
7676 expect ( externalItem2 ) . to . have . property ( 'duration' , 10 ) ;
@@ -95,6 +95,99 @@ describe('[Call History]', () => {
9595 expect ( res . body ) . to . have . property ( 'count' , 0 ) ;
9696 } ) ;
9797 } ) ;
98+
99+ it ( 'should apply filter by state' , async ( ) => {
100+ await request
101+ . get ( api ( 'call-history.list' ) )
102+ . set ( credentials )
103+ . query ( {
104+ state : [ 'ended' ] ,
105+ } )
106+ . expect ( 'Content-Type' , 'application/json' )
107+ . expect ( 200 )
108+ . expect ( ( res : Response ) => {
109+ expect ( res . body ) . to . have . property ( 'success' , true ) ;
110+ expect ( res . body ) . to . have . property ( 'items' ) . that . is . an ( 'array' ) ;
111+
112+ expect ( res . body . items ) . to . have . lengthOf ( 2 ) ;
113+ expect ( res . body ) . to . have . property ( 'total' , 2 ) ;
114+ expect ( res . body ) . to . have . property ( 'count' , 2 ) ;
115+
116+ const historyIds = res . body . items . map ( ( item : any ) => item . _id ) ;
117+ expect ( historyIds ) . to . include ( 'rocketchat.internal.history.test.outbound' ) ;
118+ expect ( historyIds ) . to . include ( 'rocketchat.external.history.test.inbound' ) ;
119+ } ) ;
120+ } ) ;
121+
122+ it ( 'should apply filter by multiple states' , async ( ) => {
123+ await request
124+ . get ( api ( 'call-history.list' ) )
125+ . set ( credentials )
126+ . query ( {
127+ state : [ 'failed' , 'ended' ] ,
128+ } )
129+ . expect ( 'Content-Type' , 'application/json' )
130+ . expect ( 200 )
131+ . expect ( ( res : Response ) => {
132+ expect ( res . body ) . to . have . property ( 'success' , true ) ;
133+ expect ( res . body ) . to . have . property ( 'items' ) . that . is . an ( 'array' ) ;
134+
135+ expect ( res . body . items ) . to . have . lengthOf ( 3 ) ;
136+ expect ( res . body ) . to . have . property ( 'total' , 3 ) ;
137+ expect ( res . body ) . to . have . property ( 'count' , 3 ) ;
138+
139+ const historyIds = res . body . items . map ( ( item : any ) => item . _id ) ;
140+ expect ( historyIds ) . to . include ( 'rocketchat.internal.history.test.outbound' ) ;
141+ expect ( historyIds ) . to . include ( 'rocketchat.external.history.test.outbound' ) ;
142+ expect ( historyIds ) . to . include ( 'rocketchat.external.history.test.inbound' ) ;
143+ } ) ;
144+ } ) ;
145+
146+ it ( 'should apply filter by direction' , async ( ) => {
147+ await request
148+ . get ( api ( 'call-history.list' ) )
149+ . set ( credentials )
150+ . query ( {
151+ direction : 'inbound' ,
152+ } )
153+ . expect ( 'Content-Type' , 'application/json' )
154+ . expect ( 200 )
155+ . expect ( ( res : Response ) => {
156+ expect ( res . body ) . to . have . property ( 'success' , true ) ;
157+ expect ( res . body ) . to . have . property ( 'items' ) . that . is . an ( 'array' ) ;
158+
159+ expect ( res . body . items ) . to . have . lengthOf ( 2 ) ;
160+ expect ( res . body ) . to . have . property ( 'total' , 2 ) ;
161+ expect ( res . body ) . to . have . property ( 'count' , 2 ) ;
162+
163+ const historyIds = res . body . items . map ( ( item : any ) => item . _id ) ;
164+ expect ( historyIds ) . to . include ( 'rocketchat.internal.history.test.inbound' ) ;
165+ expect ( historyIds ) . to . include ( 'rocketchat.external.history.test.inbound' ) ;
166+ } ) ;
167+ } ) ;
168+
169+ it ( 'should apply filter by state and direction' , async ( ) => {
170+ await request
171+ . get ( api ( 'call-history.list' ) )
172+ . set ( credentials )
173+ . query ( {
174+ state : [ 'failed' , 'ended' ] ,
175+ direction : 'inbound' ,
176+ } )
177+ . expect ( 'Content-Type' , 'application/json' )
178+ . expect ( 200 )
179+ . expect ( ( res : Response ) => {
180+ expect ( res . body ) . to . have . property ( 'success' , true ) ;
181+ expect ( res . body ) . to . have . property ( 'items' ) . that . is . an ( 'array' ) ;
182+
183+ expect ( res . body . items ) . to . have . lengthOf ( 1 ) ;
184+ expect ( res . body ) . to . have . property ( 'total' , 1 ) ;
185+ expect ( res . body ) . to . have . property ( 'count' , 1 ) ;
186+
187+ const historyIds = res . body . items . map ( ( item : any ) => item . _id ) ;
188+ expect ( historyIds ) . to . include ( 'rocketchat.external.history.test.inbound' ) ;
189+ } ) ;
190+ } ) ;
98191 } ) ;
99192
100193 describe ( '[/call-history.info]' , ( ) => {
@@ -103,7 +196,7 @@ describe('[Call History]', () => {
103196 . get ( api ( 'call-history.info' ) )
104197 . set ( credentials )
105198 . query ( {
106- historyId : 'rocketchat.internal.history.test' ,
199+ historyId : 'rocketchat.internal.history.test.outbound ' ,
107200 } )
108201 . expect ( 'Content-Type' , 'application/json' )
109202 . expect ( 200 )
@@ -113,7 +206,7 @@ describe('[Call History]', () => {
113206 expect ( res . body ) . to . have . property ( 'call' ) . that . is . an ( 'object' ) ;
114207
115208 const { item, call } = res . body ;
116- expect ( item ) . to . have . property ( '_id' , 'rocketchat.internal.history.test' ) ;
209+ expect ( item ) . to . have . property ( '_id' , 'rocketchat.internal.history.test.outbound ' ) ;
117210 expect ( item ) . to . have . property ( 'callId' , 'rocketchat.internal.call.test' ) ;
118211 expect ( item ) . to . have . property ( 'state' , 'ended' ) ;
119212 expect ( item ) . to . have . property ( 'type' , 'media-call' ) ;
@@ -158,9 +251,9 @@ describe('[Call History]', () => {
158251 expect ( res . body ) . to . have . property ( 'call' ) . that . is . an ( 'object' ) ;
159252
160253 const { item, call } = res . body ;
161- expect ( item ) . to . have . property ( '_id' , 'rocketchat.internal.history.test.2 ' ) ;
254+ expect ( item ) . to . have . property ( '_id' , 'rocketchat.internal.history.test.inbound ' ) ;
162255 expect ( item ) . to . have . property ( 'callId' , 'rocketchat.internal.call.test.2' ) ;
163- expect ( item ) . to . have . property ( 'state' , 'ended ' ) ;
256+ expect ( item ) . to . have . property ( 'state' , 'not-answered ' ) ;
164257 expect ( item ) . to . have . property ( 'type' , 'media-call' ) ;
165258 expect ( item ) . to . have . property ( 'duration' , 10 ) ;
166259 expect ( item ) . to . have . property ( 'external' , false ) ;
@@ -215,7 +308,7 @@ describe('[Call History]', () => {
215308 . get ( api ( 'call-history.info' ) )
216309 . set ( userCredentials )
217310 . query ( {
218- historyId : 'rocketchat.internal.history.test' ,
311+ historyId : 'rocketchat.internal.history.test.outbound ' ,
219312 } )
220313 . expect ( 'Content-Type' , 'application/json' )
221314 . expect ( 404 ) ;
0 commit comments