Skip to content

Commit

Permalink
Match a Canvas quiz name to a gradebook quiz name if the quiz's descr…
Browse files Browse the repository at this point in the history
…iption appears anywhere in the name of the Canvas quiz.
  • Loading branch information
DavidWhitlock committed Feb 12, 2022
1 parent ae35329 commit 34c33c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ public List<CanvasStudent> getStudents() {
return this.students;
}

public Optional<Assignment> findAssignmentInGradebookForCanvasQuiz(String quizName, GradeBook gradebook) {
Assignment assignment = gradebook.getAssignment(quizName);
public Optional<Assignment> findAssignmentInGradebookForCanvasQuiz(String canvasQuizName, GradeBook gradebook) {
Assignment assignment = gradebook.getAssignment(canvasQuizName);
if (assignment != null) {
return Optional.of(assignment);
}

return findAssignmentInGradebookLike(quizName, gradebook);
return findAssignmentInGradebookLike(canvasQuizName, gradebook);
}

private Optional<Assignment> findAssignmentInGradebookLike(String quizName, GradeBook gradebook) {
private Optional<Assignment> findAssignmentInGradebookLike(String canvasQuizName, GradeBook gradebook) {
for (String assignmentName : gradebook.getAssignmentNames()) {
Assignment assignment = gradebook.getAssignment(assignmentName);
if (quizName.startsWith(assignmentName)) {
if (canvasQuizName.startsWith(assignmentName)) {
return Optional.ofNullable(assignment);
}

if (quizName.startsWith(assignment.getDescription())) {
if (canvasQuizName.contains(assignment.getDescription())) {
return Optional.of(assignment);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,23 @@ public void matchQuizWithDescriptionPrefixThatIsTheSameAsQuizNameInD2L() {

}

@Test
void matchQuizWithDescriptionThatIsContainedInQuizNameInCanvas() {
String quizDescription = "Quiz Description";

GradesFromCanvas grades = new GradesFromCanvas();
GradesFromCanvas.CanvasStudent d2lStudent = GradesFromCanvas.newStudent().setFirstName("first").setLastName("last").setLoginId("id").create();
grades.addStudent(d2lStudent);
String canvasQuizName = "Quiz 1: " + quizDescription + " (12345)";
d2lStudent.setScore(canvasQuizName, 3.6);

GradeBook book = new GradeBook("test");
Assignment assignment = new Assignment("quiz1", 4.0);
assignment.setDescription(quizDescription);
book.addAssignment(assignment);

assertThat(grades.findAssignmentInGradebookForCanvasQuiz(canvasQuizName, book).orElseGet(() -> null), equalTo(assignment));

}

}

0 comments on commit 34c33c6

Please sign in to comment.