From d402b3382f1af93a8617915ee506680051f007d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9D=80=EC=B1=84?= Date: Tue, 23 Jan 2024 23:06:11 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=ED=97=A4=EB=8D=94=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hhive/domain/user/controller/UserController.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/HHive/hhive/domain/user/controller/UserController.java b/src/main/java/com/HHive/hhive/domain/user/controller/UserController.java index e55f602..febd04a 100644 --- a/src/main/java/com/HHive/hhive/domain/user/controller/UserController.java +++ b/src/main/java/com/HHive/hhive/domain/user/controller/UserController.java @@ -133,13 +133,15 @@ public ResponseEntity> setCategory( } @GetMapping("/kakao/callback") - public String kakaoLogin(@RequestParam String code, HttpServletResponse response) throws JsonProcessingException { + public ResponseEntity> 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)); } } From 57069919a3124b44504225897c776a4993685479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9D=80=EC=B1=84?= Date: Wed, 24 Jan 2024 23:58:50 +0900 Subject: [PATCH 2/2] =?UTF-8?q?test:=20user=20entity=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hhive/domain/user/entity/UserTest.java | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/test/java/com/HHive/hhive/domain/user/entity/UserTest.java diff --git a/src/test/java/com/HHive/hhive/domain/user/entity/UserTest.java b/src/test/java/com/HHive/hhive/domain/user/entity/UserTest.java new file mode 100644 index 0000000..4cf61be --- /dev/null +++ b/src/test/java/com/HHive/hhive/domain/user/entity/UserTest.java @@ -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", "testEmail@email.com", "testDescription"); + Long kakaoId = 12345678L; + + // when + user.kakaoIdUpdate(kakaoId); + + // then + assertEquals(kakaoId, user.getKakaoId()); + } + + @Test + @DisplayName("프로필 업데이트") + void updateProfile() { + // given + User user = new User("testUser", "testPassword", "testEmail@email.com", "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", "testEmail@email.com", "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", "testEmail@email.com", "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", "testEmail@email.com", "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", "testEmail@email.com", "testDescription"); + SubCategory subCategory = SubCategory.LOL; + + // when + user.setSubCategory(subCategory); + + // then + assertEquals(subCategory, user.getSubCategory()); + } + } +} +