diff --git a/eeg_backend/src/test/java/at/mueller/eeg/backend/iam/service/AuthServiceTest.java b/eeg_backend/src/test/java/at/mueller/eeg/backend/iam/service/AuthServiceTest.java index e3563f5..530f193 100644 --- a/eeg_backend/src/test/java/at/mueller/eeg/backend/iam/service/AuthServiceTest.java +++ b/eeg_backend/src/test/java/at/mueller/eeg/backend/iam/service/AuthServiceTest.java @@ -20,6 +20,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.oauth2.jwt.JwtEncoder; import org.springframework.security.oauth2.jwt.JwtEncoderParameters; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; import java.util.UUID; @@ -80,6 +81,25 @@ class AuthServiceTest { verify(mailService).sendVerificationEmail(eq("test@example.com"), anyString()); } + @Test + void register_setsCreatedAt() { + IamDtos.RegistrationRequest request = new IamDtos.RegistrationRequest( + ParticipantType.PRIVATE, "Test", "Benutzer", null, "test@example.com", "password123" + ); + + when(userRepository.findByEmail("test@example.com")).thenReturn(Optional.empty()); + when(userMapper.mapToEntity(any(), any())).thenReturn(testUser); + when(userRepository.save(any())).thenReturn(testUser); + + LocalDateTime before = LocalDateTime.now().minusSeconds(1); + authService.register(request); + LocalDateTime after = LocalDateTime.now().plusSeconds(1); + + assertNotNull(testUser.getCreatedAt()); + assertFalse(testUser.getCreatedAt().isBefore(before), "createdAt should not be before registration started"); + assertFalse(testUser.getCreatedAt().isAfter(after), "createdAt should not be after registration ended"); + } + @Test void register_duplicateEmail_throws() { IamDtos.RegistrationRequest request = new IamDtos.RegistrationRequest(