diff --git a/README.md b/README.md index 72be121f..81e3215e 100644 --- a/README.md +++ b/README.md @@ -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] @@ -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. diff --git a/__tests__/featureditems.test.tsx b/__tests__/featureditems.test.tsx new file mode 100644 index 00000000..af7786e3 --- /dev/null +++ b/__tests__/featureditems.test.tsx @@ -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); + }); +}); diff --git a/src/data/featureditems.json b/src/data/featureditems.json new file mode 100644 index 00000000..59a9b679 --- /dev/null +++ b/src/data/featureditems.json @@ -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" + ] + } + } +} diff --git a/src/pages/api/featuredItems.ts b/src/pages/api/featuredItems.ts new file mode 100644 index 00000000..2dfd189f --- /dev/null +++ b/src/pages/api/featuredItems.ts @@ -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