Skip to content

Commit

Permalink
test(next-drupal): replace @ts-ignore with @ts-expect-error
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnAlbin committed Apr 18, 2024
1 parent c9ae778 commit 9556704
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 25 deletions.
10 changes: 9 additions & 1 deletion packages/next-drupal/tests/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
{
"files": ["*.test.ts"],
"rules": {
"@typescript-eslint/ban-ts-comment": "off"
"@typescript-eslint/ban-ts-comment": [
"error",
{
"ts-expect-error": false,
"ts-ignore": true,
"ts-nocheck": true,
"ts-check": false
}
]
}
}
]
Expand Down
8 changes: 5 additions & 3 deletions packages/next-drupal/tests/NextDrupal/basic-methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ describe("deserialize()", () => {
test("allows for custom data serializer", async () => {
const deserializer: JsonDeserializer = (
body: { data: { id: string; attributes: { title: string } } },
options: { pathPrefix: string }
options: { titlePrefix: string }
) => {
return {
id: body.data.id,
title: `${options.pathPrefix}: ${body.data.attributes.title}`,
title:
(options.titlePrefix ? `${options.titlePrefix}: ` : "") +
body.data.attributes.title,
}
}
const drupal = new NextDrupal(BASE_URL, {
Expand All @@ -71,7 +73,7 @@ describe("deserialize()", () => {
expect(response.status).toBe(200)
const json = await response.json()
const article = drupal.deserialize(json, {
pathPrefix: "TITLE",
titlePrefix: "TITLE",
}) as DrupalNode

expect(article).toMatchSnapshot()
Expand Down
2 changes: 2 additions & 0 deletions packages/next-drupal/tests/NextDrupal/constructor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jest.mock("jsona", () => {
})

beforeEach(() => {
// @ts-expect-error
Jsona.mockClear()
})

Expand Down Expand Up @@ -108,6 +109,7 @@ describe("options parameter", () => {
expect(Jsona).toBeCalledTimes(1)

const deserializeMock = new Jsona().deserialize
// @ts-expect-error
deserializeMock.mockClear()
const args: Parameters<JsonDeserializer> = [{}, { options: true }]
drupal.deserialize(...args)
Expand Down
20 changes: 11 additions & 9 deletions packages/next-drupal/tests/NextDrupalBase/constructor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ describe("baseUrl parameter", () => {
})

test("throws error given an invalid baseUrl", () => {
// @ts-ignore
expect(() => new NextDrupalBase()).toThrow(
"The 'baseUrl' param is required."
)

// @ts-ignore
expect(() => new NextDrupalBase({})).toThrow(
"The 'baseUrl' param is required."
)
expect(
() =>
// @ts-expect-error
new NextDrupalBase()
).toThrow("The 'baseUrl' param is required.")

expect(
() =>
// @ts-expect-error
new NextDrupalBase({})
).toThrow("The 'baseUrl' param is required.")
})

test("announces debug mode when turned on", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ describe("getAccessToken()", () => {

await expect(
drupal.getAccessToken(
// @ts-ignore
// @ts-expect-error
{ clientId: clientIdSecret.clientId }
)
).rejects.toThrow(errorMessage)
Expand Down Expand Up @@ -563,7 +563,7 @@ describe("getAuthorizationHeader()", () => {

await expect(
drupal.getAuthorizationHeader(
// @ts-ignore
// @ts-expect-error
auth
)
).rejects.toThrow(
Expand Down
22 changes: 14 additions & 8 deletions packages/next-drupal/tests/NextDrupalBase/getters-setters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("auth", () => {
test("missing username", () => {
expect(() => {
const drupal = new NextDrupalBase(BASE_URL)
// @ts-ignore
// @ts-expect-error
drupal.auth = {
password: "password",
}
Expand All @@ -46,7 +46,7 @@ describe("auth", () => {
test("missing password", () => {
expect(() => {
const drupal = new NextDrupalBase(BASE_URL)
// @ts-ignore
// @ts-expect-error
drupal.auth = {
username: "admin",
}
Expand All @@ -60,7 +60,7 @@ describe("auth", () => {
test("missing access_token", () => {
expect(() => {
const drupal = new NextDrupalBase(BASE_URL)
// @ts-ignore
// @ts-expect-error
drupal.auth = {
token_type: mocks.auth.accessToken.token_type,
}
Expand All @@ -72,7 +72,7 @@ describe("auth", () => {
test("missing token_type", () => {
expect(() => {
const drupal = new NextDrupalBase(BASE_URL)
// @ts-ignore
// @ts-expect-error
drupal.auth = {
access_token: mocks.auth.accessToken.access_token,
}
Expand All @@ -86,7 +86,7 @@ describe("auth", () => {
test("missing clientId", () => {
expect(() => {
const drupal = new NextDrupalBase(BASE_URL)
// @ts-ignore
// @ts-expect-error
drupal.auth = {
clientSecret: mocks.auth.clientIdSecret.clientSecret,
}
Expand All @@ -98,7 +98,7 @@ describe("auth", () => {
test("missing clientSecret", () => {
expect(() => {
const drupal = new NextDrupalBase(BASE_URL)
// @ts-ignore
// @ts-expect-error
drupal.auth = {
clientId: mocks.auth.clientIdSecret.clientId,
}
Expand Down Expand Up @@ -258,7 +258,13 @@ describe("token", () => {
const after = getExpiresOn(accessToken)

expect(drupal.token).toBe(accessToken)
expect(drupal._tokenExpiresOn).toBeGreaterThanOrEqual(before)
expect(drupal._tokenExpiresOn).toBeLessThanOrEqual(after)
expect(
// @ts-expect-error
drupal._tokenExpiresOn
).toBeGreaterThanOrEqual(before)
expect(
// @ts-expect-error
drupal._tokenExpiresOn
).toBeLessThanOrEqual(after)
})
})
10 changes: 8 additions & 2 deletions packages/next-drupal/tests/NextDrupalPages/constructor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ describe("options parameter", () => {
describe("serializer", () => {
test("defaults to `new Jsona()`", () => {
const drupal = new NextDrupalPages(BASE_URL)
expect(drupal.serializer).toBeInstanceOf(Jsona)
expect(
// @ts-expect-error
drupal.serializer
).toBeInstanceOf(Jsona)
})

test("sets up a custom serializer", () => {
Expand All @@ -37,7 +40,10 @@ describe("options parameter", () => {
const drupal = new NextDrupalPages(BASE_URL, {
serializer: customSerializer,
})
expect(drupal.serializer).toBe(customSerializer)
expect(
// @ts-expect-error
drupal.serializer
).toBe(customSerializer)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ describe("preview()", () => {
// Get values from our mocked request.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { path, resourceVersion, plugin, secret, ...draftData } =
// @ts-expect-error
new NextApiRequest().query
const dataCookie = `${DRAFT_DATA_COOKIE_NAME}=${encodeURIComponent(
JSON.stringify({ path, resourceVersion, ...draftData })
Expand All @@ -1130,7 +1131,9 @@ describe("preview()", () => {
}

test("turns on preview mode and clears preview data", async () => {
// @ts-expect-error
const request = new NextApiRequest()
// @ts-expect-error
const response = new NextApiResponse()
const drupal = new NextDrupalPages(BASE_URL)
spyOnFetch({ responseBody: validationPayload })
Expand All @@ -1147,7 +1150,9 @@ describe("preview()", () => {

test("does not enable preview mode if validation fails", async () => {
const logger = mockLogger()
// @ts-expect-error
const request = new NextApiRequest()
// @ts-expect-error
const response = new NextApiResponse()
const drupal = new NextDrupalPages(BASE_URL, { debug: true, logger })
const status = 403
Expand All @@ -1171,7 +1176,9 @@ describe("preview()", () => {
})

test("does not turn on draft mode by default", async () => {
// @ts-expect-error
const request = new NextApiRequest()
// @ts-expect-error
const response = new NextApiResponse()
const drupal = new NextDrupalPages(BASE_URL)
spyOnFetch({ responseBody: validationPayload })
Expand All @@ -1186,7 +1193,9 @@ describe("preview()", () => {
})

test("optionally turns on draft mode", async () => {
// @ts-expect-error
const request = new NextApiRequest()
// @ts-expect-error
const response = new NextApiResponse()
const logger = mockLogger()
const drupal = new NextDrupalPages(BASE_URL, {
Expand All @@ -1208,7 +1217,9 @@ describe("preview()", () => {
})

test("updates preview mode cookie’s sameSite flag", async () => {
// @ts-expect-error
const request = new NextApiRequest()
// @ts-expect-error
const response = new NextApiResponse()
const drupal = new NextDrupalPages(BASE_URL)
spyOnFetch({ responseBody: validationPayload })
Expand All @@ -1232,7 +1243,9 @@ describe("preview()", () => {
})

test("redirects to the given path", async () => {
// @ts-expect-error
const request = new NextApiRequest()
// @ts-expect-error
const response = new NextApiResponse()
const logger = mockLogger()
const drupal = new NextDrupalPages(BASE_URL, { debug: true, logger })
Expand All @@ -1250,7 +1263,9 @@ describe("preview()", () => {
})

test("returns a 422 response on error", async () => {
// @ts-expect-error
const request = new NextApiRequest()
// @ts-expect-error
const response = new NextApiResponse()
const logger = mockLogger()
const drupal = new NextDrupalPages(BASE_URL, { debug: true, logger })
Expand All @@ -1269,7 +1284,9 @@ describe("preview()", () => {

describe("previewDisable()", () => {
test("clears preview data", async () => {
// @ts-expect-error
const request = new NextApiRequest()
// @ts-expect-error
const response = new NextApiResponse()
const drupal = new NextDrupalPages(BASE_URL)

Expand All @@ -1278,7 +1295,9 @@ describe("previewDisable()", () => {
})

test("disables draft mode", async () => {
// @ts-expect-error
const request = new NextApiRequest()
// @ts-expect-error
const response = new NextApiResponse()
const drupal = new NextDrupalPages(BASE_URL)

Expand All @@ -1287,7 +1306,9 @@ describe("previewDisable()", () => {
})

test("deletes the draft cookie", async () => {
// @ts-expect-error
const request = new NextApiRequest()
// @ts-expect-error
const response = new NextApiResponse()
const drupal = new NextDrupalPages(BASE_URL)

Expand All @@ -1299,7 +1320,9 @@ describe("previewDisable()", () => {
})

test('redirects to "/"', async () => {
// @ts-expect-error
const request = new NextApiRequest()
// @ts-expect-error
const response = new NextApiResponse()
const drupal = new NextDrupalPages(BASE_URL)

Expand Down

0 comments on commit 9556704

Please sign in to comment.