Guest User

Untitled

a guest
May 2nd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. /*We need to import the Lecturer.js and Admin.js files to enable us test them accordingly*/
  2. const Lecturer = require("./Lecturer");
  3. const Admin = require("./Admin");
  4.  
  5. /*Create some global variables*/
  6. var admin, lecturer1, lecturer2, timetable;
  7.  
  8. /*create an admin object to enable us create lecturer objects*/
  9. test("create new admin user", function() {
  10. admin = new Admin("Admin1");
  11. expect(admin.name).toBe("Admin1");
  12. });
  13.  
  14. /*Ensure that an Admin objet can actually create a lecturer object*/
  15. test("Admin can create new lecturer", function() {
  16. /*Returns: Lecturer {
  17. name: 'ogbodo Izu',
  18. role: 'Lecturer',
  19. department: 'mathematics',
  20. courses: [ 'mth' ],
  21. password: 'solomon',
  22. id: 1 } */
  23. lecturer1 = admin.createNewLecturer(
  24. "ogbodo Izu",
  25. "mathematics",
  26. ["mth"],
  27. "solomon"
  28. );
  29.  
  30.  
  31. lecturer2 = admin.createNewLecturer(
  32. "Treasure ogbonna",
  33. "political science",
  34. ["pol212", "soc222"],
  35. "tressy"
  36. );
  37. expect(lecturer1).toBeTruthy();
  38. });
  39.  
  40. /*Return [ Course {
  41. title: 'Mth401',
  42. venue: 'AUD',
  43. startTime: '10am',
  44. endTime: '12pm',
  45. day: 'mon',
  46. userId: 1,
  47. id: 1,
  48. department: 'mathematics' },
  49. Course {
  50. title: 'Mth211',
  51. venue: 'AUD2',
  52. startTime: '8am',
  53. endTime: '10am',
  54. day: 'wed',
  55. userId: 1,
  56. id: 3,
  57. department: 'mathematics' } ]*/
  58. test("lecturer can create timetable", function() {
  59. timetable = lecturer1.createTimetable("Mth401", "AUD", "10am", "12pm", "mon");
  60. expect(timetable).toBeTruthy();
  61. });
  62.  
  63. /*Test to see if any lecturer can read only there own timetables*/
  64. test("Lecturer can read only all timetables belonging to him/her", function() {
  65. lecturer1.createTimetable("Mth211", "AUD2", "8am", "10am", "wed");
  66. expect(lecturer1.readAllTimetables()).toBeTruthy();
  67. });
  68.  
  69. /*Test to see if any lecturer can read only there own timetables by course title*/
  70. test("Lecturers can read their own timetables by course title", function() {
  71. expect(lecturer2.readTimetableByCourseTitle("Pol212")).toBeTruthy();
  72. });
  73.  
  74. /*Test to see that another lecture*/
  75. test("Lecturer cannot read others timetables", function() {
  76. expect(lecturer1.readTimetableByCourseTitle("Pol212")).toBeFalsy();
  77. });
  78.  
  79. /*Test to see if lecturer can read only there own timetables*/
  80. test("Lecturers can update their own timetables", function() {
  81. var timetableUpdate = ["Eng421", "LR66", "3pm", "5pm", "thursday"];
  82. expect(
  83. lecturer2.updateTimetable("Pol212", "4pm", "fri", timetableUpdate)
  84. ).toBeTruthy();
  85. });
  86.  
  87. /*Test to see what happends when a lecturer object want to update timetable with one or more missing input*/
  88. test("Lecturers trying to update their own timetables with one or more update data not inputed", function() {
  89. var timetableUpdate = ["MTH302", "AUD", "3pm", "5pm"];
  90. expect(
  91. lecturer1.updateTimetable("Mth401", "10am", "mon", timetableUpdate)
  92. ).toBeTruthy();
  93. });
  94.  
  95.  
  96. /*Check if a lecturer can update their timetable*/
  97. test("Lecturers cannot update others timetable", function() {
  98. var timetableUpdate = ["Eng421", "LR66", "3pm", "5pm", "thursday"];
  99. expect(
  100. lecturer1.updateTimetable("Pol212", "4pm", "fri", timetableUpdate)
  101. ).toBeFalsy();
  102. });
  103.  
  104. /*Test to see what happends when a lecturer object want to update timetable with one or more wrong input*/
  105. test("Lecturers trying to update their own timetables with one or more wrong needed data not inputed", function() {
  106. var timetableUpdate = ["Eng421", "LR66", "3pm", "5pm", "thursday"];
  107. expect(
  108. lecturer1.updateTimetable("Pol212", "4pm", timetableUpdate)
  109. ).toBeFalsy();
  110. });
Advertisement
Add Comment
Please, Sign In to add comment