Skip to content

Commit 7715c25

Browse files
added tests
1 parent 0d03209 commit 7715c25

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

src/routes/__tests__/browse.spec.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ describe("addQueryParametersToItemLink", () => {
177177
},
178178
]);
179179
});
180-
// test for issue CMR-11320
180+
// tests for issue CMR-11320
181+
// tests that q is filtered out
181182
it("filters out collection-only query parameters from the item link", async () => {
182183
const mockRequest = {
183184
method: "GET",
@@ -203,6 +204,42 @@ describe("addQueryParametersToItemLink", () => {
203204
},
204205
]);
205206
});
207+
// tests that the query parameters from list remain in link
208+
it("preserves all specified ITEM_QUERY_PARAMS", async () => {
209+
const originalQuery = [
210+
"datetime=2021-01-01T00:00:00.000Z",
211+
"bbox=-180,-90,180,90",
212+
"intersects=polygon_data",
213+
"query=cloud_cover<10",
214+
"limit=100",
215+
"sortby=-datetime",
216+
"fields=id,properties",
217+
].join("&");
218+
219+
const mockRequest = {
220+
method: "GET",
221+
originalUrl: `/stac/TEST_PROV/collections?${originalQuery}`,
222+
} as Request;
223+
224+
let stacCollection = generateSTACCollections(1)[0];
225+
stacCollection.links.push({
226+
rel: "items",
227+
href: "https://example.com/items",
228+
type: "application/geo+json",
229+
title: "Collection Items",
230+
});
231+
232+
addQueryParametersToItemLink(stacCollection, mockRequest);
233+
234+
expect(stacCollection).to.have.deep.property("links", [
235+
{
236+
rel: "items",
237+
href: `https://example.com/items?${originalQuery}`,
238+
type: "application/geo+json",
239+
title: "Collection Items",
240+
},
241+
]);
242+
});
206243
});
207244

208245
describe("generateBaseUrlForCollection for cloudstac/ALL", () => {

src/routes/browse.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,17 @@ export function addItemLinkIfNotPresent(collection: STACCollection, url: string)
198198
* @param collection the STAC Collection object containing links
199199
* @param req the incoming STAC request
200200
*/
201-
const ITEM_QUERY_PARAMS = ["datetime", "bbox", "intersects", "query", "limit", "sortby", "fields", "ids", "collections"];
201+
const ITEM_QUERY_PARAMS = [
202+
"datetime",
203+
"bbox",
204+
"intersects",
205+
"query",
206+
"limit",
207+
"sortby",
208+
"fields",
209+
"ids",
210+
"collections",
211+
];
202212

203213
export function addQueryParametersToItemLink(collection: STACCollection, req: Request) {
204214
const itemsLink = collection.links.find((link) => link.rel === "items");

0 commit comments

Comments
 (0)