Skip to content

Commit 0b29457

Browse files
committed
✅add test for getSubjectList from all faculties
1 parent ce22d58 commit 0b29457

1 file changed

Lines changed: 31 additions & 13 deletions

File tree

src/index.test.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getFaculty, getFacultyList, getSubjectList } from ".";
2+
import { Subject } from './types'
23

34
describe("getFacultyList", () => {
45
it("should return list of faculties containing: code, name_en, name_th", () => {
@@ -33,19 +34,36 @@ describe("getFaculty", () => {
3334
});
3435

3536
describe("getSubject", () => {
36-
it("should return list of subjects containing: code, abbr, facultyCode, name, isClosed, openSemester and closeSemester", async () => {
37-
const subjectList = await 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");
37+
const facultyList = getFacultyList();
38+
const noSubjectFacultyCodeList = ["56", "58", "99", "01"];
39+
const filteredFacultyList = facultyList.filter((f)=>{
40+
return !noSubjectFacultyCodeList.includes(f.code);
41+
});
42+
filteredFacultyList.forEach((faculty) => {
43+
describe(`when getting subjects from facultyId ${faculty.code}`, () => {
44+
it(`should not be undefined`, async () => {
45+
const subjectList = await getSubjectList(faculty.code);
46+
expect(subjectList).not.toBeUndefined();
47+
});
48+
it("should return list of subjects with correct properties", async () => {
49+
const subjectList = await getSubjectList(faculty.code);
50+
if(subjectList === undefined) throw Error("subjectList is undefined");
51+
subjectList.forEach((s) => {
52+
expect(s).toHaveProperty("code");
53+
expect(s).toHaveProperty("abbr");
54+
expect(s).toHaveProperty("facultyCode");
55+
expect(s).toHaveProperty("name");
56+
expect(s).toHaveProperty("isClosed");
57+
expect(s).toHaveProperty("openSemester");
58+
expect(s).toHaveProperty("closeSemester");
59+
});
60+
});
4661
});
4762
});
48-
// TODO: All subject's code, codeName, facultyCode, name_en, name_th, openSemester should be string
49-
// TODO: closeSemester should be string or undefined
50-
// TODO: isClosed should be boolean and should be consistence to closeSemester
63+
describe(`when getting subjects from faculty with no subjects`, () => {
64+
it(`should return undefined`, async () => {
65+
const subjectList = await getSubjectList(noSubjectFacultyCodeList[0]);
66+
expect(subjectList).toBeUndefined();
67+
})
68+
})
5169
});

0 commit comments

Comments
 (0)