Skip to content

Commit

Permalink
Merge pull request #161 from nulib/3741-slider-view-all
Browse files Browse the repository at this point in the history
Collection handle /similar endpoint
  • Loading branch information
adamjarling authored Aug 29, 2023
2 parents 7cc3b16 + fe40ceb commit 1a7c242
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/api/response/iiif/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,19 @@ function homepageUrl(pageInfo) {
result = new URL(`/collections/${collectionId}`, dcUrl());
} else {
result = new URL("/search", dcUrl());
if (pageInfo.options?.queryStringParameters?.query)
if (pageInfo.options?.queryStringParameters?.query) {
result.searchParams.set(
"q",
pageInfo.options.queryStringParameters.query
);
}

if (pageInfo.query_url.includes("similar")) {
// Grab the work id from the query_url and add it to the search params
const regex = /works\/(.*)\/similar/;
const found = pageInfo.query_url.match(regex);
result.searchParams.set("similar", found[1]);
}
}

return result;
Expand Down
27 changes: 27 additions & 0 deletions test/unit/api/response/iiif/collection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,31 @@ describe("IIIF Collection response transformer", () => {
expect(body.status).to.eq(404);
expect(body.error).to.be.a("string");
});

it("handles a request including /similar route", async () => {
let pagerWorkSimilar = new Paginator(
"http://dcapi.library.northwestern.edu/api/v2/",
"works/1234/similar",
["works"],
{ query: { query_string: { query: "genre.label:architecture" } } },
"iiif",
{
includeToken: false,
queryStringParameters: {
collectionLabel: "The collection label",
collectionSummary: "The collection Summary",
},
}
);

const response = {
statusCode: 200,
body: helpers.testFixture("mocks/search.json"),
};
const result = await transformer.transform(response, pagerWorkSimilar);
expect(result.statusCode).to.eq(200);

const body = JSON.parse(result.body);
expect(body.homepage[0].id).to.contain("search?similar=1234");
});
});

0 comments on commit 1a7c242

Please sign in to comment.