Skip to content

Commit

Permalink
Merge pull request #97 from H-Hive/feature/user
Browse files Browse the repository at this point in the history
fix: 헤더 수정
  • Loading branch information
EUNCHAEv1006 authored Jan 24, 2024
2 parents c9aae1e + 5706991 commit 9e932b7
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ public ResponseEntity<CommonResponse<UserCategoryResponseDTO>> setCategory(
}

@GetMapping("/kakao/callback")
public String kakaoLogin(@RequestParam String code, HttpServletResponse response) throws JsonProcessingException {
public ResponseEntity<CommonResponse<String>> kakaoLogin(@RequestParam String code, HttpServletResponse response)
throws JsonProcessingException {

// jwt 토큰 반환
String token = kaKaoService.kakaoLogin(code);

response.setHeader(JwtUtil.AUTHORIZATION_HEADER, JwtUtil.BEARER_PREFIX + token);
response.setHeader(JwtUtil.AUTHORIZATION_HEADER, JwtUtil.BEARER_PREFIX + token.substring(7));

return "redirect:https://hhive.store/";
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.CREATED.value(), "카카오 로그인 성공", token));
}
}
109 changes: 109 additions & 0 deletions src/test/java/com/HHive/hhive/domain/user/entity/UserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.HHive.hhive.domain.user.entity;

import com.HHive.hhive.domain.category.data.MajorCategory;
import com.HHive.hhive.domain.category.data.SubCategory;
import com.HHive.hhive.domain.user.dto.UpdateUserProfileRequestDTO;
import org.junit.jupiter.api.*;

import static org.junit.jupiter.api.Assertions.*;

@DisplayName("User Entity 테스트")
class UserTest {

@Nested
@DisplayName("유저 정보 업데이트 테스트")
class UpdateUserInfoTest {

@Test
@DisplayName("카카오 ID 업데이트")
void kakaoIdUpdate() {
// given
User user = new User("testUser", "testPassword", "[email protected]", "testDescription");
Long kakaoId = 12345678L;

// when
user.kakaoIdUpdate(kakaoId);

// then
assertEquals(kakaoId, user.getKakaoId());
}

@Test
@DisplayName("프로필 업데이트")
void updateProfile() {
// given
User user = new User("testUser", "testPassword", "[email protected]", "testDescription");
UpdateUserProfileRequestDTO requestDTO = new UpdateUserProfileRequestDTO();

// when
user.updateProfile(requestDTO);

// then
assertEquals(requestDTO.getEmail(), user.getEmail());
assertEquals(requestDTO.getDescription(), user.getDescription());
}

@Test
@DisplayName("계정 삭제 업데이트")
void updateDeletedAt() {
// given
User user = new User("testUser", "testPassword", "[email protected]", "testDescription");
assertFalse(user.is_deleted());

// when
user.updateDeletedAt();

// then
assertTrue(user.is_deleted());
assertNotNull(user.getDeletedAt());
}
}

@Nested
@DisplayName("유저 정보 설정 테스트")
class SetUserInfoTest {

@Test
@DisplayName("비밀번호 설정")
void setPassword() {
// given
User user = new User("testUser", "testPassword", "[email protected]", "testDescription");
String newPassword = "newPassword";

// when
user.setPassword(newPassword);

// then
assertEquals(newPassword, user.getPassword());
}

@Test
@DisplayName("major 카테고리 설정")
void setMajorCategory() {
// given
User user = new User("testUser", "testPassword", "[email protected]", "testDescription");
MajorCategory majorCategory = MajorCategory.GAME;

// when
user.setMajorCategory(majorCategory);

// then
assertEquals(majorCategory, user.getMajorCategory());
}

@Test
@DisplayName("sub 카테고리 설정")
void setSubCategory() {
// given
User user = new User("testUser", "testPassword", "[email protected]", "testDescription");
SubCategory subCategory = SubCategory.LOL;

// when
user.setSubCategory(subCategory);

// then
assertEquals(subCategory, user.getSubCategory());
}
}
}

0 comments on commit 9e932b7

Please sign in to comment.