From a8db4bfe0d6c9286ce76bdee60a1982048936f20 Mon Sep 17 00:00:00 2001 From: william-valencia <51178394+william-valencia@users.noreply.github.com> Date: Wed, 9 Oct 2024 16:47:17 -0400 Subject: [PATCH] CMR-10186: Handling case when collections query parameter is a comma separated string (#357) * CMR-10186: Handling case when collections query parameter is a comma separated string * CMR-10186: Fixing prettier issues --- src/domains/__tests__/stac.spec.ts | 17 +++++++++++++++++ src/domains/stac.ts | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/src/domains/__tests__/stac.spec.ts b/src/domains/__tests__/stac.spec.ts index 118c97b3..a414ea67 100644 --- a/src/domains/__tests__/stac.spec.ts +++ b/src/domains/__tests__/stac.spec.ts @@ -573,6 +573,23 @@ describe("conversions to GraphQL", () => { }); }); + describe("given multiple collection identifiers as a comma separated string", () => { + it("should separate the entryIds properly", async () => { + expect( + await buildQuery({ + method: "GET", + url: "/stac/PROV/search", + headers: {}, + params: { providerId: "PROV" }, + query: { collections: "coll_v1,coll_v2" }, + } as any) + ).to.deep.equal({ + provider: "PROV", + entryId: ["coll_v1", "coll_v2"], + }); + }); + }); + describe("given an id as part of the path", () => { it("should not modify them", async () => { expect( diff --git a/src/domains/stac.ts b/src/domains/stac.ts index 9c0afcef..d9cd76dd 100644 --- a/src/domains/stac.ts +++ b/src/domains/stac.ts @@ -465,6 +465,12 @@ const collectionsQuery = async (req: Request, query: StacQuery): Promise<{ entry } = req; const cloudHosted = headers["cloud-stac"] === "true"; + // query.collections could be a comma separated string of multiple collections. + // Need to ensure this would be split out appropriately. + if (query.collections && !Array.isArray(query.collections)) { + query.collections = query.collections.split(","); + } + const collections = Array.isArray(query.collections) ? [...query.collections, collectionId] : [query.collections, collectionId];