@@ -13,6 +13,43 @@ describe('Command: vonage conversations list', () => {
1313 mockConsole ( ) ;
1414 } ) ;
1515
16+ test ( 'Will list with no conversations' , async ( ) => {
17+ confirm . mockResolvedValue ( true ) ;
18+
19+ const conversationMock = jest . fn ( )
20+ . mockResolvedValueOnce ( {
21+ conversations : [ ] ,
22+ links : {
23+ self : {
24+ href : 'https://api.nexmo.com/conversations' ,
25+ } ,
26+ } ,
27+ } ) ;
28+
29+ const sdkMock = {
30+ conversations : {
31+ getConversationPage : conversationMock ,
32+ } ,
33+ } ;
34+
35+ await handler ( { SDK : sdkMock , pageSize : 10 } ) ;
36+
37+ expect ( conversationMock ) . toHaveBeenCalledTimes ( 1 ) ;
38+ expect ( conversationMock ) . toHaveBeenNthCalledWith (
39+ 1 ,
40+ {
41+ pageSize : 10 ,
42+ cursor : undefined ,
43+ } ,
44+ ) ;
45+
46+ expect ( console . log ) . toHaveBeenNthCalledWith (
47+ 1 ,
48+ 'No conversations found' ,
49+ ) ;
50+ expect ( console . table ) . toHaveBeenCalledTimes ( 0 ) ;
51+ } ) ;
52+
1653 test ( 'Will list all conversations' , async ( ) => {
1754 confirm . mockResolvedValue ( true ) ;
1855
@@ -31,7 +68,7 @@ describe('Command: vonage conversations list', () => {
3168 } ,
3269 } )
3370 . mockResolvedValueOnce ( {
34- conversations : conversations . slice ( 10 , 10 ) ,
71+ conversations : conversations . slice ( 10 , 20 ) ,
3572 links : {
3673 next : {
3774 href : 'https://api.nexmo.com/conversations?cursor=2' ,
@@ -50,6 +87,11 @@ describe('Command: vonage conversations list', () => {
5087
5188 await handler ( { SDK : sdkMock , pageSize : 10 } ) ;
5289
90+ console . log ( conversations . length ) ;
91+ console . log ( conversations . slice ( 0 , 10 ) . length ) ;
92+ console . log ( conversations . slice ( 10 , 20 ) . length ) ;
93+ console . log ( conversations . slice ( 20 ) . length ) ;
94+
5395 expect ( confirm ) . toHaveBeenCalledTimes ( 2 ) ;
5496 expect ( confirm ) . toHaveBeenNthCalledWith (
5597 1 ,
@@ -96,7 +138,7 @@ describe('Command: vonage conversations list', () => {
96138
97139 expect ( console . table ) . toHaveBeenNthCalledWith (
98140 2 ,
99- conversations . slice ( 10 , 10 ) . map ( ( conversation ) => ( {
141+ conversations . slice ( 10 , 20 ) . map ( ( conversation ) => ( {
100142 'Name' : conversation . name ,
101143 'Conversation ID' : conversation . id ,
102144 'Display Name' : conversation . displayName ,
@@ -133,7 +175,7 @@ describe('Command: vonage conversations list', () => {
133175 } ,
134176 } )
135177 . mockResolvedValueOnce ( {
136- conversations : conversations . slice ( 10 , 10 ) ,
178+ conversations : conversations . slice ( 10 , 20 ) ,
137179 links : {
138180 next : {
139181 href : 'https://api.nexmo.com/conversations?cursor=2' ,
@@ -179,7 +221,7 @@ describe('Command: vonage conversations list', () => {
179221
180222 expect ( console . table ) . toHaveBeenNthCalledWith (
181223 2 ,
182- conversations . slice ( 10 , 10 ) . map ( ( conversation ) => ( {
224+ conversations . slice ( 10 , 20 ) . map ( ( conversation ) => ( {
183225 'Name' : conversation . name ,
184226 'Conversation ID' : conversation . id ,
185227 'Display Name' : conversation . displayName ,
0 commit comments