Skip to content

Commit

Permalink
CMR-10186: Handling case when collections query parameter is a comma …
Browse files Browse the repository at this point in the history
…separated string (#357)

* CMR-10186: Handling case when collections query parameter is a comma separated string

* CMR-10186: Fixing prettier issues
  • Loading branch information
william-valencia authored Oct 9, 2024
1 parent 2449123 commit a8db4bf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/domains/__tests__/stac.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions src/domains/stac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit a8db4bf

Please sign in to comment.