@@ -428,6 +428,43 @@ describe("ZendeskService", () => {
428428 expect ( result ) . toEqual ( organizations ) ;
429429 } ) ;
430430 } ) ;
431+
432+ describe ( "getRoles" , ( ) => {
433+ it ( "should call the API and return the roles" , async ( ) => {
434+ const custom_roles = [ { name : "role1" } ] ;
435+ requestMock . mockResolvedValueOnce ( { custom_roles } ) ;
436+
437+ const result = await service . getRoles ( ) ;
438+
439+ expect ( requestMock ) . toHaveBeenCalledWith ( `/api/v2/custom_roles` ) ;
440+ expect ( result ) . toEqual ( custom_roles ) ;
441+ } ) ;
442+
443+ it ( "should continue calling the API until next_page disappears" , async ( ) => {
444+ const custom_roles = [ { name : "role1" } ] ;
445+ requestMock
446+ . mockResolvedValueOnce ( { custom_roles, next_page : "next_page" } )
447+ . mockResolvedValueOnce ( { custom_roles : [ ] } ) ;
448+
449+ const result = await service . getRoles ( ) ;
450+
451+ expect ( requestMock ) . toHaveBeenCalledTimes ( 2 ) ;
452+ expect ( requestMock ) . toHaveBeenNthCalledWith ( 1 , `/api/v2/custom_roles` ) ;
453+ expect ( requestMock ) . toHaveBeenNthCalledWith ( 2 , "next_page" ) ;
454+ expect ( result ) . toEqual ( custom_roles ) ;
455+ } ) ;
456+
457+ it ( "should only call the API one time with fetchAllRoles set to false" , async ( ) => {
458+ const custom_roles = [ { name : "role1" } ] ;
459+ requestMock . mockResolvedValueOnce ( { custom_roles, next_page : "next_page" } ) ;
460+
461+ const result = await service . getRoles ( false ) ;
462+
463+ expect ( requestMock ) . toHaveBeenCalledTimes ( 1 ) ;
464+ expect ( requestMock ) . toHaveBeenCalledWith ( `/api/v2/custom_roles` ) ;
465+ expect ( result ) . toEqual ( custom_roles ) ;
466+ } ) ;
467+ } ) ;
431468 describe ( "getLocales" , ( ) => {
432469 it ( "should fetch and return locales" , async ( ) => {
433470 const locales = [ { locale : "en-US" } ] ;
0 commit comments