Advertisement
Guest User

Untitled

a guest
May 2nd, 2019
107
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. email: 'solomon@gmail.com',
  22. password: 'solomon',
  23. id: 1 } */
  24. lecturer1 = admin.createNewLecturer(
  25. "ogbodo Izu",
  26. "mathematics",
  27. ["mth"],
  28. "solomon@gmail.com",
  29. "solomon"
  30. );
  31.  
  32.  
  33. lecturer2 = admin.createNewLecturer(
  34. "Treasure ogbonna",
  35. "political science",
  36. ["pol212", "soc222"],
  37. "tressy@gmail.com",
  38. "tressy"
  39. );
  40. expect(lecturer1).toBeTruthy();
  41. });
  42.  
  43. /*Return [ Course {
  44. title: 'Mth401',
  45. venue: 'AUD',
  46. startTime: '10am',
  47. endTime: '12pm',
  48. day: 'mon',
  49. userId: 1,
  50. id: 1,
  51. department: 'mathematics' },
  52. Course {
  53. title: 'Mth211',
  54. venue: 'AUD2',
  55. startTime: '8am',
  56. endTime: '10am',
  57. day: 'wed',
  58. userId: 1,
  59. id: 3,
  60. department: 'mathematics' } ]*/
  61. test("lecturer can create timetable", function() {
  62. timetable = lecturer1.createTimetable("Mth401", "AUD", "10am", "12pm", "mon");
  63. expect(timetable).toBeTruthy();
  64. });
  65.  
  66. /*Test to see if any lecturer can read only there own timetables*/
  67. test("Lecturer can read only all timetables belonging to him/her", function() {
  68. lecturer1.createTimetable("Mth211", "AUD2", "8am", "10am", "wed");
  69. expect(lecturer1.readAllTimetables()).toBeTruthy();
  70. });
  71.  
  72. /*Test to see if any lecturer can read only there own timetables by course title*/
  73. test("Lecturers can read their own timetables by course title", function() {
  74. expect(lecturer2.readTimetableByCourseTitle("Pol212")).toBeTruthy();
  75. });
  76.  
  77. /*Test to see that another lecture*/
  78. test("Lecturer cannot read others timetables", function() {
  79. expect(lecturer1.readTimetableByCourseTitle("Pol212")).toBeFalsy();
  80. });
  81.  
  82. /*Test to see if lecturer can read only there own timetables*/
  83. test("Lecturers can update their own timetables", function() {
  84. var timetableUpdate = ["Eng421", "LR66", "3pm", "5pm", "thursday"];
  85. expect(
  86. lecturer2.updateTimetable("Pol212", "4pm", "fri", timetableUpdate)
  87. ).toBeTruthy();
  88. });
  89.  
  90. /*Test to see what happends when a lecturer object want to update timetable with one or more missing input*/
  91. test("Lecturers trying to update their own timetables with one or more update data not inputed", function() {
  92. var timetableUpdate = ["MTH302", "AUD", "3pm", "5pm"];
  93. expect(
  94. lecturer1.updateTimetable("Mth401", "10am", "mon", timetableUpdate)
  95. ).toBeTruthy();
  96. });
  97.  
  98.  
  99. /*Check if a lecturer can update their timetable*/
  100. test("Lecturers cannot update others timetable", function() {
  101. var timetableUpdate = ["Eng421", "LR66", "3pm", "5pm", "thursday"];
  102. expect(
  103. lecturer1.updateTimetable("Pol212", "4pm", "fri", timetableUpdate)
  104. ).toBeFalsy();
  105. });
  106.  
  107. /*Test to see what happends when a lecturer object want to update timetable with one or more wrong input*/
  108. test("Lecturers trying to update their own timetables with one or more wrong needed data not inputed", function() {
  109. var timetableUpdate = ["Eng421", "LR66", "3pm", "5pm", "thursday"];
  110. expect(
  111. lecturer1.updateTimetable("Pol212", "4pm", timetableUpdate)
  112. ).toBeFalsy();
  113. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement