Skip to content

Commit

Permalink
fix(next-drupal)!: upgrade tests to new async request objects
Browse files Browse the repository at this point in the history
  • Loading branch information
yobottehg committed Dec 6, 2024
1 parent 8802691 commit e85ffb1
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions packages/next-drupal/tests/draft/draft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe("enableDraftMode()", () => {

await enableDraftMode(request, drupal)

expect((await draftMode()).enable).not.toHaveBeenCalled()
expect((await draftMode()).enable).toHaveBeenCalled()
})

test("updates draft mode cookie’s sameSite flag", async () => {
Expand Down Expand Up @@ -124,7 +124,7 @@ describe("disableDraftMode()", () => {
test("draft data cookie was deleted", async () => {
await disableDraftMode()

expect(await cookies()).toHaveBeenCalledTimes(1)
expect(cookies).toHaveBeenCalledTimes(1)
expect((await cookies()).delete).toHaveBeenCalledWith(
DRAFT_DATA_COOKIE_NAME
)
Expand Down Expand Up @@ -173,17 +173,15 @@ describe("getDraftData()", () => {
})

test("returns empty object if no draft data cookie", async () => {
const cookiesStore = await cookies()

;(await draftMode()).enable()
draftMode.mockClear()

const data = await getDraftData()
expect(draftMode).toHaveBeenCalledTimes(1)
expect((await draftMode()).isEnabled).toBe(true)
expect(cookiesStore.has).toHaveBeenCalledWith(DRAFT_DATA_COOKIE_NAME)
expect(cookiesStore.has).toHaveBeenCalledTimes(1)
expect(cookiesStore.get).toHaveBeenCalledTimes(0)
expect((await cookies()).has).toHaveBeenCalledWith(DRAFT_DATA_COOKIE_NAME)
expect((await cookies()).has).toHaveBeenCalledTimes(1)
expect((await cookies()).get).toHaveBeenCalledTimes(0)
expect(data).toMatchObject({})
})

Expand All @@ -209,8 +207,6 @@ describe("getDraftData()", () => {
;(await cookies()).set(draftDataCookie)
;(await draftMode()).enable()

const draftDataReturn = await getDraftData()

expect(draftDataReturn).toMatchObject(draftData)
expect(await getDraftData()).toMatchObject(draftData)
})
})

0 comments on commit e85ffb1

Please sign in to comment.