github.com/quickfeed/quickfeed@v0.0.0-20240507093252-ed8ca812a09c/public/src/__tests__/mock_data/mockData.ts (about)

     1  /* eslint-disable no-unused-vars */
     2  import {
     3      Course,
     4      Enrollment,
     5      Enrollments,
     6      GradingBenchmark,
     7      GradingCriterion,
     8      Group,
     9      Groups,
    10      Review,
    11      Submission,
    12      Submissions,
    13      User,
    14      Assignment,
    15      Enrollment_UserStatus,
    16      Group_GroupStatus,
    17      Submission_Status,
    18      GradingCriterion_Grade,
    19      Enrollment_DisplayState,
    20  } from "../../../proto/qf/types_pb"
    21  import {
    22      Organization,
    23  } from "../../../proto/qf/requests_pb"
    24  import { BuildInfo, Score } from "../../../proto/kit/score/score_pb"
    25  import { Timestamp } from "@bufbuild/protobuf"
    26  
    27  export class MockData {
    28      public static mockedUsers(): User[] {
    29          const userList: User[] = []
    30          userList.push(
    31              new User({
    32                  ID: BigInt(1),
    33                  Name: "Test Testersen",
    34                  Email: "test@testersen.no",
    35                  Login: "Test User",
    36                  StudentID: "9999",
    37                  IsAdmin: true,
    38              })
    39          )
    40  
    41          userList.push(
    42              new User({
    43                  ID: BigInt(2),
    44                  Name: "Admin Admin",
    45                  Email: "admin@admin",
    46                  Login: "Admin",
    47                  StudentID: "1000",
    48                  IsAdmin: true,
    49              })
    50          )
    51  
    52          userList.push(
    53              new User({
    54                  ID: BigInt(3),
    55                  Name: "Test Student",
    56                  Email: "test@student.no",
    57                  Login: "Student",
    58                  AvatarURL: "https://avatars0.githubusercontent.com/u/1?v=4",
    59                  IsAdmin: false,
    60              })
    61          )
    62  
    63          userList.push(
    64              new User({
    65                  ID: BigInt(4),
    66                  Name: "Bob Bobsen",
    67                  Email: "bob@bobsen.no",
    68                  Login: "Bob",
    69                  StudentID: "1234",
    70                  IsAdmin: true,
    71              })
    72          )
    73  
    74          userList.push(
    75              new User({
    76                  ID: BigInt(5),
    77                  Name: "Petter Pan",
    78                  Email: "petter@pan.no",
    79                  StudentID: "2345",
    80                  IsAdmin: false,
    81              })
    82          )
    83          return userList
    84      }
    85  
    86      public static mockedAssignments(): Assignment[] {
    87          const ts = Timestamp.fromDate(new Date(2017, 5, 25))
    88          const a0 = new Assignment()
    89          const a1 = new Assignment()
    90          const a2 = new Assignment()
    91          const a3 = new Assignment()
    92          const a4 = new Assignment()
    93          const a5 = new Assignment()
    94          const a6 = new Assignment()
    95          const a7 = new Assignment()
    96          const a8 = new Assignment()
    97          const a9 = new Assignment()
    98          const a10 = new Assignment()
    99  
   100          a0.ID = BigInt(1)
   101          a0.CourseID = BigInt(1)
   102          a0.name = "Lab 1"
   103          a0.deadline = ts
   104          a0.scoreLimit = 80
   105          a0.order = 1
   106  
   107          a1.ID = BigInt(2)
   108          a1.CourseID = BigInt(1)
   109          a1.name = ("Lab 2")
   110          a1.deadline = ts
   111          a1.scoreLimit = 80
   112          a1.order = 2
   113  
   114          a2.ID = BigInt(3)
   115          a2.CourseID = BigInt(1)
   116          a2.name = "Lab 3"
   117          a2.reviewers = 1
   118          a2.deadline = ts
   119          a2.scoreLimit = 60
   120          a2.order = 3
   121  
   122          a3.ID = BigInt(4)
   123          a3.CourseID = BigInt(1)
   124          a3.name = "Lab 4"
   125          a3.deadline = ts
   126          a3.scoreLimit = 75
   127          a3.order = 4
   128          a3.isGroupLab = true
   129  
   130          a4.ID = BigInt(5)
   131          a4.CourseID = BigInt(2)
   132          a4.name = "Lab 1"
   133          a4.deadline = ts
   134          a4.scoreLimit = 90
   135          a4.order = 1
   136  
   137          a5.ID = BigInt(6)
   138          a5.CourseID = BigInt(2)
   139          a5.name = "Lab 2"
   140          a5.deadline = ts
   141          a5.scoreLimit = 85
   142          a5.order = 2
   143  
   144          a6.ID = BigInt(7)
   145          a6.CourseID = BigInt(2)
   146          a6.name = "Lab 3"
   147          a6.deadline = ts
   148          a6.scoreLimit = 80
   149          a6.order = 3
   150  
   151          a7.ID = BigInt(8)
   152          a7.CourseID = BigInt(3)
   153          a7.name = "Lab 1"
   154          a7.deadline = ts
   155          a7.scoreLimit = 90
   156          a7.order = 1
   157  
   158          a8.ID = BigInt(9)
   159          a8.CourseID = BigInt(3)
   160          a8.name = "Lab 2"
   161          a8.deadline = ts
   162          a8.scoreLimit = 85
   163          a8.order = 2
   164  
   165          a9.ID = BigInt(10)
   166          a9.CourseID = BigInt(4)
   167          a9.name = "Lab 1"
   168          a9.deadline = ts
   169          a9.scoreLimit = 90
   170          a9.order = 1
   171  
   172          a10.ID = BigInt(11)
   173          a10.CourseID = BigInt(5)
   174          a10.name = "Lab 1"
   175          a10.deadline = ts
   176          a10.scoreLimit = 90
   177          a10.order = 1
   178  
   179          return [a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]
   180      }
   181  
   182      public static mockedCourses() {
   183          const course0 = new Course()
   184          const course1 = new Course()
   185          const course2 = new Course()
   186          const course3 = new Course()
   187          const course4 = new Course()
   188  
   189          course0.ID = BigInt(1)
   190          course0.name = "Object Oriented Programming"
   191          course0.code = "DAT100"
   192          course0.tag = "Spring"
   193          course0.year = 2017
   194          course0.ScmOrganizationID = BigInt(23650610)
   195          course0.courseCreatorID = BigInt(1)
   196  
   197          course1.ID = BigInt(2)
   198          course1.name = "Algorithms and Data Structures"
   199          course1.code = "DAT200"
   200          course1.tag = "Spring"
   201          course1.year = 2017
   202          course1.ScmOrganizationID = BigInt(23650611)
   203  
   204          course2.ID = BigInt(3)
   205          course2.name = "Databases"
   206          course2.code = "DAT220"
   207          course2.tag = "Spring"
   208          course2.year = 2017
   209          course2.ScmOrganizationID = BigInt(23650612)
   210  
   211          course3.ID = BigInt(4)
   212          course3.name = "Communication Technology"
   213          course3.code = "DAT230"
   214          course3.tag = "Spring"
   215          course3.year = 2017
   216          course3.ScmOrganizationID = BigInt(23650613)
   217  
   218          course4.ID = BigInt(5)
   219          course4.name = "Operating Systems"
   220          course4.code = "DAT320"
   221          course4.tag = "Spring"
   222          course4.year = 2017
   223          course4.ScmOrganizationID = BigInt(23650614)
   224  
   225          return [course0, course1, course2, course3, course4]
   226      }
   227  
   228      public static mockedEnrollments() {
   229          const enrollments = new Enrollments()
   230          const localEnrols: Enrollment[] = []
   231          localEnrols.push(
   232              new Enrollment({
   233                  ID: BigInt(1),
   234                  courseID: BigInt(1),
   235                  userID: BigInt(1),
   236                  status: Enrollment_UserStatus.TEACHER,
   237                  state: Enrollment_DisplayState.VISIBLE,
   238                  groupID: BigInt(1),
   239                  user: MockData.mockedUsers().find((u) => u.ID === BigInt(1)),
   240              })
   241          )
   242  
   243          localEnrols.push(
   244              new Enrollment({
   245                  ID: BigInt(2),
   246                  courseID: BigInt(2),
   247                  userID: BigInt(1),
   248                  status: Enrollment_UserStatus.TEACHER,
   249                  state: Enrollment_DisplayState.VISIBLE,
   250                  user: MockData.mockedUsers().find((u) => u.ID === BigInt(1)),
   251              })
   252          )
   253  
   254          localEnrols.push(
   255              new Enrollment({
   256                  ID: BigInt(3),
   257                  courseID: BigInt(1),
   258                  userID: BigInt(2),
   259                  status: Enrollment_UserStatus.STUDENT,
   260                  groupID: BigInt(1),
   261                  user: MockData.mockedUsers().find((u) => u.ID === BigInt(2)),
   262              })
   263          )
   264  
   265          localEnrols.push(
   266              new Enrollment({
   267                  ID: BigInt(4),
   268                  courseID: BigInt(2),
   269                  userID: BigInt(2),
   270                  status: Enrollment_UserStatus.PENDING,
   271                  user: MockData.mockedUsers().find((u) => u.ID === BigInt(2)),
   272              })
   273          )
   274  
   275          localEnrols.push(
   276              new Enrollment({
   277                  ID: BigInt(5),
   278                  courseID: BigInt(1),
   279                  userID: BigInt(3),
   280                  status: Enrollment_UserStatus.STUDENT,
   281                  groupID: BigInt(2),
   282                  user: MockData.mockedUsers().find((u) => u.ID === BigInt(3)),
   283              })
   284          )
   285  
   286          localEnrols.push(
   287              new Enrollment({
   288                  ID: BigInt(6),
   289                  courseID: BigInt(1),
   290                  userID: BigInt(4),
   291                  status: Enrollment_UserStatus.STUDENT,
   292                  groupID: BigInt(2),
   293                  user: MockData.mockedUsers().find((u) => u.ID === BigInt(4)),
   294              })
   295          )
   296          enrollments.enrollments = (localEnrols)
   297          return enrollments
   298      }
   299  
   300      public static mockedOrganizations(): Organization[] {
   301          const localOrgs: Organization[] = []
   302          const localOrg = new Organization()
   303          localOrg.ScmOrganizationID = BigInt(23650610)
   304          localOrg.ScmOrganizationName = "test"
   305          localOrgs.push(localOrg)
   306          return localOrgs
   307      }
   308  
   309      public static mockedGroups() {
   310          const groups = new Groups()
   311  
   312          const group1 = new Group({
   313              ID: BigInt(1),
   314              name: "Group 1",
   315              status: Group_GroupStatus.APPROVED,
   316              courseID: BigInt(1),
   317          })
   318  
   319          const group2 = new Group({
   320              ID: BigInt(2),
   321              name: "Group 2",
   322              status: Group_GroupStatus.PENDING,
   323              courseID: BigInt(1),
   324          })
   325  
   326          groups.groups = [group1, group2]
   327          return groups
   328      }
   329  
   330      public static mockedSubmissions() {
   331          const submissions = new Submissions()
   332          submissions.submissions = [
   333              new Submission({
   334                  ID: BigInt(1),
   335                  AssignmentID: BigInt(1),
   336                  userID: BigInt(1),
   337                  status: Submission_Status.APPROVED,
   338                  BuildInfo: new BuildInfo({
   339                      ID: BigInt(1),
   340                      SubmissionID: BigInt(1),
   341                      ExecTime: BigInt(1),
   342                      BuildDate: Timestamp.fromDate(new Date(2017, 6, 4)),
   343                      SubmissionDate: Timestamp.fromDate(new Date(2017, 6, 4)),
   344                      BuildLog: "Build log for submission 1",
   345                  }),
   346                  score: 100,
   347                  commitHash: "abc",
   348                  Scores: [
   349                      new Score({
   350                          ID: BigInt(1),
   351                          SubmissionID: BigInt(1),
   352                          MaxScore: 10,
   353                          Score: 10,
   354                          TestName: "Test 1",
   355                          Weight: 2
   356                      }),
   357                      new Score({
   358                          ID: BigInt(2),
   359                          SubmissionID: BigInt(1),
   360                          MaxScore: 10,
   361                          Score: 10,
   362                          TestName: "Test 2",
   363                          Weight: 2
   364                      }),
   365                  ],
   366              }),
   367  
   368              new Submission({
   369                  ID: BigInt(2),
   370                  AssignmentID: BigInt(2),
   371                  userID: BigInt(2),
   372                  score: 75,
   373                  commitHash: "bcd",
   374              }),
   375  
   376              new Submission({
   377                  ID: BigInt(3),
   378                  AssignmentID: BigInt(3),
   379                  userID: BigInt(1),
   380                  score: 80,
   381                  released: true,
   382                  reviews: [
   383                      new Review({
   384                          ID: BigInt(1),
   385                          SubmissionID: BigInt(3),
   386                          score: 80,
   387                          feedback: "Well done!",
   388                          ReviewerID: BigInt(1),
   389                          gradingBenchmarks: [
   390                              new GradingBenchmark({
   391                                  ID: BigInt(1),
   392                                  AssignmentID: BigInt(2),
   393                                  heading: "HTML",
   394                                  ReviewID: BigInt(1),
   395                                  criteria: [
   396                                      new GradingCriterion({
   397                                          ID: BigInt(1),
   398                                          BenchmarkID: BigInt(1),
   399                                          description: "Add div",
   400                                          comment: "Good job!",
   401                                          grade: GradingCriterion_Grade.PASSED,
   402                                          points: BigInt(10),
   403                                      }),
   404                                      new GradingCriterion({
   405                                          ID: BigInt(2),
   406                                          BenchmarkID: BigInt(1),
   407                                          description: "Div has text",
   408                                          comment: "Good job!",
   409                                          grade: GradingCriterion_Grade.PASSED,
   410                                          points: BigInt(10),
   411                                      })
   412                                  ]
   413                              }),
   414                              new GradingBenchmark({
   415                                  ID: BigInt(2),
   416                                  AssignmentID: BigInt(2),
   417                                  heading: "CSS",
   418                                  ReviewID: BigInt(1),
   419                                  criteria: [
   420                                      new GradingCriterion({
   421                                          ID: BigInt(3),
   422                                          BenchmarkID: BigInt(2),
   423                                          description: "Div centered",
   424                                          comment: "Good job!",
   425                                          grade: GradingCriterion_Grade.PASSED,
   426                                          points: BigInt(10),
   427                                      }),
   428                                      new GradingCriterion({
   429                                          ID: BigInt(4),
   430                                          BenchmarkID: BigInt(2),
   431                                          description: "Div colored",
   432                                          comment: "Good job!",
   433                                          grade: GradingCriterion_Grade.PASSED,
   434                                          points: BigInt(10),
   435                                      })
   436                                  ]
   437                              })
   438                          ]
   439                      }),
   440                  ]
   441              }),
   442              new Submission({
   443                  ID: BigInt(4),
   444                  AssignmentID: BigInt(3),
   445                  groupID: BigInt(1),
   446                  score: 90,
   447                  commitHash: "def",
   448              }),
   449              new Submission({
   450                  ID: BigInt(5),
   451                  AssignmentID: BigInt(5),
   452                  userID: BigInt(1),
   453                  score: 100,
   454                  commitHash: "efg",
   455              }),
   456  
   457              new Submission({
   458                  ID: BigInt(6),
   459                  AssignmentID: BigInt(1),
   460                  userID: BigInt(3),
   461                  score: 50,
   462                  commitHash: "test",
   463                  status: Submission_Status.NONE,
   464                  BuildInfo: new BuildInfo({
   465                      ID: BigInt(3),
   466                      BuildDate: Timestamp.fromDate(new Date(2022, 6, 4)),
   467                      BuildLog: "Build log for test student",
   468                      ExecTime: BigInt(1),
   469                  }),
   470                  Scores: [
   471                      new Score({
   472                          ID: BigInt(3),
   473                          MaxScore: 10,
   474                          Score: 5,
   475                          SubmissionID: BigInt(6),
   476                          TestName: "Test 1",
   477                          TestDetails: "Test details for test 1",
   478                          Weight: 5,
   479                      }),
   480                      new Score({
   481                          ID: BigInt(4),
   482                          MaxScore: 10,
   483                          Score: 7,
   484                          SubmissionID: BigInt(6),
   485                          TestName: "Test 2",
   486                          TestDetails: "Test details for test 2",
   487                          Weight: 2,
   488                      }),
   489                  ]
   490              })
   491  
   492          ]
   493          return submissions
   494      }
   495  
   496      public static mockedBenchmarks(): GradingBenchmark[] {
   497          const templateBenchmarks = []
   498  
   499          templateBenchmarks.push(
   500              new GradingBenchmark({
   501                  ID: BigInt(1),
   502                  AssignmentID: BigInt(1),
   503                  heading: "HTML",
   504                  criteria: [
   505                      new GradingCriterion({
   506                          ID: BigInt(1),
   507                          BenchmarkID: BigInt(1),
   508                          description: "Add div",
   509                          points: BigInt(10),
   510                      }),
   511                      new GradingCriterion({
   512                          ID: BigInt(2),
   513                          BenchmarkID: BigInt(1),
   514                          description: "Div has text",
   515                          points: BigInt(10),
   516                      }),
   517                  ]
   518              }),
   519              new GradingBenchmark({
   520                  ID: BigInt(2),
   521                  AssignmentID: BigInt(2),
   522                  heading: "CSS",
   523                  criteria: [
   524                      new GradingCriterion({
   525                          ID: BigInt(3),
   526                          BenchmarkID: BigInt(2),
   527                          description: "Div centered",
   528                          points: BigInt(10),
   529                      }),
   530                      new GradingCriterion({
   531                          ID: BigInt(4),
   532                          BenchmarkID: BigInt(2),
   533                          description: "Div colored",
   534                          points: BigInt(10),
   535                      }),
   536                  ]
   537              })
   538          )
   539          return templateBenchmarks
   540      }
   541  
   542      public static computeScore(r: Review) {
   543          let score = 0
   544          let totalApproved = 0
   545          let total = 0
   546          for (let i = 0; i < r.gradingBenchmarks.length; i++) {
   547              const gb = r.gradingBenchmarks[i]
   548              for (let j = 0; j < gb.criteria.length; j++) {
   549                  const criterion = gb.criteria[j]
   550                  total++
   551                  if (criterion.grade === GradingCriterion_Grade.PASSED) {
   552                      score += Number(criterion.points)
   553                      totalApproved++
   554                  }
   555              }
   556          }
   557          if (score === 0) {
   558              score = 100 / total * totalApproved
   559          }
   560          return score
   561      }
   562  }