Skip to content

Commit 864686c

Browse files
committed
feat: additional test coverage for resource methods
1 parent 864453a commit 864686c

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

packages/next-drupal/tests/NextDrupal/resource-methods.test.ts

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,25 @@ describe("getMenu()", () => {
281281
})
282282
)
283283
})
284+
285+
test("makes request with cache option", async () => {
286+
const drupal = new NextDrupal(BASE_URL)
287+
const mockInit = {
288+
cache: "no-store",
289+
} as FetchOptions
290+
291+
const fetchSpy = spyOnFetch()
292+
293+
await drupal.getMenu("main", mockInit)
294+
295+
expect(fetchSpy).toBeCalledTimes(1)
296+
expect(fetchSpy).toBeCalledWith(
297+
expect.anything(),
298+
expect.objectContaining({
299+
...mockInit,
300+
})
301+
)
302+
})
284303
})
285304

286305
describe("getResource()", () => {
@@ -853,6 +872,32 @@ describe("getResourceByPath()", () => {
853872
})
854873
)
855874
})
875+
876+
test("makes request with cache option", async () => {
877+
const drupal = new NextDrupal(BASE_URL)
878+
const mockInit = {
879+
cache: "no-store",
880+
} as FetchOptions
881+
882+
const fetchSpy = spyOnFetch({
883+
status: 207,
884+
statusText: "Multi-Status",
885+
responseBody: mocks.resources.subRequests.ok,
886+
})
887+
888+
await drupal.getResourceByPath<DrupalNode>(
889+
"/recipes/deep-mediterranean-quiche",
890+
mockInit
891+
)
892+
893+
expect(fetchSpy).toBeCalledTimes(1)
894+
expect(fetchSpy).toBeCalledWith(
895+
expect.anything(),
896+
expect.objectContaining({
897+
...mockInit,
898+
})
899+
)
900+
})
856901
})
857902

858903
describe("getResourceCollection()", () => {
@@ -980,6 +1025,25 @@ describe("getResourceCollection()", () => {
9801025
})
9811026
)
9821027
})
1028+
1029+
test("makes request with cache option", async () => {
1030+
const drupal = new NextDrupal(BASE_URL)
1031+
const mockInit = {
1032+
cache: "no-store",
1033+
} as FetchOptions
1034+
1035+
const fetchSpy = spyOnFetch()
1036+
1037+
await drupal.getResourceCollection("node--recipe", mockInit)
1038+
1039+
expect(fetchSpy).toBeCalledTimes(1)
1040+
expect(fetchSpy).toBeCalledWith(
1041+
expect.anything(),
1042+
expect.objectContaining({
1043+
...mockInit,
1044+
})
1045+
)
1046+
})
9831047
})
9841048

9851049
describe("getResourceCollectionPathSegments()", () => {
@@ -1139,6 +1203,27 @@ describe("getResourceCollectionPathSegments()", () => {
11391203
})
11401204
)
11411205
})
1206+
1207+
test("makes request with cache option", async () => {
1208+
const drupal = new NextDrupal(BASE_URL)
1209+
const mockInit = {
1210+
cache: "no-store",
1211+
} as FetchOptions
1212+
1213+
const fetchSpy = spyOnFetch({
1214+
responseBody: { data: [] },
1215+
})
1216+
1217+
await drupal.getResourceCollectionPathSegments("node--article", mockInit)
1218+
1219+
expect(fetchSpy).toBeCalledTimes(1)
1220+
expect(fetchSpy).toBeCalledWith(
1221+
expect.anything(),
1222+
expect.objectContaining({
1223+
...mockInit,
1224+
})
1225+
)
1226+
})
11421227
})
11431228

11441229
describe("getSearchIndex()", () => {
@@ -1269,6 +1354,25 @@ describe("getSearchIndex()", () => {
12691354
})
12701355
)
12711356
})
1357+
1358+
test("makes request with cache option", async () => {
1359+
const drupal = new NextDrupal(BASE_URL)
1360+
const mockInit = {
1361+
cache: "no-store",
1362+
} as FetchOptions
1363+
1364+
const fetchSpy = spyOnFetch()
1365+
1366+
await drupal.getSearchIndex("recipes", mockInit)
1367+
1368+
expect(fetchSpy).toBeCalledTimes(1)
1369+
expect(fetchSpy).toBeCalledWith(
1370+
expect.anything(),
1371+
expect.objectContaining({
1372+
...mockInit,
1373+
})
1374+
)
1375+
})
12721376
})
12731377

12741378
describe("getView()", () => {
@@ -1392,6 +1496,25 @@ describe("getView()", () => {
13921496
})
13931497
)
13941498
})
1499+
1500+
test("makes request with cache option", async () => {
1501+
const drupal = new NextDrupal(BASE_URL)
1502+
const mockInit = {
1503+
cache: "no-store",
1504+
} as FetchOptions
1505+
1506+
const fetchSpy = spyOnFetch()
1507+
1508+
await drupal.getView("featured_articles--page_1", mockInit)
1509+
1510+
expect(fetchSpy).toBeCalledTimes(1)
1511+
expect(fetchSpy).toBeCalledWith(
1512+
expect.anything(),
1513+
expect.objectContaining({
1514+
...mockInit,
1515+
})
1516+
)
1517+
})
13951518
})
13961519

13971520
describe("translatePath()", () => {
@@ -1501,4 +1624,23 @@ describe("translatePath()", () => {
15011624
})
15021625
)
15031626
})
1627+
1628+
test("makes request with cache option", async () => {
1629+
const drupal = new NextDrupal(BASE_URL)
1630+
const mockInit = {
1631+
cache: "no-store",
1632+
} as FetchOptions
1633+
1634+
const fetchSpy = spyOnFetch()
1635+
1636+
await drupal.translatePath("recipes/deep-mediterranean-quiche", mockInit)
1637+
1638+
expect(fetchSpy).toBeCalledTimes(1)
1639+
expect(fetchSpy).toBeCalledWith(
1640+
expect.anything(),
1641+
expect.objectContaining({
1642+
...mockInit,
1643+
})
1644+
)
1645+
})
15041646
})

0 commit comments

Comments
 (0)