-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into UpdateSearchBar
- Loading branch information
Showing
10 changed files
with
164 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const data = [ | ||
{ id: "1", workTerm: "SPRING", workEnvironment: "REMOTE" }, | ||
{ id: "2", workTerm: "FALL", workEnvironment: "INPERSON" }, | ||
{ id: "3", workTerm: "SUMMER", workEnvironment: "HYBRID" }, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/unbound-method */ | ||
import { beforeEach, describe, expect, test, vi } from "vitest"; | ||
|
||
import type { Session } from "@cooper/auth"; | ||
import type { ReviewType } from "@cooper/db/schema"; | ||
import { and, eq } from "@cooper/db"; | ||
import { db } from "@cooper/db/client"; | ||
import { Review } from "@cooper/db/schema"; | ||
|
||
import { appRouter } from "../src/root"; | ||
import { createCallerFactory, createTRPCContext } from "../src/trpc"; | ||
import { data } from "./mocks/review"; | ||
|
||
vi.mock("@cooper/db/client", () => ({ | ||
db: { | ||
query: { | ||
Review: { | ||
findMany: vi.fn(), | ||
}, | ||
}, | ||
}, | ||
})); | ||
|
||
vi.mock("@cooper/auth", () => ({ | ||
auth: vi.fn(), | ||
})); | ||
|
||
describe("Review Router", async () => { | ||
beforeEach(() => { | ||
vi.restoreAllMocks(); | ||
vi.mocked(db.query.Review.findMany).mockResolvedValue(data as ReviewType[]); | ||
}); | ||
|
||
const session: Session = { | ||
user: { | ||
id: "1", | ||
}, | ||
expires: "1", | ||
}; | ||
|
||
const ctx = await createTRPCContext({ | ||
session, | ||
headers: new Headers(), | ||
}); | ||
|
||
const caller = createCallerFactory(appRouter)(ctx); | ||
|
||
test("list endpoint returns all reviews", async () => { | ||
const reviews = await caller.review.list({}); | ||
|
||
expect(reviews).toEqual(data); | ||
|
||
expect(db.query.Review.findMany).toHaveBeenCalledWith({ | ||
orderBy: expect.anything(), | ||
where: undefined, | ||
}); | ||
}); | ||
|
||
test("list endpoint with cycle filter", async () => { | ||
await caller.review.list({ | ||
options: { | ||
cycle: "SPRING", | ||
}, | ||
}); | ||
|
||
expect(db.query.Review.findMany).toHaveBeenCalledWith({ | ||
orderBy: expect.anything(), | ||
where: and(eq(Review.workTerm, "SPRING")), | ||
}); | ||
}); | ||
|
||
test("list endpoint with term filter", async () => { | ||
await caller.review.list({ | ||
options: { | ||
term: "REMOTE", | ||
}, | ||
}); | ||
|
||
expect(db.query.Review.findMany).toHaveBeenCalledWith({ | ||
orderBy: expect.anything(), | ||
where: and(eq(Review.workEnvironment, "REMOTE")), | ||
}); | ||
}); | ||
|
||
test("list endpoint with cycle and term filter", async () => { | ||
await caller.review.list({ | ||
options: { | ||
cycle: "SPRING", | ||
term: "REMOTE", | ||
}, | ||
}); | ||
|
||
expect(db.query.Review.findMany).toHaveBeenCalledWith({ | ||
orderBy: expect.anything(), | ||
where: and( | ||
eq(Review.workTerm, "SPRING"), | ||
eq(Review.workEnvironment, "REMOTE"), | ||
), | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters