Skip to content

Commit

Permalink
test: add getProblem test (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sota810 authored Nov 28, 2024
1 parent 4ab79ee commit 46fd689
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions backend/src/api/paths/problem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,41 @@ describe("updateProblem", () => {
expect(response.status).toBe(404)
})
})

describe("getProblem", () => {
test("should retrieve a problem by ID", async () => {
const problem = await createProblem()
const response = await testClient(app).problems[":problemId"].$get({
param: {
problemId: problem.id.toString(),
},
})

expect(response.status).toBe(200)
if (response.status !== 200) return // type guard

const actual = await response.json()
expect(actual).toEqual({
body: problem.body,
id: problem.id,
supported_languages: problem.supportedLanguages.map(
({ languageName, languageVersion }) => ({
name: languageName,
version: languageVersion,
}),
),
test_cases: problem.testCases,
title: problem.title,
} satisfies typeof actual)
})

test("should return 404 if problem not found", async () => {
const problemCount = await prisma.problem.count()
const response = await testClient(app).problems[":problemId"].$get({
param: {
problemId: (problemCount + 1).toString(),
},
})
expect(response.status).toBe(404)
})
})

0 comments on commit 46fd689

Please sign in to comment.