Fixed tests

This commit is contained in:
lobo committed 2026-04-18 11:47:58 +02:00
1 parent 20402eb7c4
commit f90b674ed2
9 files changed
+26 -14

No files matched your search

@@ -1,5 +1,6 @@
package auth_service.configuration.security; package auth_service.configuration.security;
import auth_service.shared.security.UserPrincipal;
import jakarta.servlet.FilterChain; import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@@ -1,6 +1,6 @@
package auth_service.domain.user.controller; package auth_service.domain.user.controller;
import auth_service.configuration.security.UserPrincipal; import auth_service.shared.security.UserPrincipal;
import auth_service.domain.user.controller.dto.request.UserSettingsRequest; import auth_service.domain.user.controller.dto.request.UserSettingsRequest;
import auth_service.domain.user.controller.dto.response.UserProfileResponse; import auth_service.domain.user.controller.dto.response.UserProfileResponse;
import auth_service.domain.user.controller.mapper.ApiMapper; import auth_service.domain.user.controller.mapper.ApiMapper;
@@ -61,15 +61,24 @@ public class UserRepositoryImpl implements UserRepository {
@Transactional @Transactional
@Override @Override
public boolean updateSettings(long userId, long steamId, UserSettings settings) { public boolean updateSettings(long userId, long steamId, UserSettings settings) {
var entity = EntityMapper.toPersistence(userId, settings);
// merge() acts as an upsert: it updates if the ID exists, or inserts if it doesn't.
entityManager.merge(entity);
var userEntity = entityManager.find(UserEntity.class, userId); var userEntity = entityManager.find(UserEntity.class, userId);
if (userEntity != null && userEntity.getSteamId() != steamId) { if (userEntity == null) {
userEntity.setSteamId(steamId);
return true;
}
return false; return false;
} }
var settingsEntity = userEntity.getSettings();
if (settingsEntity == null) {
settingsEntity = new UserSettingsEntity();
settingsEntity.setUserId(userId);
userEntity.setSettings(settingsEntity);
}
settingsEntity.setLanguage(settings.getLanguage());
settingsEntity.setTheme(settings.getTheme());
boolean steamIdChanged = userEntity.getSteamId() != steamId;
userEntity.setSteamId(steamId);
return steamIdChanged;
}
} }
@@ -30,7 +30,7 @@ public class UserEntity {
@Column(nullable = false) @Column(nullable = false)
private boolean enabled; private boolean enabled;
@Column(name = "steam_id", unique = true, nullable = false) @Column(name = "steam_id", unique = true)
private Long steamId; private Long steamId;
@Column(name = "registration_date", nullable = false) @Column(name = "registration_date", nullable = false)
@@ -1,4 +1,4 @@
package auth_service.configuration.security; package auth_service.shared.security;
import java.security.Principal; import java.security.Principal;
@@ -1,6 +1,6 @@
-- Create the users table -- Create the users table
ALTER TABLE users ALTER TABLE users
ADD COLUMN steam_id BIGINT DEFAULT 0, ADD COLUMN steam_id BIGINT,
ADD COLUMN registration_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, ADD COLUMN registration_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN last_login_date TIMESTAMP; ADD COLUMN last_login_date TIMESTAMP;
@@ -2,7 +2,7 @@ package auth_service.domain.user.controller;
import auth_service.configuration.security.JwtAuthenticationFilter; import auth_service.configuration.security.JwtAuthenticationFilter;
import auth_service.configuration.security.JwtService; import auth_service.configuration.security.JwtService;
import auth_service.configuration.security.UserPrincipal; import auth_service.shared.security.UserPrincipal;
import auth_service.domain.user.controller.dto.request.UserSettingsRequest; import auth_service.domain.user.controller.dto.request.UserSettingsRequest;
import auth_service.domain.user.exception.UserNotFoundException; import auth_service.domain.user.exception.UserNotFoundException;
import auth_service.domain.user.model.User; import auth_service.domain.user.model.User;
@@ -24,7 +24,7 @@ class UserRepositoryTest extends AbstractPersistenceTest {
@Test @Test
void findByEmail_Success() { void findByEmail_Success() {
// Arrange // Arrange
var email = "test@example.com"; var email = "newuser@example.com";
var userEntity = UserEntity.builder() var userEntity = UserEntity.builder()
.email(email) .email(email)
.password("password") .password("password")
@@ -2,6 +2,7 @@ package auth_service.shared.test;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Container;
@@ -13,6 +14,7 @@ import org.testcontainers.junit.jupiter.Testcontainers;
*/ */
@Tag("IntegrationTest") @Tag("IntegrationTest")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("dev")
@Testcontainers @Testcontainers
public abstract class AbstractIntegrationTest { public abstract class AbstractIntegrationTest {