Skip to content

Commit

Permalink
fix: update tests to ignore TypeScript errors and fix route parameter…
Browse files Browse the repository at this point in the history
… naming
  • Loading branch information
ThomasGross committed Nov 20, 2024
1 parent eac067d commit 93b9d65
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion __tests__/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { expect, test, vi } from "vitest"
import { expect, test } from "vitest"

import goConfig from "@/lib/config/config"
import MissingConfigurationError from "@/lib/config/errors/MissingConfigurationError"

test("That an error is thrown if we ask for unknown config", async () => {
// @ts-ignore
expect(() => goConfig("unknown.thingy")).toThrowError(MissingConfigurationError)
})

Expand Down
5 changes: 5 additions & 0 deletions __tests__/refresh-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IronSession, getIronSession } from "iron-session"
import { testApiHandler } from "next-test-api-route-handler"
import { afterAll, beforeAll, beforeEach, expect, test, vi } from "vitest"

// @ts-ignore
import * as tokenRefreshHandler from "@/app/auth/token/refresh/route"
import { TSessionData, accessTokenShouldBeRefreshed } from "@/lib/session/session"

Expand All @@ -24,6 +25,7 @@ afterAll(() => {
})

beforeEach(() => {
// @ts-ignore
getIronSession.mockResolvedValue({
isLoggedIn: true,
})
Expand All @@ -41,6 +43,7 @@ const sessionThatShouldBeRefreshed = () => ({

test("That the refresh endpoint redirects to the frontpage if there is no active session", async () => {
// Simulate an anonymous session.
// @ts-ignore
getIronSession.mockResolvedValue({
isLoggedIn: false,
})
Expand All @@ -57,6 +60,7 @@ test("That the refresh endpoint redirects to the frontpage if there is no active

test("That the refresh endpoint redirects to the given endpoint after refreshing token", async () => {
// This is an authorized session that should be refreshed.
// @ts-ignore
getIronSession.mockResolvedValue(sessionThatShouldBeRefreshed())

await testApiHandler({
Expand All @@ -69,6 +73,7 @@ test("That the refresh endpoint redirects to the given endpoint after refreshing
})

// This is an authorized session that should NOT be refreshed.
// @ts-ignore
getIronSession.mockResolvedValue({
isLoggedIn: true,
expires: add(new Date(), { seconds: 300 }),
Expand Down
3 changes: 3 additions & 0 deletions __tests__/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const facets = {
} as const

beforeEach(() => {
// @ts-ignore
;(goConfig as jest.Mock).mockImplementation((key: string) => {
if (key === "search.item.limit") {
return 9 // Mocked return value for "search.item.limit"
Expand All @@ -49,6 +50,7 @@ beforeEach(() => {

describe("Facet functionality", () => {
it("getMachineNames should return all the facet machine names", () => {
// @ts-ignore
goConfig.mockReturnValue(facets)
const machineNames = getFacetMachineNames()
expect(machineNames).toStrictEqual([
Expand Down Expand Up @@ -109,6 +111,7 @@ describe("Facet functionality", () => {
})

it("getFacetTranslation should give a translated facet when given a facet machine name", () => {
// @ts-ignore
const translation = getFacetTranslation("LIX")
expect(translation).toBe("Lix")
})
Expand Down
6 changes: 3 additions & 3 deletions __tests__/url.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { expect, test, vi } from "vitest"
import { expect, test } from "vitest"

import { resolveUrl } from "../lib/helpers/helper.routes"

test("That resolveUrl can return a work url", async () => {
const workUrl = resolveUrl({ type: "work", routeParams: { id: 123 } })
const workUrl = resolveUrl({ type: "work", routeParams: { wid: 123 } })
expect(workUrl).toBe("/work/123")
})

test("That resolveUrl can return a work url with a manifestation type", async () => {
const workUrl = resolveUrl({
type: "work",
routeParams: { id: 123 },
routeParams: { wid: 123 },
queryParams: { audio: "true" },
})
expect(workUrl).toBe("/work/123?audio=true")
Expand Down

0 comments on commit 93b9d65

Please sign in to comment.