Started with:

- Registration logic for new players
- Extended User table with more information
This commit is contained in:
lobo committed 2026-04-04 17:11:13 +02:00
1 parent ad30de4190
commit 5dcdf7bd61
22 files changed
+341 -5

No files matched your search

@@ -0,0 +1,102 @@
package auth_service.domain.registration.service;
import auth_service.domain.registration.exception.EmailAlreadyInUseException;
import auth_service.domain.registration.exception.InvalidInvitationCodeException;
import auth_service.domain.registration.exception.SteamIdAlreadyRegisteredException;
import auth_service.domain.registration.model.RegisteredUser;
import auth_service.domain.registration.model.Registration;
import auth_service.domain.registration.persistence.RegisteredUserRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.security.crypto.password.PasswordEncoder;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
class RegistrationServiceTest {
@Mock
private CodeValidationService codeValidationService;
@Mock
private RegisteredUserRepository registeredUserRepository;
@Mock
private PasswordEncoder passwordEncoder;
@InjectMocks
private RegistrationService registrationService;
private Registration validRegistration;
@BeforeEach
void setUp() {
validRegistration = Registration.builder()
.email("test@example.com")
.rawPassword("SuperSecret123!")
.encryptedPassword("")
.inviteCode("TBP-INVITE-2026")
.steamId(314159L)
.build();
}
@Test
void register_withValidData_shouldReturnRegisteredUserAndMarkCodeAsUsed() {
// Arrange
when(codeValidationService.isCodeValid("TBP-INVITE-2026")).thenReturn(true);
when(registeredUserRepository.existsByEmail("test@example.com")).thenReturn(false);
when(passwordEncoder.encode("SuperSecret123!")).thenReturn("hashedPasswordXYZ");
RegisteredUser expectedUser = new RegisteredUser("uuid-1234", "test@example.com");
when(registeredUserRepository.save(validRegistration)).thenReturn(expectedUser);
// Act
RegisteredUser result = registrationService.register(validRegistration);
// Assert
assertNotNull(result);
assertEquals("uuid-1234", result.id());
assertEquals("test@example.com", result.email());
}
@Test
void register_withInvalidInviteCode_shouldThrowException() {
// Arrange
when(codeValidationService.isCodeValid("TBP-INVITE-2026")).thenReturn(false);
// Act & Assert
assertThrows(InvalidInvitationCodeException.class, () -> registrationService.register(validRegistration));
verify(registeredUserRepository, never()).save(any());
}
@Test
void register_withExistingEmail_shouldThrowException() {
// Arrange
when(codeValidationService.isCodeValid("TBP-INVITE-2026")).thenReturn(true);
when(registeredUserRepository.existsByEmail("test@example.com")).thenReturn(true);
// Act & Assert
assertThrows(EmailAlreadyInUseException.class, () -> registrationService.register(validRegistration));
verify(registeredUserRepository, never()).save(any());
}
@Test
void register_withExistingSteamId_shouldThrowException() {
// Arrange
when(codeValidationService.isCodeValid("TBP-INVITE-2026")).thenReturn(true);
when(registeredUserRepository.existsByEmail("test@example.com")).thenReturn(false);
when(registeredUserRepository.existsBySteamId(314159L)).thenReturn(true);
// Act & Assert
assertThrows(SteamIdAlreadyRegisteredException.class, () -> registrationService.register(validRegistration));
verify(registeredUserRepository, never()).save(any());
}
}