@@ -1167,4 +1167,51 @@ describe("ZendeskService", () => {
11671167 expect ( result ) . toEqual ( [ viewSample ] ) ;
11681168 } ) ;
11691169 } ) ;
1170+
1171+ describe ( "getBrands" , ( ) => {
1172+ const brandSample = {
1173+ active : true ,
1174+ brand_url : "https://example.zendesk.com/api/v2/brands/123.json" ,
1175+ created_at : "2023-01-01T00:00:00Z" ,
1176+ default : false ,
1177+ has_help_center : true ,
1178+ help_center_state : "enabled"
1179+ } ;
1180+
1181+ it ( "should fetch brands with the correct data" , async ( ) => {
1182+ requestMock . mockResolvedValueOnce ( { brands : [ brandSample ] } ) ;
1183+
1184+ const result = await service . getBrands ( ) ;
1185+
1186+ expect ( requestMock ) . toHaveBeenCalledWith ( {
1187+ url : `/api/v2/brands`
1188+ } ) ;
1189+ expect ( result ) . toEqual ( [ brandSample ] ) ;
1190+ } ) ;
1191+
1192+ it ( "should continue calling the API until next_page disappears" , async ( ) => {
1193+ requestMock
1194+ . mockResolvedValueOnce ( { brands : [ brandSample ] , next_page : "next_page" } )
1195+ . mockResolvedValueOnce ( { brands : [ ] } ) ;
1196+
1197+ const result = await service . getBrands ( ) ;
1198+
1199+ expect ( requestMock ) . toHaveBeenCalledTimes ( 2 ) ;
1200+ expect ( requestMock ) . toHaveBeenNthCalledWith ( 1 , {
1201+ url : `/api/v2/brands`
1202+ } ) ;
1203+ expect ( requestMock ) . toHaveBeenNthCalledWith ( 2 , {
1204+ url : "next_page"
1205+ } ) ;
1206+ expect ( result ) . toEqual ( [ brandSample ] ) ;
1207+ } ) ;
1208+
1209+ it ( "should only call the API one time with fetchAllBrands set to false" , async ( ) => {
1210+ requestMock . mockResolvedValueOnce ( { brands : [ brandSample ] , next_page : "next_page" } ) ;
1211+
1212+ await service . getBrands ( false ) ;
1213+
1214+ expect ( requestMock ) . toHaveBeenCalledTimes ( 1 ) ;
1215+ } ) ;
1216+ } ) ;
11701217} ) ;
0 commit comments