forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBc35a83aBurak Boduroğlu4 months ago440 commits

learning.contract.test.ts53 lines, 2.0 KiBHistoryRawDownload
1import { api, configuredExamKind, contractBaseUrl, expectPage, isLive, json, loginAdmin, SKIP_MESSAGE } from "./helpers/live-client";
2
3if (!isLive) console.warn(SKIP_MESSAGE);
4
5describe.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 it("returns filtered courses through the standard page envelope", async () => {
25 const page = await json<{ items: Array<{ id: string }> }>(`/courses?kind=course&q=contract-learning&limit=10`);
26 expectPage(page);
27 expect(page.items.some((course) => course.id === courseId)).toBe(true);
28 });
29
30 it("supports course subjects and exam-question lists", async () => {
31 const subject = await json<{ id: string; course: string }>(`/courses/${courseId}/subjects`, {
32 method: "POST",
33 body: { name: "contract subject" },
34 });
35 expect(subject.course).toBe(courseId);
36
37 const examKind = await configuredExamKind();
38 const exam = await json<{ id: string; course: string; draft: boolean }>(`/courses/${courseId}/exams`, {
39 method: "POST",
40 body: { title: "contract exam", kind: examKind, draft: true },
41 });
42 examId = exam.id;
43 expect(exam.course).toBe(courseId);
44
45 const question = await json<{ id: string; exam: string }>(`/exams/${examId}/questions`, {
46 method: "POST",
47 body: { subject_id: subject.id, text: "Contract question", kind: "text", points: 1 },
48 });
49 expect(question.exam).toBe(examId);
50 expectPage(await json(`/exams/${examId}/questions?limit=10`));
51 expectPage(await json(`/courses/${courseId}/exams?limit=10`));
52 });
53});