Skip to content

Commit 1a7c242

Browse files
authored
Merge pull request #161 from nulib/3741-slider-view-all
Collection handle /similar endpoint
2 parents 7cc3b16 + fe40ceb commit 1a7c242

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/api/response/iiif/collection.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,19 @@ function homepageUrl(pageInfo) {
102102
result = new URL(`/collections/${collectionId}`, dcUrl());
103103
} else {
104104
result = new URL("/search", dcUrl());
105-
if (pageInfo.options?.queryStringParameters?.query)
105+
if (pageInfo.options?.queryStringParameters?.query) {
106106
result.searchParams.set(
107107
"q",
108108
pageInfo.options.queryStringParameters.query
109109
);
110+
}
111+
112+
if (pageInfo.query_url.includes("similar")) {
113+
// Grab the work id from the query_url and add it to the search params
114+
const regex = /works\/(.*)\/similar/;
115+
const found = pageInfo.query_url.match(regex);
116+
result.searchParams.set("similar", found[1]);
117+
}
110118
}
111119

112120
return result;

test/unit/api/response/iiif/collection.test.js

+27
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,31 @@ describe("IIIF Collection response transformer", () => {
5454
expect(body.status).to.eq(404);
5555
expect(body.error).to.be.a("string");
5656
});
57+
58+
it("handles a request including /similar route", async () => {
59+
let pagerWorkSimilar = new Paginator(
60+
"http://dcapi.library.northwestern.edu/api/v2/",
61+
"works/1234/similar",
62+
["works"],
63+
{ query: { query_string: { query: "genre.label:architecture" } } },
64+
"iiif",
65+
{
66+
includeToken: false,
67+
queryStringParameters: {
68+
collectionLabel: "The collection label",
69+
collectionSummary: "The collection Summary",
70+
},
71+
}
72+
);
73+
74+
const response = {
75+
statusCode: 200,
76+
body: helpers.testFixture("mocks/search.json"),
77+
};
78+
const result = await transformer.transform(response, pagerWorkSimilar);
79+
expect(result.statusCode).to.eq(200);
80+
81+
const body = JSON.parse(result.body);
82+
expect(body.homepage[0].id).to.contain("search?similar=1234");
83+
});
5784
});

0 commit comments

Comments
 (0)