diff --git a/src/main/java/de/tum/in/www1/artemis/domain/exam/StudentExam.java b/src/main/java/de/tum/in/www1/artemis/domain/exam/StudentExam.java index a0f2d9173e05..2ee168c022c4 100644 --- a/src/main/java/de/tum/in/www1/artemis/domain/exam/StudentExam.java +++ b/src/main/java/de/tum/in/www1/artemis/domain/exam/StudentExam.java @@ -26,7 +26,7 @@ public class StudentExam extends AbstractAuditingEntity { private Boolean submitted; @Column(name = "abandoned") - private Boolean abandoned; + private boolean abandoned = false; /** * The individual working time per student in seconds diff --git a/src/main/java/de/tum/in/www1/artemis/web/rest/StudentExamResource.java b/src/main/java/de/tum/in/www1/artemis/web/rest/StudentExamResource.java index 5a99b58aceb8..cf31f6a44e45 100644 --- a/src/main/java/de/tum/in/www1/artemis/web/rest/StudentExamResource.java +++ b/src/main/java/de/tum/in/www1/artemis/web/rest/StudentExamResource.java @@ -269,7 +269,7 @@ public ResponseEntity submitStudentExam(@PathVariable Long courseId, @Path return ResponseEntity.ok().build(); } - if (Boolean.TRUE.equals(studentExamFromClient.isAbandoned()) || Boolean.TRUE.equals(existingStudentExam.isAbandoned())) { + if (studentExamFromClient.isAbandoned() || existingStudentExam.isAbandoned()) { log.error("Student exam with id {} for user {} is abandoned.", studentExamFromClient.getId(), currentUser.getLogin()); throw new BadRequestException("Exam is already abandoned"); } @@ -323,7 +323,7 @@ public ResponseEntity abandonStudentExam(@PathVariable Long courseId, @Pat throw new BadRequestException("Exam is already submitted"); } - if (Boolean.TRUE.equals(studentExamFromClient.isAbandoned()) || Boolean.TRUE.equals(existingStudentExam.isAbandoned())) { + if (studentExamFromClient.isAbandoned() || existingStudentExam.isAbandoned()) { log.error("Student exam with id {} for user {} is already abandoned.", studentExamFromClient.getId(), currentUser.getLogin()); throw new BadRequestException("Exam is already abandoned"); } diff --git a/src/test/javascript/spec/service/exam-participation.service.spec.ts b/src/test/javascript/spec/service/exam-participation.service.spec.ts index d12be7312ce2..01abb73103f8 100644 --- a/src/test/javascript/spec/service/exam-participation.service.spec.ts +++ b/src/test/javascript/spec/service/exam-participation.service.spec.ts @@ -180,26 +180,7 @@ describe('Exam Participation Service', () => { }); it('should load a StudentExam in the version of server', async () => { - /*configure exercises of this student Exam*/ - const exercise = new TextExercise(new Course(), undefined); - const studentParticipation = new StudentParticipation(); - const participationResult = new Result(); - participationResult.participation = studentParticipation; - studentParticipation.results = [participationResult]; - const submission = new TextSubmission(); - submission.results = [new Result()]; - submission.participation = studentParticipation; - getLatestSubmissionResult(submission)!.participation = studentParticipation; - getLatestSubmissionResult(submission)!.submission = submission; - studentParticipation.submissions = [submission]; - exercise.studentParticipations = [studentParticipation]; - /*configure the exam of a student exam*/ - const examToSend = new Exam(); - - const returnedFromService = Object.assign(studentExam, { - exercises: [exercise], - exam: examToSend, - }); + const returnedFromService = studentExamPayload(); service .submitStudentExam(2, 2, returnedFromService) .pipe(take(1)) @@ -265,4 +246,33 @@ describe('Exam Participation Service', () => { const req = httpMock.expectOne({ method: 'GET' }); req.flush(returnedFromService); }); + + it('should call student-exam/abandon', async () => { + const objectToSend = studentExamPayload(); + service.abandonStudentExam(2, 2, objectToSend).subscribe(); + const url = service.getResourceURL(2, 2) + '/student-exams/abandon'; + + httpMock.expectOne({ method: 'POST', url: url }); + }); + + const studentExamPayload = () => { + const exercise = new TextExercise(new Course(), undefined); + const studentParticipation = new StudentParticipation(); + const participationResult = new Result(); + participationResult.participation = studentParticipation; + studentParticipation.results = [participationResult]; + const submission = new TextSubmission(); + submission.results = [new Result()]; + submission.participation = studentParticipation; + getLatestSubmissionResult(submission)!.participation = studentParticipation; + getLatestSubmissionResult(submission)!.submission = submission; + studentParticipation.submissions = [submission]; + exercise.studentParticipations = [studentParticipation]; + const examToSend = new Exam(); + + return Object.assign(studentExam, { + exercises: [exercise], + exam: examToSend, + }); + }; });