Skip to content

Commit

Permalink
Merge pull request #253 from NYPL/DR-3271/api-test-coverage
Browse files Browse the repository at this point in the history
DR-3271: API helper test coverage
  • Loading branch information
7emansell authored Dec 2, 2024
2 parents 3e628bb + 0ac2d4c commit b8e1327
Show file tree
Hide file tree
Showing 13 changed files with 783 additions and 172 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased


### Added

- Added tests for API helpers (DR-3271)


### Updated

- Update thumbnail logic so thumbnails are never restricted (DR-3293)


## [0.2.4] 2024-11-26

### Updated
Expand Down
295 changes: 295 additions & 0 deletions __tests__/__mocks__/data/mockApiResponses.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
export const mockFeaturedItemResponse = {
headers: { status: "success", code: "200", message: "ok" },
numResults: "1",
capture: {
uuid: "67b040f0-228a-0132-e62e-58d385a7b928",
imageLinks: {
imageLink: [
"http://images.nypl.org/index.php?id=5164604&t=t&download=1&suffix=67b040f0-228a-0132-e62e-58d385a7b928.001",
"http://images.nypl.org/index.php?id=5164604&t=f&download=1&suffix=67b040f0-228a-0132-e62e-58d385a7b928.001",
"http://images.nypl.org/index.php?id=5164604&t=b&download=1&suffix=67b040f0-228a-0132-e62e-58d385a7b928.001",
"http://images.nypl.org/index.php?id=5164604&t=r&download=1&suffix=67b040f0-228a-0132-e62e-58d385a7b928.001",
"http://images.nypl.org/index.php?id=5164604&t=q&download=1&suffix=67b040f0-228a-0132-e62e-58d385a7b928.001",
"http://images.nypl.org/index.php?id=5164604&t=v&download=1&suffix=67b040f0-228a-0132-e62e-58d385a7b928.001",
"http://images.nypl.org/index.php?id=5164604&t=g&download=1&suffix=67b040f0-228a-0132-e62e-58d385a7b928.001",
"http://images.nypl.org/index.php?id=5164604&t=w&download=1&suffix=67b040f0-228a-0132-e62e-58d385a7b928.001",
"http://images.nypl.org/index.php?id=5164604&t=s&download=1&suffix=67b040f0-228a-0132-e62e-58d385a7b928.001",
"http://images.nypl.org/index.php?id=5164604&t=j&download=1&suffix=67b040f0-228a-0132-e62e-58d385a7b928.001",
],
},
apiUri:
"http://api.repo.nypl.org/api/v2/items/mods/67b040f0-228a-0132-e62e-58d385a7b928",
typeOfResource: "still image",
imageID: "5164604",
sortString: "0000000001|0000000007|0000000014|0000000001",
itemLink:
"http://digitalcollections.nypl.org/items/67b040f0-228a-0132-e62e-58d385a7b928",
highResLink: "https://link.nypl.org/GyZyYkQfEeSTtU9llX1nUwH",
title: "Roadside sandwich shop. Ponchatoula, Louisiana",
dateDigitized: "2015-05-19T15:05:21Z",
rightsStatement:
'The New York Public Library believes that this item is in the public domain under the laws of the United States, but did not make a determination as to its copyright status under the copyright laws of other countries. This item may not be in the public domain under the laws of other countries. Though not required, if you want to credit us as the source, please use the following statement, "From The New York Public Library," and provide a link back to the item on our Digital Collections site. Doing so helps us track how our collection is used and helps justify freely releasing even more content in the future.',
rightsStatementURI: "http://rightsstatements.org/vocab/NoC-US/1.0/",
},
};

