From af313a81e3afbfde64e54659f2b090df6e1cfcc5 Mon Sep 17 00:00:00 2001 From: Lucas Welscher Date: Tue, 10 Oct 2023 21:34:28 +0200 Subject: [PATCH] add test case --- .../ProgrammingSubmissionIntegrationTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/de/tum/in/www1/artemis/exercise/programmingexercise/ProgrammingSubmissionIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/exercise/programmingexercise/ProgrammingSubmissionIntegrationTest.java index 1202044ed886..425991229d95 100644 --- a/src/test/java/de/tum/in/www1/artemis/exercise/programmingexercise/ProgrammingSubmissionIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/exercise/programmingexercise/ProgrammingSubmissionIntegrationTest.java @@ -516,6 +516,36 @@ void testNotifyPush_isSetupCommit() throws Exception { } + @Test + @WithMockUser(username = TEST_PREFIX + "student1", roles = "USER") + void testNotifyPush_studentCommitUpdatesSubmissionCount() throws Exception { + var participation = participationUtilService.addStudentParticipationForProgrammingExercise(exercise, TEST_PREFIX + "student1"); + + Commit mockCommit = mock(Commit.class); + doReturn(mockCommit).when(versionControlService).getLastCommitDetails(any()); + doReturn("default-branch").when(versionControlService).getDefaultBranchOfRepository(any()); + + doReturn("hash1").when(mockCommit).getCommitHash(); + doReturn("default-branch").when(mockCommit).getBranch(); + doReturn("Student 1").when(mockCommit).getAuthorName(); + doReturn("student@tum.de").when(mockCommit).getAuthorEmail(); + doReturn("my nice little solution").when(mockCommit).getMessage(); + + String url = "/api/public/programming-submissions/" + participation.getId(); + // no request body needed since the commit information are mocked above + request.postWithoutLocation(url, "test", HttpStatus.OK, null); + + verify(websocketMessagingService, timeout(2000)).sendMessageToUser(eq(TEST_PREFIX + "student1"), eq(NEW_SUBMISSION_TOPIC), + argThat(arg -> arg instanceof SubmissionDTO submissionDTO && submissionDTO.participation().submissionCount() == 1)); + + // second push + doReturn("hash2").when(mockCommit).getCommitHash(); + request.postWithoutLocation(url, "test", HttpStatus.OK, null); + + verify(websocketMessagingService, timeout(2000)).sendMessageToUser(eq(TEST_PREFIX + "student1"), eq(NEW_SUBMISSION_TOPIC), + argThat(arg -> arg instanceof SubmissionDTO submissionDTO && submissionDTO.participation().submissionCount() == 2)); + } + @Test @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void getAllProgrammingSubmissionsAsInstructorAllSubmissionsReturned() throws Exception {