Skip to content

Commit 124facb

Browse files
committed
Download multiple version groups
1 parent 3be05c7 commit 124facb

File tree

3 files changed

+3225
-13
lines changed

3 files changed

+3225
-13
lines changed

src/download/exchangeDownloader.test.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ const getAssetWithVersion = require("../../testResources/download/resources/getA
3636
// eslint-disable-next-line @typescript-eslint/no-var-requires
3737
const 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+
3942
const 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", () => {

src/download/exchangeDownloader.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,6 @@ export async function getApiVersions(
256256
return;
257257
}
258258

259-
if (!asset.version) {
260-
ramlToolLogger.error(
261-
`${logPrefix} The rest API ${restApi.assetId} is missing the asset.version`
262-
);
263-
return;
264-
}
265-
266259
if (!asset.versionGroups) {
267260
ramlToolLogger.error(
268261
`${logPrefix} The rest API ${restApi.assetId} is missing asset.versionGroups`
@@ -282,7 +275,7 @@ export async function getApiVersions(
282275
function getLatestReleaseVersion(versionGroup: {
283276
versions: Array<{ version: string }>;
284277
}): void | string {
285-
if (!versionGroup.versions) {
278+
if (!versionGroup.versions || versionGroup.versions.length === 0) {
286279
return;
287280
}
288281
const releaseAssetVersions = versionGroup.versions.filter((version) => {
@@ -335,18 +328,18 @@ export async function search(query: string): Promise<RestApi[]> {
335328
process.env.ANYPOINT_PASSWORD
336329
);
337330
const apis = await searchExchange(token, query);
331+
338332
const promises = apis.map(async (api) => {
339333
const versions = await getApiVersions(token, api);
340334
if (!versions || versions.length === 0) {
341335
return [];
342336
}
343337
const versionPromises = versions.map((version) => {
344-
console.log("api=", api.name, ",version=", version);
345338
return getSpecificApi(token, api.groupId, api.assetId, version);
346339
});
347-
348340
return Promise.all(versionPromises);
349341
});
342+
350343
return Promise.all(promises).then((results) =>
351344
results.reduce((acc, val) => acc.concat(val), [])
352345
);

0 commit comments

Comments
 (0)