export const mockItemResponse = {
headers: {
status: {
$: "success",
},
code: {
$: "200",
},
message: {
$: "ok",
},
},
mods: {
version: "3.4",
schemaLocation:
"http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-4.xsd",
titleInfo: {
type: "",
authority: "",
usage: "primary",
supplied: "yes",
lang: "",
script: "",
title: {
$: "View of High Bridge and the Harlem River",
},
},
name: {
type: "personal",
authority: "naf",
valueURI: "http://id.loc.gov/authorities/names/n78047535",
usage: "primary",
namePart: {
$: "Bennett, W. J. (William James), 1787-1844",
},
role: {
roleTerm: [
{
valueURI: "http://id.loc.gov/vocabulary/relators/art",
authority: "marcrelator",
type: "code",
$: "art",
},
{
valueURI: "http://id.loc.gov/vocabulary/relators/art",
authority: "marcrelator",
type: "text",
$: "Artist",
},
],
},
},
typeOfResource: {
$: "still image",
},
genre: {
authority: "lctgm",
valueURI: "http://id.loc.gov/vocabulary/graphicMaterials/tgm003279",
$: "Drawings",
},
note: [
{
type: "citation/reference",
$: "Stokes 1844-E-131",
},
{
type: "citation/reference",
$: "Deák 526",
},
],
subject: [
{
topic: {
authority: "lcsh",
valueURI: "http://id.loc.gov/authorities/subjects/sh85016829",
$: "Bridges",
},
geographic: [
{
authority: "naf",
valueURI: "http://id.loc.gov/authorities/names/n80126293",
$: "New York (State)",
},
{
$: "New York",
},
],
},
{
authority: "lcsh",
valueURI: "http://id.loc.gov/authorities/subjects/sh88003387",
geographic: {
authority: "lcsh",
valueURI: "http://id.loc.gov/authorities/subjects/sh88003387",
$: "Harlem River (N.Y.)",
},
},
{
topic: {
authority: "lcsh",
valueURI:
"http://id.loc.gov/authorities/childrensSubjects/sj96005480",
$: "Fishing",
},
geographic: [
{
authority: "naf",
valueURI: "http://id.loc.gov/authorities/names/n80126293",
$: "New York (State)",
},
{
$: "New York",
},
],
},
],
identifier: [
{
type: "local_hades_collection",
displayLabel: "Hades Collection Guide ID (legacy)",
$: "190",
},
{
type: "local_hades",
displayLabel: "Hades struc ID (legacy)",
$: "118669",
},
{
type: "uuid",
$: "cfd3ac90-c5ed-012f-4b69-58d385a7bc34",
},
],
location: {
physicalLocation: [
{
authority: "marcorg",
type: "repository",
$: "nn",
},
{
type: "division",
$: "The Miriam and Ira D. Wallach Division of Art, Prints and Photographs: Print Collection",
},
{
type: "division_short_name",
$: "Wallach Division: Print Collection",
},
{
type: "code",
$: "PRN",
},
],
},
originInfo: {
dateCreated: {
encoding: "w3cdtf",
keyDate: "yes",
$: "1844",
},
},
physicalDescription: [
{
extent: {
$: "1 drawing ; 30.5 x 49.6 cm",
},
},
{
form: {
authority: "lctgm",
valueURI: "http://id.loc.gov/vocabulary/graphicMaterials/tgm011580",
$: "Watercolors",
},
},
],
relatedItem: {
type: "host",
titleInfo: {
title: {
$: "Individual prints, drawings, paintings and maps in the Stokes Collection.",
},
},
identifier: [
{
type: "uuid",
$: "0c284e10-c5ed-012f-a66d-58d385a7bc34",
},
{
type: "local_hades",
$: "607811",
},
],
relatedItem: {
type: "host",
titleInfo: {
title: {
$: "I. N. Phelps Stokes Collection of American Historical Prints",
},
},
identifier: [
{
type: "uuid",
$: "c901a3b0-c5ec-012f-9493-58d385a7bc34",
},
{
type: "local_hades",
$: "258154",
},
{
type: "local_hades_collection",
$: "190",
},
],
},
},
},
numResults: {
$: "1",
},
capture: {
uuid: {
$: "510d47d9-7c7c-a3d9-e040-e00a18064a99",
},
apiUri: {
$: "http://api.repo.nypl.org/api/v2/items/mods/510d47d9-7c7c-a3d9-e040-e00a18064a99",
},
typeOfResource: {
$: "still image",
},
imageID: {
$: "54795",
},
sortString: {
$: "0000000001|0000000011|0000000430|0000000001",
},
itemLink: {
$: "http://digitalcollections.nypl.org/items/510d47d9-7c7c-a3d9-e040-e00a18064a99",
},
highResLink: {
$: "https://link.nypl.org/3iIRPl9YEd2naebMmVbNCAA",
},
orderInSequence: {
$: "1",
},
isPartOfSequence: {
$: "true",
},
totalInSequence: {
$: "1",
},
title: {
$: "View of High Bridge and the Harlem River",
},
rightsStatement: {
$: 'The New York Public Library believes that this item is in the public domain under the laws of the United States, but did not make a determination as to its copyright status under the copyright laws of other countries. This item may not be in the public domain under the laws of other countries. Though not required, if you want to credit us as the source, please use the following statement, "From The New York Public Library," and provide a link back to the item on our Digital Collections site. Doing so helps us track how our collection is used and helps justify freely releasing even more content in the future.',
},
rightsStatementURI: {
$: "http://rightsstatements.org/vocab/NoC-US/1.0/",
},
},
};
2 changes: 1 addition & 1 deletion app/api/featuredItem/route.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextResponse, NextRequest } from "next/server";
import { getFeaturedItemData } from "@/src/utils/api";
import { getFeaturedItemData } from "@/src/utils/apiHelpers";
export const fetchCache = "force-no-store";

