@@ -309,6 +309,128 @@ describe("ZendeskService", () => {
309309 ) . rejects . toThrow ( RangeError ) ;
310310 expect ( requestMock ) . toHaveBeenCalledTimes ( 0 ) ;
311311 } ) ;
312+
313+ describe ( "getTags" , ( ) => {
314+ it ( "should call the API and return the tags" , async ( ) => {
315+ const tags = [ { name : "tag1" } ] ;
316+ requestMock . mockResolvedValueOnce ( { tags } ) ;
317+
318+ const result = await service . getTags ( ) ;
319+
320+ expect ( requestMock ) . toHaveBeenCalledWith ( `/api/v2/tags` ) ;
321+ expect ( result ) . toEqual ( tags ) ;
322+ } ) ;
323+
324+ it ( "should continue calling the API until next_page disappears" , async ( ) => {
325+ const tags = [ { name : "tag1" } ] ;
326+ requestMock
327+ . mockResolvedValueOnce ( { tags, next_page : "next_page" } )
328+ . mockResolvedValueOnce ( { tags : [ ] } ) ;
329+
330+ const result = await service . getTags ( ) ;
331+
332+ expect ( requestMock ) . toHaveBeenCalledTimes ( 2 ) ;
333+ expect ( requestMock ) . toHaveBeenNthCalledWith ( 1 , `/api/v2/tags` ) ;
334+ expect ( requestMock ) . toHaveBeenNthCalledWith ( 2 , "next_page" ) ;
335+ expect ( result ) . toEqual ( tags ) ;
336+ } ) ;
337+
338+ it ( "should only call the API one time with fetchAllTags set to false" , async ( ) => {
339+ const tags = [ { name : "tag1" } ] ;
340+ requestMock . mockResolvedValueOnce ( { tags, next_page : "next_page" } ) ;
341+
342+ const result = await service . getTags ( false ) ;
343+
344+ expect ( requestMock ) . toHaveBeenCalledTimes ( 1 ) ;
345+ expect ( requestMock ) . toHaveBeenCalledWith ( `/api/v2/tags` ) ;
346+ expect ( result ) . toEqual ( tags ) ;
347+ } ) ;
348+ } ) ;
349+
350+ describe ( "getGroups" , ( ) => {
351+ it ( "should call the API and return the groups" , async ( ) => {
352+ const groups = [ { name : "group1" } ] ;
353+ requestMock . mockResolvedValueOnce ( { groups } ) ;
354+
355+ const result = await service . getGroups ( ) ;
356+
357+ expect ( requestMock ) . toHaveBeenCalledWith ( `/api/v2/groups` ) ;
358+ expect ( result ) . toEqual ( groups ) ;
359+ } ) ;
360+
361+ it ( "should continue calling the API until next_page disappears" , async ( ) => {
362+ const groups = [ { name : "group1" } ] ;
363+ requestMock
364+ . mockResolvedValueOnce ( { groups, next_page : "next_page" } )
365+ . mockResolvedValueOnce ( { groups : [ ] } ) ;
366+
367+ const result = await service . getGroups ( ) ;
368+
369+ expect ( requestMock ) . toHaveBeenCalledTimes ( 2 ) ;
370+ expect ( requestMock ) . toHaveBeenNthCalledWith ( 1 , `/api/v2/groups` ) ;
371+ expect ( requestMock ) . toHaveBeenNthCalledWith ( 2 , "next_page" ) ;
372+ expect ( result ) . toEqual ( groups ) ;
373+ } ) ;
374+
375+ it ( "should only call the API one time with fetchAllGroups set to false" , async ( ) => {
376+ const groups = [ { name : "group1" } ] ;
377+ requestMock . mockResolvedValueOnce ( { groups, next_page : "next_page" } ) ;
378+
379+ const result = await service . getGroups ( false ) ;
380+
381+ expect ( requestMock ) . toHaveBeenCalledTimes ( 1 ) ;
382+ expect ( requestMock ) . toHaveBeenCalledWith ( `/api/v2/groups` ) ;
383+ expect ( result ) . toEqual ( groups ) ;
384+ } ) ;
385+ } ) ;
386+
387+ describe ( "getOrganizations" , ( ) => {
388+ it ( "should call the API and return the organizations" , async ( ) => {
389+ const organizations = [ { name : "organization1" } ] ;
390+ requestMock . mockResolvedValueOnce ( { organizations } ) ;
391+
392+ const result = await service . getOrganizations ( ) ;
393+
394+ expect ( requestMock ) . toHaveBeenCalledWith ( `/api/v2/organizations` ) ;
395+ expect ( result ) . toEqual ( organizations ) ;
396+ } ) ;
397+
398+ it ( "should continue calling the API until next_page disappears" , async ( ) => {
399+ const organizations = [ { name : "organization1" } ] ;
400+ requestMock
401+ . mockResolvedValueOnce ( { organizations, next_page : "next_page" } )
402+ . mockResolvedValueOnce ( { organizations : [ ] } ) ;
403+
404+ const result = await service . getOrganizations ( ) ;
405+
406+ expect ( requestMock ) . toHaveBeenCalledTimes ( 2 ) ;
407+ expect ( requestMock ) . toHaveBeenNthCalledWith ( 1 , `/api/v2/organizations` ) ;
408+ expect ( requestMock ) . toHaveBeenNthCalledWith ( 2 , "next_page" ) ;
409+ expect ( result ) . toEqual ( organizations ) ;
410+ } ) ;
411+
412+ it ( "should only call the API one time with fetchAllOrganizations set to false" , async ( ) => {
413+ const organizations = [ { name : "organization1" } ] ;
414+ requestMock . mockResolvedValueOnce ( { organizations, next_page : "next_page" } ) ;
415+
416+ const result = await service . getOrganizations ( false ) ;
417+
418+ expect ( requestMock ) . toHaveBeenCalledTimes ( 1 ) ;
419+ expect ( requestMock ) . toHaveBeenCalledWith ( `/api/v2/organizations` ) ;
420+ expect ( result ) . toEqual ( organizations ) ;
421+ } ) ;
422+ } ) ;
423+ describe ( "getLocales" , ( ) => {
424+ it ( "should fetch and return locales" , async ( ) => {
425+ const locales = [ { locale : "en-US" } ] ;
426+ requestMock . mockResolvedValueOnce ( { locales } ) ;
427+
428+ const result = await service . getLocales ( ) ;
429+
430+ expect ( requestMock ) . toHaveBeenCalledWith ( `/api/v2/locales` ) ;
431+ expect ( result ) . toEqual ( locales ) ;
432+ } ) ;
433+ } ) ;
312434 } ) ;
313435 } ) ;
314436} ) ;
0 commit comments