Skip to content

Commit

Permalink
Merge pull request #170 from nulib/deploy/staging
Browse files Browse the repository at this point in the history
Production push
  • Loading branch information
adamjarling authored Oct 10, 2023
2 parents f23d4c0 + e3fd2aa commit 199901c
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 5 deletions.
37 changes: 33 additions & 4 deletions src/api/response/iiif/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
function transform(response) {
if (response.statusCode === 200) {
const builder = new IIIFBuilder();

const openSearchResponse = JSON.parse(response.body);
const source = openSearchResponse._source;

Expand Down Expand Up @@ -198,10 +199,6 @@ function transform(response) {
]);
}

/** Add logo */

/** Add provider */

/** Add items (Canvases) from a Work's Filesets */
source.file_sets
.filter((fileSet) => fileSet.role === "Access")
Expand Down Expand Up @@ -259,6 +256,38 @@ function transform(response) {
}
}

/** Add logo manually (w/o IIIF Builder) */
const nulLogo = {
id: "https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000003/full/pct:50/0/default.webp",
type: "Image",
format: "image/webp",
height: 139,
width: 1190,
};
jsonManifest.logo = [nulLogo];

/** Add provider manually (w/o IIIF Builder) */
const provider = {
id: "https://www.library.northwestern.edu/",
type: "Agent",
label: { none: ["Northwestern University Libraries"] },
homepage: [
{
id: "https://dc.library.northwestern.edu/",
type: "Text",
label: {
none: [
"Northwestern University Libraries Digital Collections Homepage",
],
},
format: "text/html",
language: ["en"],
},
],
logo: [nulLogo],
};
jsonManifest.provider = [provider];

return {
statusCode: 200,
headers: {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function ensureCharacterEncoding(response, defaultEncoding = "UTF-8") {

if (!contentTypeHeader) {
contentTypeHeader = "Content-Type";
response[contentTypeHeader] ||= "application/json; charset=UTF-8";
response.headers[contentTypeHeader] ||= "application/json; charset=UTF-8";
}

const value = parseHeader(response.headers[contentTypeHeader]);
Expand Down
32 changes: 32 additions & 0 deletions test/unit/api/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
baseUrl,
decodeEventBody,
decodeToken,
ensureCharacterEncoding,
isFromReadingRoom,
maybeUseProxiedIp,
normalizeHeaders,
Expand Down Expand Up @@ -403,4 +404,35 @@ describe("helpers", () => {
expect(result.queryStringParameters).to.eql({});
});
});

describe("ensureCharacterEncoding", () => {
const response = { statusCode: 200, body: "Hello, World!" };

it("passes through an existing character set", () => {
const result = ensureCharacterEncoding({
...response,
headers: { "Content-Type": "text/plain; charset=ISO-8859-1" },
});
expect(result.headers["Content-Type"]).to.eql(
"text/plain; charset=ISO-8859-1"
);
});

it("adds character set if it's missing", () => {
const result = ensureCharacterEncoding({
...response,
headers: { "Content-Type": "text/plain" },
});
expect(result.headers["Content-Type"]).to.eql(
"text/plain; charset=UTF-8"
);
});

it("adds content type if it's missing", () => {
const result = ensureCharacterEncoding({ ...response, headers: {} });
expect(result.headers["Content-Type"]).to.eql(
"application/json; charset=UTF-8"
);
});
});
});
30 changes: 30 additions & 0 deletions test/unit/api/response/iiif/manifest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@ describe("Image Work as IIIF Manifest response transformer", () => {
expect(partOf.summary.none).to.be.an("array").that.is.not.empty;
});

it("populates Manifest logo", async () => {
const { manifest } = await setup();
const logo = manifest.logo[0];
expect(logo.id).to.eq(
"https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000003/full/pct:50/0/default.webp"
);
});

it("populates Manifest provider", async () => {
const { manifest } = await setup();
const provider = manifest.provider[0];
expect(provider.id).to.eq("https://www.library.northwestern.edu/");
expect(provider.label).to.deep.equal({
none: ["Northwestern University Libraries"],
});
expect(provider.homepage[0].id).to.eq(
"https://dc.library.northwestern.edu/"
);
expect(provider.homepage[0].label).to.deep.eq({
none: ["Northwestern University Libraries Digital Collections Homepage"],
});
expect(provider.logo[0]).to.deep.eq({
id: "https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000003/full/pct:50/0/default.webp",
type: "Image",
format: "image/webp",
height: 139,
width: 1190,
});
});

it("populates Manifest items (canvases)", async () => {
const { source, manifest } = await setup();
expect(manifest.items.length).to.eq(3);
Expand Down

0 comments on commit 199901c

Please sign in to comment.