export const GET = async (request: NextRequest, response: NextResponse) => {
Expand Down
2 changes: 1 addition & 1 deletion app/api/homepage/route.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextResponse, NextRequest } from "next/server";
import { getHomePageData } from "@/src/utils/api";
import { getHomePageData } from "@/src/utils/apiHelpers";
export const fetchCache = "force-no-store";

export const GET = async (request: NextRequest, response: NextResponse) => {
Expand Down
2 changes: 1 addition & 1 deletion app/collections/lane/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Suspense } from "react";
import { Metadata } from "next";
import CollectionLanePage from "@/src/components/pages/collectionLanePage/collectionLanePage";
import { slugToString } from "@/src/utils/utils";
import { getLaneData } from "@/src/utils/api";
import { getLaneData } from "@/src/utils/apiHelpers";
import { redirect } from "next/navigation";

type LaneProps = {
Expand Down
2 changes: 1 addition & 1 deletion app/divisions/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Metadata } from "next";
import React from "react";
import DivisionPage from "../../src/components/pages/divisionPage/divisionPage";
import { slugToString } from "../../src/utils/utils";
import { getDivisionData } from "../../src/utils/api";
import { getDivisionData } from "../../src/utils/apiHelpers";
import { Suspense } from "react";
import { redirect } from "next/navigation";

Expand Down
2 changes: 1 addition & 1 deletion app/divisions/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Suspense } from "react";
import { Metadata } from "next";
import DivisionsPage from "../src/components/pages/divisionsPage/divisionsPage";
import { getDivisionData } from "@/src/utils/api";
import { getDivisionData } from "@/src/utils/apiHelpers";
import { redirect } from "next/navigation";

export const metadata: Metadata = {
Expand Down
2 changes: 1 addition & 1 deletion app/items/[uuid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { Metadata } from "next";
import PageLayout from "../../src/components/pageLayout/pageLayout";
import Item from "../../src/components/items/item";
import { getItemData } from "../../src/utils/api";
import { getItemData } from "../../src/utils/apiHelpers";
import { createAdobeAnalyticsPageName } from "../../src/utils/utils";
import { ItemModel } from "../../src/models/item";

Expand Down
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import HomePage from "./src/components/pages/homePage/homePage";
import { getHomePageData, getFeaturedItemData } from "@/src/utils/api";
import { getHomePageData, getFeaturedItemData } from "@/src/utils/apiHelpers";
import { FeaturedItemDataType } from "../app/src/types/FeaturedItemDataType";
import { revalidatePath } from "next/cache";

Expand Down
Loading

0 comments on commit b8e1327

Please sign in to comment.