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 c437af0 commit cd4085a
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions packages/next-drupal/tests/draft/draft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ describe("enableDraftMode()", () => {

const response = await enableDraftMode(request, drupal)

const draftModeStore = await draftMode()
expect(draftModeStore.enable).not.toHaveBeenCalled()
expect((await draftMode()).enable).not.toHaveBeenCalled()
expect(response).toBeInstanceOf(Response)
expect(response.status).toBe(500)
})
Expand All @@ -73,8 +72,7 @@ describe("enableDraftMode()", () => {

await enableDraftMode(request, drupal)

const draftModeStore = await draftMode()
expect(draftModeStore.enable).not.toHaveBeenCalled()
expect((await draftMode()).enable).not.toHaveBeenCalled()
})

test("updates draft mode cookie’s sameSite flag", async () => {
Expand Down Expand Up @@ -136,13 +134,12 @@ describe("disableDraftMode()", () => {
test("draft mode was disabled", async () => {
// First ensure draft mode is enabled.

const draftModeStore = await draftMode()
draftModeStore.enable()
expect(draftModeStore.isEnabled).toBe(true)
;(await draftMode()).enable()
expect((await draftMode()).isEnabled).toBe(true)

await disableDraftMode()
expect(draftModeStore.disable).toHaveBeenCalledTimes(1)
expect(draftModeStore.isEnabled).toBe(false)
expect((await draftMode()).disable).toHaveBeenCalledTimes(1)
expect((await draftMode()).isEnabled).toBe(false)
})

test("returns a response object", async () => {
Expand All @@ -168,24 +165,24 @@ describe("getDraftData()", () => {

test("returns empty object if draft mode disabled", async () => {
const cookieStore = await cookies()
const draftModeStore = await draftMode()
cookieStore.set(draftDataCookie)

const data = await getDraftData()
expect(draftModeStore.isEnabled).toBe(false)
expect((await draftMode()).isEnabled).toBe(false)
expect(cookieStore.has).toHaveBeenCalledTimes(0)
expect(cookieStore.get).toHaveBeenCalledTimes(0)
expect(data).toMatchObject({})
})

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

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

const data = await getDraftData()
expect(draftModeStore.isEnabled).toBe(true)
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)
Expand All @@ -194,16 +191,17 @@ describe("getDraftData()", () => {

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

cookiesStore.set({
...draftDataCookie,
value: "",
})
draftModeStore.enable()
;(await draftMode()).enable()
draftMode.mockClear()

const data = await getDraftData()
expect(draftModeStore.isEnabled).toBe(true)
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).toHaveBeenCalledWith(DRAFT_DATA_COOKIE_NAME)
Expand All @@ -213,10 +211,9 @@ describe("getDraftData()", () => {

test("returns the JSON.parse()d data", async () => {
const cookiesStore = await cookies()
const draftModeStore = await draftMode()

cookiesStore.set(draftDataCookie)
draftModeStore.enable()
;(await draftMode()).enable()

const draftDataReturn = await getDraftData()

Expand Down

0 comments on commit cd4085a

Please sign in to comment.