@@ -36,6 +36,9 @@ const getAssetWithVersion = require("../../testResources/download/resources/getA
3636// eslint-disable-next-line @typescript-eslint/no-var-requires
3737const getAssetWithoutVersion = require ( "../../testResources/download/resources/getAsset" ) ;
3838
39+ // eslint-disable-next-line @typescript-eslint/no-var-requires
40+ const getAssetWithMultipleVersionGroups = require ( "../../testResources/download/resources/getAssetWithMultipleVersionGroups.json" ) ;
41+
3942const REST_API : RestApi = {
4043 id : "8888888/test-api/1.0.0" ,
4144 name : "Test API" ,
@@ -249,15 +252,39 @@ describe("exchangeDownloader", () => {
249252 . undefined ;
250253 } ) ;
251254
252- it ( "should return undefined if the asset does not have a version" , async ( ) => {
255+ it ( "should return undefined if the asset does not have a version groups " , async ( ) => {
253256 const assetWithoutVersion = _ . cloneDeep ( getAssetWithoutVersion ) ;
254- delete assetWithoutVersion . version ;
257+ delete assetWithoutVersion . versionGroups ;
255258
256259 scope . get ( "/8888888/test-api" ) . reply ( 200 , assetWithoutVersion ) ;
257260
258261 return expect ( getApiVersions ( "AUTH_TOKEN" , REST_API ) ) . to . eventually . be
259262 . undefined ;
260263 } ) ;
264+
265+ it ( "should return latest versions from all the version groups" , async ( ) => {
266+ scope
267+ . get ( "/8888888/test-api" )
268+ . reply ( 200 , getAssetWithMultipleVersionGroups ) ;
269+
270+ return expect (
271+ getApiVersions ( "AUTH_TOKEN" , REST_API )
272+ ) . to . eventually . deep . equal ( [ "2.0.10" , "1.8.19" ] ) ;
273+ } ) ;
274+
275+ it ( "should return undefined if the version groups does not have a version" , async ( ) => {
276+ const assetWithoutVersion = _ . cloneDeep (
277+ getAssetWithMultipleVersionGroups
278+ ) ;
279+ delete assetWithoutVersion . versionGroups [ 0 ] . versions ;
280+ delete assetWithoutVersion . versionGroups [ 1 ] . versions ;
281+
282+ scope . get ( "/8888888/test-api" ) . reply ( 200 , assetWithoutVersion ) ;
283+
284+ return expect (
285+ getApiVersions ( "AUTH_TOKEN" , REST_API )
286+ ) . to . eventually . deep . equal ( [ ] ) ;
287+ } ) ;
261288 } ) ;
262289
263290 describe ( "getAsset" , ( ) => {
@@ -318,7 +345,7 @@ describe("exchangeDownloader", () => {
318345 . reply ( 200 , [ assetSearchResults [ 0 ] ] ) ;
319346 } ) ;
320347
321- it ( "searches Exchange and filters by deployment " , ( ) => {
348+ it ( "searches Exchange and filters by latest version " , ( ) => {
322349 scope
323350 . get ( "/shop-products-categories-api-v1" )
324351 . reply ( 200 , getAssetWithVersion )
@@ -327,6 +354,7 @@ describe("exchangeDownloader", () => {
327354
328355 return expect ( search ( "searchString" ) ) . to . eventually . deep . equal ( [
329356 shopperCustomersAsset ,
357+ shopperCustomersAsset ,
330358 ] ) ;
331359 } ) ;
332360
@@ -335,6 +363,21 @@ describe("exchangeDownloader", () => {
335363
336364 return expect ( search ( "searchString" ) ) . to . eventually . deep . equal ( [ ] ) ;
337365 } ) ;
366+
367+ it ( "searches Exchange and returns multiple version groupd" , ( ) => {
368+ scope
369+ . get ( "/shop-products-categories-api-v1" )
370+ . reply ( 200 , getAssetWithMultipleVersionGroups )
371+ . get ( "/shop-products-categories-api-v1/1.8.19" )
372+ . reply ( 200 , getAssetWithVersion )
373+ . get ( "/shop-products-categories-api-v1/2.0.10" )
374+ . reply ( 200 , getAssetWithVersion ) ;
375+
376+ return expect ( search ( "searchString" ) ) . to . eventually . deep . equal ( [
377+ shopperCustomersAsset ,
378+ shopperCustomersAsset ,
379+ ] ) ;
380+ } ) ;
338381 } ) ;
339382
340383 describe ( "runFetch" , ( ) => {
0 commit comments