Skip to content

Commit 199901c

Browse files
authoredOct 10, 2023
Merge pull request #170 from nulib/deploy/staging
Production push
2 parents f23d4c0 + e3fd2aa commit 199901c

File tree

4 files changed

+96
-5
lines changed

4 files changed

+96
-5
lines changed
 

‎src/api/response/iiif/manifest.js

+33-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const {
1515
function transform(response) {
1616
if (response.statusCode === 200) {
1717
const builder = new IIIFBuilder();
18+
1819
const openSearchResponse = JSON.parse(response.body);
1920
const source = openSearchResponse._source;
2021

@@ -198,10 +199,6 @@ function transform(response) {
198199
]);
199200
}
200201

201-
/** Add logo */
202-
203-
/** Add provider */
204-
205202
/** Add items (Canvases) from a Work's Filesets */
206203
source.file_sets
207204
.filter((fileSet) => fileSet.role === "Access")
@@ -259,6 +256,38 @@ function transform(response) {
259256
}
260257
}
261258

259+
/** Add logo manually (w/o IIIF Builder) */
260+
const nulLogo = {
261+
id: "https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000003/full/pct:50/0/default.webp",
262+
type: "Image",
263+
format: "image/webp",
264+
height: 139,
265+
width: 1190,
266+
};
267+
jsonManifest.logo = [nulLogo];
268+
269+
/** Add provider manually (w/o IIIF Builder) */
270+
const provider = {
271+
id: "https://www.library.northwestern.edu/",
272+
type: "Agent",
273+
label: { none: ["Northwestern University Libraries"] },
274+
homepage: [
275+
{
276+
id: "https://dc.library.northwestern.edu/",
277+
type: "Text",
278+
label: {
279+
none: [
280+
"Northwestern University Libraries Digital Collections Homepage",
281+
],
282+
},
283+
format: "text/html",
284+
language: ["en"],
285+
},
286+
],
287+
logo: [nulLogo],
288+
};
289+
jsonManifest.provider = [provider];
290+
262291
return {
263292
statusCode: 200,
264293
headers: {

‎src/helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function ensureCharacterEncoding(response, defaultEncoding = "UTF-8") {
8888

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

9494
const value = parseHeader(response.headers[contentTypeHeader]);

‎test/unit/api/helpers.test.js

+32
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
baseUrl,
1212
decodeEventBody,
1313
decodeToken,
14+
ensureCharacterEncoding,
1415
isFromReadingRoom,
1516
maybeUseProxiedIp,
1617
normalizeHeaders,
@@ -403,4 +404,35 @@ describe("helpers", () => {
403404
expect(result.queryStringParameters).to.eql({});
404405
});
405406
});
407+
408+
describe("ensureCharacterEncoding", () => {
409+
const response = { statusCode: 200, body: "Hello, World!" };
410+
411+
it("passes through an existing character set", () => {
412+
const result = ensureCharacterEncoding({
413+
...response,
414+
headers: { "Content-Type": "text/plain; charset=ISO-8859-1" },
415+
});
416+
expect(result.headers["Content-Type"]).to.eql(
417+
"text/plain; charset=ISO-8859-1"
418+
);
419+
});
420+
421+
it("adds character set if it's missing", () => {
422+
const result = ensureCharacterEncoding({
423+
...response,
424+
headers: { "Content-Type": "text/plain" },
425+
});
426+
expect(result.headers["Content-Type"]).to.eql(
427+
"text/plain; charset=UTF-8"
428+
);
429+
});
430+
431+
it("adds content type if it's missing", () => {
432+
const result = ensureCharacterEncoding({ ...response, headers: {} });
433+
expect(result.headers["Content-Type"]).to.eql(
434+
"application/json; charset=UTF-8"
435+
);
436+
});
437+
});
406438
});

‎test/unit/api/response/iiif/manifest.test.js

+30
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,36 @@ describe("Image Work as IIIF Manifest response transformer", () => {
103103
expect(partOf.summary.none).to.be.an("array").that.is.not.empty;
104104
});
105105

106+
it("populates Manifest logo", async () => {
107+
const { manifest } = await setup();
108+
const logo = manifest.logo[0];
109+
expect(logo.id).to.eq(
110+
"https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000003/full/pct:50/0/default.webp"
111+
);
112+
});
113+
114+
it("populates Manifest provider", async () => {
115+
const { manifest } = await setup();
116+
const provider = manifest.provider[0];
117+
expect(provider.id).to.eq("https://www.library.northwestern.edu/");
118+
expect(provider.label).to.deep.equal({
119+
none: ["Northwestern University Libraries"],
120+
});
121+
expect(provider.homepage[0].id).to.eq(
122+
"https://dc.library.northwestern.edu/"
123+
);
124+
expect(provider.homepage[0].label).to.deep.eq({
125+
none: ["Northwestern University Libraries Digital Collections Homepage"],
126+
});
127+
expect(provider.logo[0]).to.deep.eq({
128+
id: "https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000003/full/pct:50/0/default.webp",
129+
type: "Image",
130+
format: "image/webp",
131+
height: 139,
132+
width: 1190,
133+
});
134+
});
135+
106136
it("populates Manifest items (canvases)", async () => {
107137
const { source, manifest } = await setup();
108138
expect(manifest.items.length).to.eq(3);

0 commit comments

Comments
 (0)
Please sign in to comment.