Skip to content

Commit ccad648

Browse files
committed
✅add tests for getSubject and getSubjectList
1 parent 4279738 commit ccad648

1 file changed

Lines changed: 39 additions & 20 deletions

File tree

src/index.test.ts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { getFaculty, getFacultyList, getSubjectList } from ".";
2-
import { Subject } from "./types";
1+
import { getFaculty, getFacultyList, getSubject, getSubjectList } from ".";
32

43
describe("getFacultyList", () => {
54
it("should return list of faculties containing: code, name_en, name_th", () => {
@@ -33,24 +32,44 @@ describe("getFaculty", () => {
3332
});
3433
});
3534

35+
describe("getSubjectList", () => {
36+
it(`should return list of subjects containing correct properties`, () => {
37+
const subjectList = getSubjectList();
38+
subjectList.forEach((s) => {
39+
expect(s).toHaveProperty("code");
40+
expect(s).toHaveProperty("abbr");
41+
expect(s).toHaveProperty("facultyCode");
42+
expect(s).toHaveProperty("name");
43+
expect(s).toHaveProperty("isClosed");
44+
expect(s).toHaveProperty("openSemester");
45+
expect(s).toHaveProperty("closeSemester");
46+
});
47+
});
48+
});
49+
3650
describe("getSubject", () => {
37-
describe(`when getting subjects from facultyId`, () => {
38-
it(`should not be undefined`, async () => {
39-
const subjectList = await getSubjectList("");
40-
//expect(subjectList).not.toBeUndefined();
41-
}, 30000);
42-
// it("should return list of subjects with correct properties", async () => {
43-
// const subjectList = await getSubjectList("");
44-
// if (subjectList === undefined) throw Error("subjectList is undefined");
45-
// subjectList.forEach((s) => {
46-
// expect(s).toHaveProperty("code");
47-
// expect(s).toHaveProperty("abbr");
48-
// expect(s).toHaveProperty("facultyCode");
49-
// expect(s).toHaveProperty("name");
50-
// expect(s).toHaveProperty("isClosed");
51-
// expect(s).toHaveProperty("openSemester");
52-
// expect(s).toHaveProperty("closeSemester");
53-
// });
54-
// });
51+
it(`should return subject from the subject code specified`, () => {
52+
expect(getSubject("2000501")).toEqual({
53+
code: "2000501",
54+
facultyCode: "20",
55+
abbr: "CON PDG PEACE CONF",
56+
name: {
57+
en: "CONCEPTS AND PARADIGMS IN PEACE AND CONFLICT STUDIES",
58+
th: "มโนทัศน์และกระบวนทัศน์ในการศึกษาสันติภาพและความขัดแย้ง",
59+
},
60+
isClosed: false,
61+
openSemester: "1/2552",
62+
});
63+
expect(getSubject("2110413")).toEqual({
64+
code: "2110413",
65+
facultyCode: "21",
66+
abbr: "COMP SECURITY",
67+
name: {
68+
en: "COMPUTER SECURITY",
69+
th: "ความมั่นคงของคอมพิวเตอร์",
70+
},
71+
isClosed: false,
72+
openSemester: "2/2546",
73+
});
5574
});
5675
});

0 commit comments

Comments
 (0)