hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB0069847Burak Boduroğlu2 months ago552 commits
| 1 | import { api, configuredExamKind, contractBaseUrl, expectPage, isLive, json, loginAdmin, SKIP_MESSAGE } from "./helpers/live-client"; |
| 2 | |
| 3 | if (!isLive) console.warn(SKIP_MESSAGE); |
| 4 | |
| 5 | describe.skipIf(!isLive)(`learning contract @ ${contractBaseUrl}`, () => { |
| 6 | let courseId = ""; |
| 7 | let examId = ""; |
| 8 | |
| 9 | beforeAll(async () => { |
| 10 | await loginAdmin(); |
| 11 | const tag = `contract-learning-${Date.now()}`; |
| 12 | const course = await json<{ id: string; title: string; kind: string }>("/courses", { |
| 13 | method: "POST", |
| 14 | body: { title: tag, kind: "course" }, |
| 15 | }); |
| 16 | courseId = course.id; |
| 17 | expect(course).toMatchObject({ title: tag, kind: "course" }); |
| 18 | }); |
| 19 | |
| 20 | afterAll(async () => { |
| 21 | if (courseId) await api(`/courses/${courseId}`, { method: "DELETE" }); |
| 22 | }); |
| 23 | |
| 24 | // `/courses` takes limit/offset only — kind/term/search filtering is the |
| 25 | // caller's job, so this asserts the envelope, not a server-side filter. |
| 26 | it("returns courses through the standard page envelope", async () => { |
| 27 | const page = await json<{ items: Array<{ id: string }> }>(`/courses?limit=10`); |
| 28 | expectPage(page); |
| 29 | expect(page.items.some((course) => course.id === courseId)).toBe(true); |
| 30 | }); |
| 31 | |
| 32 | it("supports course subjects and exam-question lists", async () => { |
| 33 | const subject = await json<{ id: string; course: string }>(`/courses/${courseId}/subjects`, { |
| 34 | method: "POST", |
| 35 | body: { name: "contract subject" }, |
| 36 | }); |
| 37 | expect(subject.course).toBe(courseId); |
| 38 | |
| 39 | const examKind = await configuredExamKind(); |
| 40 | const exam = await json<{ id: string; course: string; draft: boolean }>(`/courses/${courseId}/exams`, { |
| 41 | method: "POST", |
| 42 | body: { title: "contract exam", kind: examKind, draft: true }, |
| 43 | }); |
| 44 | examId = exam.id; |
| 45 | expect(exam.course).toBe(courseId); |
| 46 | |
| 47 | const question = await json<{ id: string; exam: string }>(`/exams/${examId}/questions`, { |
| 48 | method: "POST", |
| 49 | body: { subject_id: subject.id, text: "Contract question", kind: "text", points: 1 }, |
| 50 | }); |
| 51 | expect(question.exam).toBe(examId); |
| 52 | expectPage(await json(`/exams/${examId}/questions?limit=10`)); |
| 53 | expectPage(await json(`/courses/${courseId}/exams?limit=10`)); |
| 54 | }); |
| 55 | }); |