diff --git a/__tests__/__mocks__/data/mockApiResponses.tsx b/__tests__/__mocks__/data/mockApiResponses.tsx index 54589e4e..d781a2cb 100644 --- a/__tests__/__mocks__/data/mockApiResponses.tsx +++ b/__tests__/__mocks__/data/mockApiResponses.tsx @@ -293,3 +293,456 @@ export const mockItemResponse = { }, }, }; + +export const mockCollectionsResponse = { + headers: { status: "success", code: "200", message: "ok" }, + numResults: "954924", + page: "1", + perPage: "40", + collection: [ + { + uuid: "60932400-20f2-0138-8583-05c43d448773", + title: "Posada Collection", + url: "https://digitalcollections.nypl.org/collections/posada-collection#/?tab=navigation", + imageID: "58270299", + numberOfDigitizedItems: 34, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "724303e0-c6bb-012f-afbd-58d385a7bc34", + title: "MAVO", + url: "https://digitalcollections.nypl.org/collections/mavo#/?tab=navigation", + imageID: null, + numberOfDigitizedItems: 35, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "6b6532b0-5df7-013b-36f8-0242ac110002", + title: "Austin Hansen photograph collection", + url: "https://digitalcollections.nypl.org/collections/austin-hansen-photograph-collection#/?tab=navigation", + imageID: "58300996", + numberOfDigitizedItems: 65, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "5b996640-c31c-0139-0bac-0242ac110004", + title: + "Arthur Alfonso Schomburg papers Arthur Alfonso Schomburg papers Arthur Alfonso Schomburg papers", + url: "https://digitalcollections.nypl.org/collections/arthur-alfonso-schomburg-papers#/?tab=navigation", + imageID: null, + numberOfDigitizedItems: 55, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "d3802d10-f49a-0139-3bff-0242ac110002", + title: "Friedman-Abeles photographs", + url: "https://digitalcollections.nypl.org/collections/friedman-abeles-photographs#/?tab=navigation", + imageID: "58498722", + numberOfDigitizedItems: 35, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "e5462600-c5d9-012f-a6a3-58d385a7bc34", + title: "Farm Security Administration Photographs", + url: "https://digitalcollections.nypl.org/collections/farm-security-administration-photographs#/?tab=navigation", + imageID: "1952272", + numberOfDigitizedItems: 36, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "812e5770-c60c-012f-7167-58d385a7bc34", + title: "Changing New York", + url: "https://digitalcollections.nypl.org/collections/changing-new-york#/?tab=navigation", + imageID: "58447105", + numberOfDigitizedItems: 37, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "f7ffc990-c5ae-012f-eb75-58d385a7bc34", + title: + "The Black Experience in Children's Books: Selections from Augusta Baker's Bibliographies", + url: "https://digitalcollections.nypl.org/collections/the-black-experience-in-childrens-books-selections-from-augusta-bakers#/?tab=about", + imageID: "56958645", + numberOfDigitizedItems: 153, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "60932400-20f2-0138-8583-05c43d448773", + title: "Posada Collection", + url: "https://digitalcollections.nypl.org/collections/posada-collection#/?tab=navigation", + imageID: "58270299", + numberOfDigitizedItems: 34, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "724303e0-c6bb-012f-afbd-58d385a7bc34", + title: "MAVO", + url: "https://digitalcollections.nypl.org/collections/mavo#/?tab=navigation", + imageID: null, + numberOfDigitizedItems: 35, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "6b6532b0-5df7-013b-36f8-0242ac110002", + title: "Austin Hansen photograph collection", + url: "https://digitalcollections.nypl.org/collections/austin-hansen-photograph-collection#/?tab=navigation", + imageID: "58300996", + numberOfDigitizedItems: 65, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "5b996640-c31c-0139-0bac-0242ac110004", + title: + "Arthur Alfonso Schomburg papers Arthur Alfonso Schomburg papers Arthur Alfonso Schomburg papers", + url: "https://digitalcollections.nypl.org/collections/arthur-alfonso-schomburg-papers#/?tab=navigation", + imageID: null, + numberOfDigitizedItems: 55, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "d3802d10-f49a-0139-3bff-0242ac110002", + title: "Friedman-Abeles photographs", + url: "https://digitalcollections.nypl.org/collections/friedman-abeles-photographs#/?tab=navigation", + imageID: "58498722", + numberOfDigitizedItems: 35, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "e5462600-c5d9-012f-a6a3-58d385a7bc34", + title: "Farm Security Administration Photographs", + url: "https://digitalcollections.nypl.org/collections/farm-security-administration-photographs#/?tab=navigation", + imageID: "1952272", + numberOfDigitizedItems: 36, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "812e5770-c60c-012f-7167-58d385a7bc34", + title: "Changing New York", + url: "https://digitalcollections.nypl.org/collections/changing-new-york#/?tab=navigation", + imageID: "58447105", + numberOfDigitizedItems: 37, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "f7ffc990-c5ae-012f-eb75-58d385a7bc34", + title: + "The Black Experience in Children's Books: Selections from Augusta Baker's Bibliographies", + url: "https://digitalcollections.nypl.org/collections/the-black-experience-in-childrens-books-selections-from-augusta-bakers#/?tab=about", + imageID: "56958645", + numberOfDigitizedItems: 153, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "60932400-20f2-0138-8583-05c43d448773", + title: "Posada Collection", + url: "https://digitalcollections.nypl.org/collections/posada-collection#/?tab=navigation", + imageID: "58270299", + numberOfDigitizedItems: 34, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "724303e0-c6bb-012f-afbd-58d385a7bc34", + title: "MAVO", + url: "https://digitalcollections.nypl.org/collections/mavo#/?tab=navigation", + imageID: null, + numberOfDigitizedItems: 35, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "6b6532b0-5df7-013b-36f8-0242ac110002", + title: "Austin Hansen photograph collection", + url: "https://digitalcollections.nypl.org/collections/austin-hansen-photograph-collection#/?tab=navigation", + imageID: "58300996", + numberOfDigitizedItems: 65, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "5b996640-c31c-0139-0bac-0242ac110004", + title: + "Arthur Alfonso Schomburg papers Arthur Alfonso Schomburg papers Arthur Alfonso Schomburg papers", + url: "https://digitalcollections.nypl.org/collections/arthur-alfonso-schomburg-papers#/?tab=navigation", + imageID: null, + numberOfDigitizedItems: 55, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "d3802d10-f49a-0139-3bff-0242ac110002", + title: "Friedman-Abeles photographs", + url: "https://digitalcollections.nypl.org/collections/friedman-abeles-photographs#/?tab=navigation", + imageID: "58498722", + numberOfDigitizedItems: 35, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "e5462600-c5d9-012f-a6a3-58d385a7bc34", + title: "Farm Security Administration Photographs", + url: "https://digitalcollections.nypl.org/collections/farm-security-administration-photographs#/?tab=navigation", + imageID: "1952272", + numberOfDigitizedItems: 36, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "812e5770-c60c-012f-7167-58d385a7bc34", + title: "Changing New York", + url: "https://digitalcollections.nypl.org/collections/changing-new-york#/?tab=navigation", + imageID: "58447105", + numberOfDigitizedItems: 37, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "f7ffc990-c5ae-012f-eb75-58d385a7bc34", + title: + "The Black Experience in Children's Books: Selections from Augusta Baker's Bibliographies", + url: "https://digitalcollections.nypl.org/collections/the-black-experience-in-childrens-books-selections-from-augusta-bakers#/?tab=about", + imageID: "56958645", + numberOfDigitizedItems: 153, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "60932400-20f2-0138-8583-05c43d448773", + title: "Posada Collection", + url: "https://digitalcollections.nypl.org/collections/posada-collection#/?tab=navigation", + imageID: "58270299", + numberOfDigitizedItems: 34, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "724303e0-c6bb-012f-afbd-58d385a7bc34", + title: "MAVO", + url: "https://digitalcollections.nypl.org/collections/mavo#/?tab=navigation", + imageID: null, + numberOfDigitizedItems: 35, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "6b6532b0-5df7-013b-36f8-0242ac110002", + title: "Austin Hansen photograph collection", + url: "https://digitalcollections.nypl.org/collections/austin-hansen-photograph-collection#/?tab=navigation", + imageID: "58300996", + numberOfDigitizedItems: 65, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "5b996640-c31c-0139-0bac-0242ac110004", + title: + "Arthur Alfonso Schomburg papers Arthur Alfonso Schomburg papers Arthur Alfonso Schomburg papers", + url: "https://digitalcollections.nypl.org/collections/arthur-alfonso-schomburg-papers#/?tab=navigation", + imageID: null, + numberOfDigitizedItems: 55, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "d3802d10-f49a-0139-3bff-0242ac110002", + title: "Friedman-Abeles photographs", + url: "https://digitalcollections.nypl.org/collections/friedman-abeles-photographs#/?tab=navigation", + imageID: "58498722", + numberOfDigitizedItems: 35, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "e5462600-c5d9-012f-a6a3-58d385a7bc34", + title: "Farm Security Administration Photographs", + url: "https://digitalcollections.nypl.org/collections/farm-security-administration-photographs#/?tab=navigation", + imageID: "1952272", + numberOfDigitizedItems: 36, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "812e5770-c60c-012f-7167-58d385a7bc34", + title: "Changing New York", + url: "https://digitalcollections.nypl.org/collections/changing-new-york#/?tab=navigation", + imageID: "58447105", + numberOfDigitizedItems: 37, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "f7ffc990-c5ae-012f-eb75-58d385a7bc34", + title: + "The Black Experience in Children's Books: Selections from Augusta Baker's Bibliographies", + url: "https://digitalcollections.nypl.org/collections/the-black-experience-in-childrens-books-selections-from-augusta-bakers#/?tab=about", + imageID: "56958645", + numberOfDigitizedItems: 153, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "60932400-20f2-0138-8583-05c43d448773", + title: "Posada Collection", + url: "https://digitalcollections.nypl.org/collections/posada-collection#/?tab=navigation", + imageID: "58270299", + numberOfDigitizedItems: 34, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "724303e0-c6bb-012f-afbd-58d385a7bc34", + title: "MAVO", + url: "https://digitalcollections.nypl.org/collections/mavo#/?tab=navigation", + imageID: null, + numberOfDigitizedItems: 35, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "6b6532b0-5df7-013b-36f8-0242ac110002", + title: "Austin Hansen photograph collection", + url: "https://digitalcollections.nypl.org/collections/austin-hansen-photograph-collection#/?tab=navigation", + imageID: "58300996", + numberOfDigitizedItems: 65, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "5b996640-c31c-0139-0bac-0242ac110004", + title: + "Arthur Alfonso Schomburg papers Arthur Alfonso Schomburg papers Arthur Alfonso Schomburg papers", + url: "https://digitalcollections.nypl.org/collections/arthur-alfonso-schomburg-papers#/?tab=navigation", + imageID: null, + numberOfDigitizedItems: 55, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "d3802d10-f49a-0139-3bff-0242ac110002", + title: "Friedman-Abeles photographs", + url: "https://digitalcollections.nypl.org/collections/friedman-abeles-photographs#/?tab=navigation", + imageID: "58498722", + numberOfDigitizedItems: 35, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "e5462600-c5d9-012f-a6a3-58d385a7bc34", + title: "Farm Security Administration Photographs", + url: "https://digitalcollections.nypl.org/collections/farm-security-administration-photographs#/?tab=navigation", + imageID: "1952272", + numberOfDigitizedItems: 36, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "812e5770-c60c-012f-7167-58d385a7bc34", + title: "Changing New York", + url: "https://digitalcollections.nypl.org/collections/changing-new-york#/?tab=navigation", + imageID: "58447105", + numberOfDigitizedItems: 37, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "f7ffc990-c5ae-012f-eb75-58d385a7bc34", + title: + "The Black Experience in Children's Books: Selections from Augusta Baker's Bibliographies", + url: "https://digitalcollections.nypl.org/collections/the-black-experience-in-childrens-books-selections-from-augusta-bakers#/?tab=about", + imageID: "56958645", + numberOfDigitizedItems: 153, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "60932400-20f2-0138-8583-05c43d448773", + title: "Posada Collection", + url: "https://digitalcollections.nypl.org/collections/posada-collection#/?tab=navigation", + imageID: "58270299", + numberOfDigitizedItems: 34, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "724303e0-c6bb-012f-afbd-58d385a7bc34", + title: "MAVO", + url: "https://digitalcollections.nypl.org/collections/mavo#/?tab=navigation", + imageID: null, + numberOfDigitizedItems: 35, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "6b6532b0-5df7-013b-36f8-0242ac110002", + title: "Austin Hansen photograph collection", + url: "https://digitalcollections.nypl.org/collections/austin-hansen-photograph-collection#/?tab=navigation", + imageID: "58300996", + numberOfDigitizedItems: 65, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "5b996640-c31c-0139-0bac-0242ac110004", + title: + "Arthur Alfonso Schomburg papers Arthur Alfonso Schomburg papers Arthur Alfonso Schomburg papers", + url: "https://digitalcollections.nypl.org/collections/arthur-alfonso-schomburg-papers#/?tab=navigation", + imageID: null, + numberOfDigitizedItems: 55, + containsOnSiteMaterials: true, + containsAVMaterial: false, + }, + { + uuid: "d3802d10-f49a-0139-3bff-0242ac110002", + title: "Friedman-Abeles photographs", + url: "https://digitalcollections.nypl.org/collections/friedman-abeles-photographs#/?tab=navigation", + imageID: "58498722", + numberOfDigitizedItems: 35, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "e5462600-c5d9-012f-a6a3-58d385a7bc34", + title: "Farm Security Administration Photographs", + url: "https://digitalcollections.nypl.org/collections/farm-security-administration-photographs#/?tab=navigation", + imageID: "1952272", + numberOfDigitizedItems: 36, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "812e5770-c60c-012f-7167-58d385a7bc34", + title: "Changing New York", + url: "https://digitalcollections.nypl.org/collections/changing-new-york#/?tab=navigation", + imageID: "58447105", + numberOfDigitizedItems: 37, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + { + uuid: "f7ffc990-c5ae-012f-eb75-58d385a7bc34", + title: + "The Black Experience in Children's Books: Selections from Augusta Baker's Bibliographies", + url: "https://digitalcollections.nypl.org/collections/the-black-experience-in-childrens-books-selections-from-augusta-bakers#/?tab=about", + imageID: "56958645", + numberOfDigitizedItems: 153, + containsOnSiteMaterials: false, + containsAVMaterial: false, + }, + ], +}; diff --git a/app/src/utils/apiHelpers.test.tsx b/app/src/utils/apiHelpers.test.tsx index 56c0cf6c..462eda27 100644 --- a/app/src/utils/apiHelpers.test.tsx +++ b/app/src/utils/apiHelpers.test.tsx @@ -15,6 +15,7 @@ import defaultFeaturedItem from "../data/defaultFeaturedItemData"; import { mockFeaturedItemResponse, mockItemResponse, + mockCollectionsResponse, } from "__tests__/__mocks__/data/mockApiResponses"; jest.mock("./fetchApi"); @@ -371,18 +372,42 @@ describe("getItemData", () => { }); }); -// describe("getCollectionsData", () => { -// it("returns expected results", async () => { -// (fetchApi as jest.Mock).mockResolvedValueOnce( -// Promise.resolve(getCollectionsData) -// ); -// const collections = await getCollectionsData("uuid1"); -// expect(fetchApi as jest.Mock).toHaveBeenCalledWith( -// `${process.env.API_URL}/api/v2/collections?page=1&per_page=48&sort=&q=` -// ); - -// expect(collections).toEqual(mockPaginatedCollections); -// expect(collections).toHaveProperty("capture"); -// expect(collections).toHaveProperty("mods"); -// }); -// }); +describe("getCollectionsData", () => { + it("returns expected results", async () => { + (fetchApi as jest.Mock).mockResolvedValueOnce( + Promise.resolve(mockCollectionsResponse) + ); + const collections = await getCollectionsData({ + keyword: "cat", + sortID: "date-asc", + pageNum: "2", + }); + + expect(fetchApi as jest.Mock).toHaveBeenCalledWith( + `${process.env.API_URL}/api/v2/collections?page=2&per_page=48&sort=date ASC&q=cat` + ); + + expect(collections).toEqual(mockCollectionsResponse); + expect(collections).toHaveProperty("collection"); + expect(collections).toHaveProperty("perPage"); + expect(collections).toHaveProperty("page"); + expect(collections).toHaveProperty("numResults"); + }); + + it("returns default search when given no params", async () => { + (fetchApi as jest.Mock).mockResolvedValueOnce( + Promise.resolve(mockCollectionsResponse) + ); + const collections = await getCollectionsData(); + + expect(fetchApi as jest.Mock).toHaveBeenCalledWith( + `${process.env.API_URL}/api/v2/collections?page=1&per_page=48&sort=date DESC&q=` + ); + + expect(collections).toEqual(mockCollectionsResponse); + expect(collections).toHaveProperty("collection"); + expect(collections).toHaveProperty("perPage"); + expect(collections).toHaveProperty("page"); + expect(collections).toHaveProperty("numResults"); + }); +});