Skip to content

Commit

Permalink
Update values.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewjordan committed Jul 22, 2024
1 parent 9d1c62d commit 2e6af8f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
25 changes: 12 additions & 13 deletions node/src/api/response/iiif/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,16 @@ async function buildCollection(responseBody, pageInfo) {
collectionSummary = "",
},
},
query_url,
} = pageInfo;

/**
* if the query_url pathname is `/collections` then we
* know this is a top-level "collection of collections"
*/
const { pathname } = new URL(query_url);
const isTopCollection = pathname.split("/").pop() === "collections";

let result = {
"@context": ["http://iiif.io/api/presentation/3/context.json"],
id: collectionId(pageInfo),
Expand All @@ -37,16 +45,15 @@ async function buildCollection(responseBody, pageInfo) {
summary: { none: [collectionSummary] },
homepage: [
{
id: homepageUrl(pageInfo),
id: isTopCollection ? dcUrl() : homepageUrl(pageInfo),
type: "Text",
format: "text/html",
label: {
none: [collectionLabel],
},
},
],

items: getItems(responseBody?.hits?.hits, pageInfo),
items: getItems(responseBody?.hits?.hits, pageInfo, isTopCollection),
};

if (pageInfo.options?.parameterOverrides) {
Expand All @@ -68,16 +75,8 @@ async function buildCollection(responseBody, pageInfo) {
return result;
}

function getItems(hits, pageInfo) {
/**
* If the queryUrl pathname is "/collections" then we know this
* is a top-level "collection of collections" and set itemType as
* "Collection". Otherwise, we know this is a collection of Manifests
*/
const queryUrl = new URL(pageInfo.query_url);
const pathname = queryUrl.pathname.split("/").pop();
const itemType = pathname === "collections" ? "Collection" : "Manifest";

function getItems(hits, pageInfo, isTopCollection) {
const itemType = isTopCollection ? "Collection" : "Manifest";
const items = hits.map((item) => loadItem(item["_source"], itemType));

if (pageInfo?.next_url) {
Expand Down
Empty file.
5 changes: 3 additions & 2 deletions node/src/handlers/get-collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ const getCollectionsAsIiif = async (event) => {
event.pathParameters.models = "collections";
event.body = { query: { match_all: {} } };
event.queryStringParameters.collectionLabel =
"Northwestern Digital Collections";
event.queryStringParameters.collectionSummary = "Something fancy";
"Northwestern University Libraries Digital Collections";
event.queryStringParameters.collectionSummary =
"Explore digital resources from the Northwestern University Library collections – including letters, photographs, diaries, maps, and audiovisual materials.";

return doSearch(event, {
includeToken: false,
Expand Down
6 changes: 4 additions & 2 deletions node/test/integration/get-collections.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ describe("Collections route", () => {
const resultBody = JSON.parse(result.body);
expect(resultBody.type).to.eq("Collection");
expect(resultBody.label.none[0]).to.eq(
"Northwestern Digital Collections"
"Northwestern University Libraries Digital Collections"
);
expect(resultBody.summary.none[0]).to.eq(
"Explore digital resources from the Northwestern University Library collections – including letters, photographs, diaries, maps, and audiovisual materials."
);
expect(resultBody.summary.none[0]).to.eq("Something fancy");
expect(resultBody.items.length).to.eq(69);
});
});
Expand Down
14 changes: 10 additions & 4 deletions node/test/unit/api/response/iiif/collection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ describe("IIIF Collection response for top level colllections", () => {
parameterOverrides: { as: "iiif" },
queryStringParameters: {
as: "iiif",
collectionLabel: "Northwestern Digital Collections",
collectionSummary: "Something fancy",
collectionLabel:
"Northwestern University Libraries Digital Collections",
collectionSummary:
"Explore digital resources from the Northwestern University Library collections – including letters, photographs, diaries, maps, and audiovisual materials.",
},
}
);
Expand All @@ -117,8 +119,12 @@ describe("IIIF Collection response for top level colllections", () => {

const body = JSON.parse(result.body);
expect(body.type).to.eq("Collection");
expect(body.label.none[0]).to.eq("Northwestern Digital Collections");
expect(body.summary.none[0]).to.eq("Something fancy");
expect(body.label.none[0]).to.eq(
"Northwestern University Libraries Digital Collections"
);
expect(body.summary.none[0]).to.eq(
"Explore digital resources from the Northwestern University Library collections – including letters, photographs, diaries, maps, and audiovisual materials."
);
expect(body.items.length).to.eq(69);
expect(body.items[0].type).to.eq("Collection");
});
Expand Down

0 comments on commit 2e6af8f

Please sign in to comment.