Skip to content

Commit

Permalink
fix: ci 에러 수정 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
choidongkuen committed Jan 6, 2024
1 parent 9f480f4 commit dbb7adc
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 89 deletions.
9 changes: 9 additions & 0 deletions src/main/java/net/teumteum/core/context/LoginContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.teumteum.core.context;

public interface LoginContext {

Long getUserId();

void setUserId(Long userId);

}
25 changes: 25 additions & 0 deletions src/main/java/net/teumteum/core/context/LoginContextImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.teumteum.core.context;

import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;

@Component
@Profile("prod")
@RequestScope(proxyMode = ScopedProxyMode.INTERFACES)
public class LoginContextImpl implements LoginContext {

private Long userId;

@Override
public Long getUserId() {
return userId;
}

@Override
public void setUserId(Long userId) {
this.userId = userId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Getter
@Setter
Expand Down
20 changes: 5 additions & 15 deletions src/main/java/net/teumteum/user/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.teumteum.user.controller;

import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import net.teumteum.core.error.ErrorResponse;
import net.teumteum.core.security.service.SecurityService;
Expand All @@ -9,16 +8,9 @@
import net.teumteum.user.domain.response.UsersGetByIdResponse;
import net.teumteum.user.service.UserService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RestController
@RequiredArgsConstructor
Expand All @@ -28,20 +20,18 @@ public class UserController {
private final UserService userService;
private final SecurityService securityService;

/* userId 로 회원 조회 */
@GetMapping("/{userId}")
@ResponseStatus(HttpStatus.OK)
public UserGetResponse getUserById(@PathVariable("userId") Long userId) {
return userService.getUserById(userId);
}

/* 여러 userId 로 회원 들 조회 */
@GetMapping
@ResponseStatus(HttpStatus.OK)
public UsersGetByIdResponse getUsersById(@RequestParam("id") String userIds) {
var parsedUserIds = Arrays.stream(userIds.split(","))
.map(Long::valueOf)
.toList();
.map(Long::valueOf)
.toList();

return userService.getUsersById(parsedUserIds);
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/net/teumteum/user/domain/OAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -16,6 +18,7 @@ public class OAuth {
@Column(name = "oauth_id", unique = true, nullable = false)
private String oauthId;

@Column(name = "provider_type", nullable = false)
@Enumerated(EnumType.STRING)
@Column(name = "provider_type", nullable = false)
private Authenticated authenticated;
}
8 changes: 4 additions & 4 deletions src/test/java/net/teumteum/integration/IntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.teumteum.integration;

import net.teumteum.Application;
import net.teumteum.core.security.service.SecurityService;
import net.teumteum.core.context.LoginContext;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -10,7 +10,7 @@
import org.springframework.test.context.ContextConfiguration;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ContextConfiguration(classes = {Application.class, Api.class, Repository.class, SecurityService.class})
@ContextConfiguration(classes = {Application.class, Api.class, Repository.class, TestLoginContext.class})
abstract public class IntegrationTest {

@Autowired
Expand All @@ -20,8 +20,8 @@ abstract public class IntegrationTest {
protected Repository repository;

@Autowired
protected SecurityService securityService;
protected LoginContext loginContext;

@AfterEach
@BeforeEach
void clearAll() {
Expand Down
34 changes: 0 additions & 34 deletions src/test/java/net/teumteum/integration/SecurityService.java

This file was deleted.

20 changes: 20 additions & 0 deletions src/test/java/net/teumteum/integration/TestLoginContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.teumteum.integration;

import net.teumteum.core.context.LoginContext;
import org.springframework.boot.test.context.TestComponent;

@TestComponent
public class TestLoginContext implements LoginContext {

private Long userId;

@Override
public Long getUserId() {
return this.userId;
}

@Override
public void setUserId(Long userId) {
this.userId = userId;
}
}
25 changes: 13 additions & 12 deletions src/test/java/net/teumteum/integration/UserIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.teumteum.integration;

import java.util.List;
import net.teumteum.core.error.ErrorResponse;
import net.teumteum.user.domain.response.UserGetResponse;
import net.teumteum.user.domain.response.UsersGetByIdResponse;
Expand All @@ -9,6 +8,8 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import java.util.List;

@DisplayName("유저 통합테스트의")
class UserIntegrationTest extends IntegrationTest {

Expand All @@ -31,11 +32,11 @@ void Return_user_info_if_exist_user_id_received() {

// then
Assertions.assertThat(
result.expectStatus().isOk()
.expectBody(UserGetResponse.class)
.returnResult().getResponseBody())
.usingRecursiveComparison()
.isEqualTo(expected);
result.expectStatus().isOk()
.expectBody(UserGetResponse.class)
.returnResult().getResponseBody())
.usingRecursiveComparison()
.isEqualTo(expected);
}

@Test
Expand All @@ -49,7 +50,7 @@ void Return_400_bad_request_if_not_exists_user_id_received() {

// then
result.expectStatus().isBadRequest()
.expectBody(ErrorResponse.class);
.expectBody(ErrorResponse.class);
}
}

Expand All @@ -71,9 +72,9 @@ void Return_user_info_if_exist_user_ids_received() {

// then
Assertions.assertThat(result.expectStatus().isOk()
.expectBody(UsersGetByIdResponse.class)
.returnResult()
.getResponseBody()
.expectBody(UsersGetByIdResponse.class)
.returnResult()
.getResponseBody()
).usingRecursiveComparison().isEqualTo(expected);
}

Expand Down Expand Up @@ -113,7 +114,7 @@ void Update_user_info() {
var existUser = repository.saveAndGetUser();
var updateUser = RequestFixture.userUpdateRequest(existUser);

securityService.setUserId(existUser.getId());
loginContext.setUserId(existUser.getId());

// when
var result = api.updateUser(VALID_TOKEN, updateUser);
Expand All @@ -135,7 +136,7 @@ void Return_200_ok_with_success_make_friends() {
var myToken = "JWT MY_TOKEN";
var friend = repository.saveAndGetUser();

securityService.setUserId(me.getId());
loginContext.setUserId(me.getId());

// when
var result = api.addFriends(myToken, friend.getId());
Expand Down
44 changes: 22 additions & 22 deletions src/test/java/net/teumteum/user/domain/UserFixture.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package net.teumteum.user.domain;

import lombok.Builder;

import java.util.List;
import java.util.Set;
import java.util.UUID;
import lombok.Builder;
import net.teumteum.core.security.Authenticated;

import static net.teumteum.core.security.Authenticated.네이버;

public class UserFixture {

public static User getNullIdUser() {
return newUserByBuilder(UserBuilder.builder()
.id(null)
.build());
.id(null)
.build());
}

public static User getUserWithId(Long id) {
return newUserByBuilder(UserBuilder.builder()
.id(id)
.build());
.id(id)
.build());
}

public static User getDefaultUser() {
Expand All @@ -28,21 +28,21 @@ public static User getDefaultUser() {

public static User newUserByBuilder(UserBuilder userBuilder) {
return new User(
userBuilder.id,
userBuilder.name,
userBuilder.birth,
userBuilder.characterId,
userBuilder.mannerTemperature,
userBuilder.oauth,
userBuilder.roleType,
userBuilder.activityArea,
userBuilder.mbti,
userBuilder.status,
userBuilder.goal,
userBuilder.job,
userBuilder.interests,
userBuilder.terms,
Set.of()
userBuilder.id,
userBuilder.name,
userBuilder.birth,
userBuilder.characterId,
userBuilder.mannerTemperature,
userBuilder.oauth,
userBuilder.roleType,
userBuilder.activityArea,
userBuilder.mbti,
userBuilder.status,
userBuilder.goal,
userBuilder.job,
userBuilder.interests,
userBuilder.terms,
Set.of()
);
}

Expand Down Expand Up @@ -75,7 +75,7 @@ public static class UserBuilder {
private Job job = new Job("netflix", true, "developer", "backend");
@Builder.Default
private List<String> interests = List.of(
"game", "sleep", "Eating delicious food"
"game", "sleep", "Eating delicious food"
);
@Builder.Default
private Terms terms = new Terms(true, true);
Expand Down

0 comments on commit dbb7adc

Please sign in to comment.