Skip to content

Commit

Permalink
test(next-drupal): fix "403 forbidden" jest failures
Browse files Browse the repository at this point in the history
Fixes #603
  • Loading branch information
JohnAlbin committed Apr 14, 2024
1 parent abc1a0a commit 9856af9
Show file tree
Hide file tree
Showing 3 changed files with 430 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ describe("getResource()", () => {

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

await expect(
drupal.getResource<DrupalNode>(
Expand Down Expand Up @@ -495,6 +496,10 @@ describe("getResourceByPath()", () => {

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

await expect(
drupal.getResourceByPath<DrupalNode>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,29 +889,6 @@ describe("getResourceFromContext()", () => {
)
})

test("throws an error if revision access is forbidden", async () => {
const drupal = new NextDrupalPages(BASE_URL)

const context: GetStaticPropsContext = {
previewData: {
resourceVersion: "id:1",
},
params: {
slug: ["recipes", "deep-mediterranean-quiche"],
},
}

await expect(
drupal.getResourceFromContext<DrupalNode>("node--recipe", context, {
params: {
"fields[node--recipe]": "title",
},
})
).rejects.toThrow(
"403 Forbidden\nThe current user is not allowed to GET the selected resource. The user does not have access to the requested version."
)
})

test("makes un-authenticated requests by default", async () => {
const drupal = new NextDrupalPages(BASE_URL)
const drupalFetchSpy = spyOnDrupalFetch(drupal)
Expand Down
Loading

0 comments on commit 9856af9

Please sign in to comment.