Skip to content

Commit

Permalink
feat: additional test coverage for resource methods
Browse files Browse the repository at this point in the history
  • Loading branch information
backlineint committed Nov 19, 2024
1 parent 864453a commit 864686c
Showing 1 changed file with 142 additions and 0 deletions.
142 changes: 142 additions & 0 deletions packages/next-drupal/tests/NextDrupal/resource-methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()", () => {
Expand Down Expand Up @@ -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<DrupalNode>(
"/recipes/deep-mediterranean-quiche",
mockInit
)

expect(fetchSpy).toBeCalledTimes(1)
expect(fetchSpy).toBeCalledWith(
expect.anything(),
expect.objectContaining({
...mockInit,
})
)
})
})

describe("getResourceCollection()", () => {
Expand Down Expand Up @@ -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()", () => {
Expand Down Expand Up @@ -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()", () => {
Expand Down Expand Up @@ -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()", () => {
Expand Down Expand Up @@ -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()", () => {
Expand Down Expand Up @@ -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,
})
)
})
})

0 comments on commit 864686c

Please sign in to comment.