test(iam): verify createdAt is set during registration
This commit is contained in:
parent
72c29cfcc1
commit
f7375dd9aa
@ -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(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user