diff --git a/src/main/java/ch/uzh/ifi/access/student/dao/CustomizedStudentSubmissionRepositoryImpl.java b/src/main/java/ch/uzh/ifi/access/student/dao/CustomizedStudentSubmissionRepositoryImpl.java index 612ce269..829cffee 100644 --- a/src/main/java/ch/uzh/ifi/access/student/dao/CustomizedStudentSubmissionRepositoryImpl.java +++ b/src/main/java/ch/uzh/ifi/access/student/dao/CustomizedStudentSubmissionRepositoryImpl.java @@ -78,7 +78,7 @@ public boolean existsByUserIdAndHasNoResultOrConsoleNotOlderThan10min(String use .where("userId").is(userId) .and("console").exists(false) .and("result").exists(false) - .and("timestamp").gt(Instant.now().minus(10, ChronoUnit.MINUTES))); + .and("timestamp").gt(Instant.now().minus(1, ChronoUnit.MINUTES))); return mongoTemplate.exists(query, StudentSubmission.class); } } diff --git a/src/test/java/ch/uzh/ifi/access/student/service/StudentSubmissionServiceTest.java b/src/test/java/ch/uzh/ifi/access/student/service/StudentSubmissionServiceTest.java index 52e6f01e..c5c01b4b 100644 --- a/src/test/java/ch/uzh/ifi/access/student/service/StudentSubmissionServiceTest.java +++ b/src/test/java/ch/uzh/ifi/access/student/service/StudentSubmissionServiceTest.java @@ -469,4 +469,56 @@ public void userRateLimitedWithOldSubmission() { boolean userRateLimited = service.isUserRateLimited(userId); Assertions.assertThat(userRateLimited).isFalse(); } + + @Test + public void userRateLimitedWithOldSubmissionMinutes() { + String userId = "123"; + submissionProperties.setUserRateLimit(true); + CodeSubmission submission = CodeSubmission.builder() + .userId(userId) + .timestamp(Instant.now().minus(1, ChronoUnit.MINUTES)) + .build(); + repository.save(submission); + boolean userRateLimited = service.isUserRateLimited(userId); + Assertions.assertThat(userRateLimited).isFalse(); + } + + @Test + public void userRateLimitedWithOldSubmissionSeconds() { + String userId = "123"; + submissionProperties.setUserRateLimit(true); + CodeSubmission submission = CodeSubmission.builder() + .userId(userId) + .timestamp(Instant.now().minus(59, ChronoUnit.SECONDS)) + .build(); + repository.save(submission); + boolean userRateLimited = service.isUserRateLimited(userId); + Assertions.assertThat(userRateLimited).isTrue(); + } + + @Test + public void userRateLimitedWithOldSubmission1Minute() { + String userId = "123"; + submissionProperties.setUserRateLimit(true); + CodeSubmission submission = CodeSubmission.builder() + .userId(userId) + .timestamp(Instant.now().minus(60, ChronoUnit.SECONDS)) + .build(); + repository.save(submission); + boolean userRateLimited = service.isUserRateLimited(userId); + Assertions.assertThat(userRateLimited).isFalse(); + } + + @Test + public void userRateLimitedWithOldSubmission1Minute1Second() { + String userId = "123"; + submissionProperties.setUserRateLimit(true); + CodeSubmission submission = CodeSubmission.builder() + .userId(userId) + .timestamp(Instant.now().minus(61, ChronoUnit.SECONDS)) + .build(); + repository.save(submission); + boolean userRateLimited = service.isUserRateLimited(userId); + Assertions.assertThat(userRateLimited).isFalse(); + } } \ No newline at end of file