|
1 | 1 | import { getFaculty, getFacultyList, getSubjectList } from "."; |
| 2 | +import { Subject } from './types' |
2 | 3 |
|
3 | 4 | describe("getFacultyList", () => { |
4 | 5 | it("should return list of faculties containing: code, name_en, name_th", () => { |
@@ -33,19 +34,36 @@ describe("getFaculty", () => { |
33 | 34 | }); |
34 | 35 |
|
35 | 36 | 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 | + }); |
46 | 61 | }); |
47 | 62 | }); |
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 | + }) |
51 | 69 | }); |
0 commit comments