Skip to content

Commit 784206b

Browse files
committed
test(next-drupal): fix "403 forbidden" jest failures
Fixes #603
1 parent 52a3c73 commit 784206b

File tree

3 files changed

+430
-25
lines changed

3 files changed

+430
-25
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ describe("getResource()", () => {
330330

331331
test("throws an error if revision access is forbidden", async () => {
332332
const drupal = new NextDrupal(BASE_URL)
333+
spyOnFetch({ responseBody: mocks.resources.node.forbidden, status: 403 })
333334

334335
await expect(
335336
drupal.getResource<DrupalNode>(
@@ -501,6 +502,10 @@ describe("getResourceByPath()", () => {
501502

502503
test("throws an error if revision access is forbidden", async () => {
503504
const drupal = new NextDrupal(BASE_URL)
505+
spyOnFetch({
506+
responseBody: mocks.resources.subRequests.forbidden,
507+
status: 207,
508+
})
504509

505510
await expect(
506511
drupal.getResourceByPath<DrupalNode>(

packages/next-drupal/tests/NextDrupalPages/pages-router-methods.test.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -889,29 +889,6 @@ describe("getResourceFromContext()", () => {
889889
)
890890
})
891891

892-
test("throws an error if revision access is forbidden", async () => {
893-
const drupal = new NextDrupalPages(BASE_URL)
894-
895-
const context: GetStaticPropsContext = {
896-
previewData: {
897-
resourceVersion: "id:1",
898-
},
899-
params: {
900-
slug: ["recipes", "deep-mediterranean-quiche"],
901-
},
902-
}
903-
904-
await expect(
905-
drupal.getResourceFromContext<DrupalNode>("node--recipe", context, {
906-
params: {
907-
"fields[node--recipe]": "title",
908-
},
909-
})
910-
).rejects.toThrow(
911-
"403 Forbidden\nThe current user is not allowed to GET the selected resource. The user does not have access to the requested version."
912-
)
913-
})
914-
915892
test("makes un-authenticated requests by default", async () => {
916893
const drupal = new NextDrupalPages(BASE_URL)
917894
const drupalFetchSpy = spyOnDrupalFetch(drupal)

0 commit comments

Comments
 (0)