Public Access
Fixed tests
This commit is contained in:
1 parent
20402eb7c4
commit
f90b674ed2
9 files changed
+26
-14
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package auth_service.configuration.security;
|
||||
|
||||
import auth_service.shared.security.UserPrincipal;
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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.response.UserProfileResponse;
|
||||
import auth_service.domain.user.controller.mapper.ApiMapper;
|
||||
|
||||
@@ -61,15 +61,24 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
@Transactional
|
||||
@Override
|
||||
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);
|
||||
if (userEntity != null && userEntity.getSteamId() != steamId) {
|
||||
userEntity.setSteamId(steamId);
|
||||
return true;
|
||||
if (userEntity == null) {
|
||||
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)
|
||||
private boolean enabled;
|
||||
|
||||
@Column(name = "steam_id", unique = true, nullable = false)
|
||||
@Column(name = "steam_id", unique = true)
|
||||
private Long steamId;
|
||||
|
||||
@Column(name = "registration_date", nullable = false)
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package auth_service.configuration.security;
|
||||
package auth_service.shared.security;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Create the users table
|
||||
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 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.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.exception.UserNotFoundException;
|
||||
import auth_service.domain.user.model.User;
|
||||
|
||||
@@ -24,7 +24,7 @@ class UserRepositoryTest extends AbstractPersistenceTest {
|
||||
@Test
|
||||
void findByEmail_Success() {
|
||||
// Arrange
|
||||
var email = "test@example.com";
|
||||
var email = "newuser@example.com";
|
||||
var userEntity = UserEntity.builder()
|
||||
.email(email)
|
||||
.password("password")
|
||||
|
||||
@@ -2,6 +2,7 @@ package auth_service.shared.test;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.testcontainers.containers.PostgreSQLContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
@@ -13,6 +14,7 @@ import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
*/
|
||||
@Tag("IntegrationTest")
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@ActiveProfiles("dev")
|
||||
@Testcontainers
|
||||
public abstract class AbstractIntegrationTest {
|
||||
|
||||
|
||||
Reference in new issue
Block a user