Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DR-2443 Featured items endpoint #15

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ The following endpoints are currently available at http://localhost:3000/api/lan
- [/photographs](http://localhost:3000/api/lanes/photographs)
- [/prints-and-drawings](http://localhost:3000/api/lanes/prints-and-drawings)
- [/recently-digitized-collections](http://localhost:3000/api/lanes/recently-digitized-collections)
- [/items](http://localhost:3000/api/lanes/items)

### Individual Lane - GET /api/lanes/[...slug]

Expand Down Expand Up @@ -81,6 +82,12 @@ Returns respective JSON for that lane.

Returns JSON containing all lanes' metadata.

### Featured Items - GET /api/featuredItems

---

Returns JSON containing all featured items' image data.

#### Note for future

These endpoints will change (as DC homepage is built out) to be dynamically generated from another source instead of getting static data.
Expand Down
39 changes: 39 additions & 0 deletions __tests__/featureditems.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { getItemsData } from "@/pages/api/featuredItems";
import itemsDataHandler from "@/pages/api/featuredItems";
import { NextApiRequest } from "next";

describe("Featured items API endpoint handler", () => {
it("should respond with 200 status and items data for a GET request", () => {
const request: NextApiRequest = {
method: "GET",
} as NextApiRequest;

const mockResponse: any = {
status: jest.fn(function () {
return this;
}),
json: jest.fn(),
};

itemsDataHandler(request, mockResponse);

expect(mockResponse.status).toHaveBeenCalledWith(200);
expect(mockResponse.json).toHaveBeenCalledWith(getItemsData());
});

it("should respond with an error for non-GET requests", () => {
const request: NextApiRequest = {
method: "POST",
} as NextApiRequest;

const mockResponse: any = {
status: jest.fn(function () {
return this;
}),
};

itemsDataHandler(request, mockResponse);

expect(mockResponse.status).not.toHaveBeenCalledWith(200);
});
});
95 changes: 95 additions & 0 deletions src/data/featureditems.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"featuredItems": {
"images": [
"105180.jpg",
"105196.jpg",
"105224.jpg",
"105226.jpg",
"1108684.jpg",
"1161044.jpg",
"1161045.jpg",
"1221632.jpg",
"1260009.jpg",
"1269908.jpg",
"1536497.jpg",
"1536861.jpg",
"1549431.jpg",
"1557804.jpg",
"1558053.jpg",
"1657176.jpg",
"1693502.jpg",
"4000175.jpg",
"405476.jpg",
"417074.jpg",
"419720.jpg",
"433221.jpg",
"433223.jpg",
"434110.jpg",
"434408.jpg",
"464341.jpg",
"465012.jpg",
"482599.jpg",
"482603.jpg",
"482752.jpg",
"482815.jpg",
"483644.jpg",
"5013067.jpg",
"5082781.jpg",
"5086214.jpg",
"5104191.jpg",
"5131004.jpg",
"5150304.jpg",
"5164274.jpg",
"5164604.jpg",
"5164631.jpg",
"5179778.jpg",
"5179798.jpg",
"5180605.jpg",
"5273165.jpg",
"5339958.jpg",
"53926.jpg",
"54528.jpg",
"54795.jpg",
"700179F.jpg",
"79781.jpg",
"79849.jpg",
"836151.jpg",
"G91F075_038F.jpg",
"M_1260849.jpg",
"T000725.jpg",
"nypl_mss_901.jpg",
"ps_mss_831.jpg",
"ps_prn_cd31_456.jpg",
"ps_prn_cd32_461.jpg",
"psnypl_dan_1757.jpg",
"psnypl_mss_1228.jpg",
"psnypl_spn_610.jpg"
],
"noIndex": {
"images": [
"105069.jpg",
"1558052.jpg",
"1582228.jpg",
"435037.jpg",
"465016.jpg",
"482602.jpg",
"5002508.jpg",
"5013067.jpg",
"5086214.jpg",
"5164590.jpg",
"5164599.jpg",
"5164608.jpg",
"5316870.jpg",
"53901.jpg",
"87300.jpg",
"G91F380_080F.jpg",
"den_1409v.jpg",
"psnypl_the_4323.jpg",
"swope_246124.jpg",
"th-16090.jpg",
"trouvelot_003.jpg",
"trouvelot_010.jpg"
]
}
}
}
19 changes: 19 additions & 0 deletions src/pages/api/featuredItems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import itemsData from "@/data/featureditems.json";
import type { NextApiRequest, NextApiResponse } from "next";

export const getItemsData = () => {
return itemsData;
};

const itemsDataHandler = (
request: NextApiRequest,
response: NextApiResponse
) => {
const { method } = request;
if (method === "GET") {
return response.status(200).json(getItemsData());
}
};
export default itemsDataHandler;

// http://localhost:3000/api/featuredItems