From 864686c371e0dd8c412898b65b1fe9355fc98adc Mon Sep 17 00:00:00 2001 From: Brian Perry Date: Tue, 19 Nov 2024 09:56:22 -0600 Subject: [PATCH] feat: additional test coverage for resource methods --- .../tests/NextDrupal/resource-methods.test.ts | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/packages/next-drupal/tests/NextDrupal/resource-methods.test.ts b/packages/next-drupal/tests/NextDrupal/resource-methods.test.ts index ecdf251f..7d1867b2 100644 --- a/packages/next-drupal/tests/NextDrupal/resource-methods.test.ts +++ b/packages/next-drupal/tests/NextDrupal/resource-methods.test.ts @@ -281,6 +281,25 @@ describe("getMenu()", () => { }) ) }) + + test("makes request with cache option", async () => { + const drupal = new NextDrupal(BASE_URL) + const mockInit = { + cache: "no-store", + } as FetchOptions + + const fetchSpy = spyOnFetch() + + await drupal.getMenu("main", mockInit) + + expect(fetchSpy).toBeCalledTimes(1) + expect(fetchSpy).toBeCalledWith( + expect.anything(), + expect.objectContaining({ + ...mockInit, + }) + ) + }) }) describe("getResource()", () => { @@ -853,6 +872,32 @@ describe("getResourceByPath()", () => { }) ) }) + + test("makes request with cache option", async () => { + const drupal = new NextDrupal(BASE_URL) + const mockInit = { + cache: "no-store", + } as FetchOptions + + const fetchSpy = spyOnFetch({ + status: 207, + statusText: "Multi-Status", + responseBody: mocks.resources.subRequests.ok, + }) + + await drupal.getResourceByPath( + "/recipes/deep-mediterranean-quiche", + mockInit + ) + + expect(fetchSpy).toBeCalledTimes(1) + expect(fetchSpy).toBeCalledWith( + expect.anything(), + expect.objectContaining({ + ...mockInit, + }) + ) + }) }) describe("getResourceCollection()", () => { @@ -980,6 +1025,25 @@ describe("getResourceCollection()", () => { }) ) }) + + test("makes request with cache option", async () => { + const drupal = new NextDrupal(BASE_URL) + const mockInit = { + cache: "no-store", + } as FetchOptions + + const fetchSpy = spyOnFetch() + + await drupal.getResourceCollection("node--recipe", mockInit) + + expect(fetchSpy).toBeCalledTimes(1) + expect(fetchSpy).toBeCalledWith( + expect.anything(), + expect.objectContaining({ + ...mockInit, + }) + ) + }) }) describe("getResourceCollectionPathSegments()", () => { @@ -1139,6 +1203,27 @@ describe("getResourceCollectionPathSegments()", () => { }) ) }) + + test("makes request with cache option", async () => { + const drupal = new NextDrupal(BASE_URL) + const mockInit = { + cache: "no-store", + } as FetchOptions + + const fetchSpy = spyOnFetch({ + responseBody: { data: [] }, + }) + + await drupal.getResourceCollectionPathSegments("node--article", mockInit) + + expect(fetchSpy).toBeCalledTimes(1) + expect(fetchSpy).toBeCalledWith( + expect.anything(), + expect.objectContaining({ + ...mockInit, + }) + ) + }) }) describe("getSearchIndex()", () => { @@ -1269,6 +1354,25 @@ describe("getSearchIndex()", () => { }) ) }) + + test("makes request with cache option", async () => { + const drupal = new NextDrupal(BASE_URL) + const mockInit = { + cache: "no-store", + } as FetchOptions + + const fetchSpy = spyOnFetch() + + await drupal.getSearchIndex("recipes", mockInit) + + expect(fetchSpy).toBeCalledTimes(1) + expect(fetchSpy).toBeCalledWith( + expect.anything(), + expect.objectContaining({ + ...mockInit, + }) + ) + }) }) describe("getView()", () => { @@ -1392,6 +1496,25 @@ describe("getView()", () => { }) ) }) + + test("makes request with cache option", async () => { + const drupal = new NextDrupal(BASE_URL) + const mockInit = { + cache: "no-store", + } as FetchOptions + + const fetchSpy = spyOnFetch() + + await drupal.getView("featured_articles--page_1", mockInit) + + expect(fetchSpy).toBeCalledTimes(1) + expect(fetchSpy).toBeCalledWith( + expect.anything(), + expect.objectContaining({ + ...mockInit, + }) + ) + }) }) describe("translatePath()", () => { @@ -1501,4 +1624,23 @@ describe("translatePath()", () => { }) ) }) + + test("makes request with cache option", async () => { + const drupal = new NextDrupal(BASE_URL) + const mockInit = { + cache: "no-store", + } as FetchOptions + + const fetchSpy = spyOnFetch() + + await drupal.translatePath("recipes/deep-mediterranean-quiche", mockInit) + + expect(fetchSpy).toBeCalledTimes(1) + expect(fetchSpy).toBeCalledWith( + expect.anything(), + expect.objectContaining({ + ...mockInit, + }) + ) + }) })