diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4fe85d304..afaf055b2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -44,14 +44,21 @@ jobs: java-version: '17' distribution: 'temurin' - # 3. Docker 이미지 build 및 push + # 3. Build Gradle + - name: Build Gradle + run: | + chmod +x ./gradlew + ./gradlew build --stacktrace --info -x test + shell: bash + + # 4. Docker 이미지 build 및 push - name: docker build and push run: | docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} docker build -t jinlee1703/pennyway-was . docker push jinlee1703/pennyway-was - # 4. AWS SSM을 통한 Run-Command (Docker 이미지 pull 후 docker-compose를 통한 실행) + # 5. AWS SSM을 통한 Run-Command (Docker 이미지 pull 후 docker-compose를 통한 실행) - name: AWS SSM Send-Command uses: peterkimzz/aws-ssm-send-command@master id: ssm diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 200219117..db9a9519d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,4 +46,6 @@ jobs: # 3. Gradle Test 실행 - name: Test with Gradle - run: ./gradlew --info test \ No newline at end of file + run: | + chmod +x ./gradlew + ./gradlew --info test \ No newline at end of file diff --git a/build.gradle b/build.gradle index 39cad6583..1ccc1e45d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,50 +1,61 @@ buildscript { - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } } plugins { - id 'java' - id 'org.springframework.boot' version '3.2.3' - id 'io.spring.dependency-management' version '1.1.4' + id 'java' + id 'org.springframework.boot' version '3.2.3' + id 'io.spring.dependency-management' version '1.1.4' } group = 'kr.co' version = '0.0.1-SNAPSHOT' -bootJar {enabled = false} -jar {enabled = true} +bootJar { enabled = false } +jar { enabled = true } allprojects { - group = 'kr.co' - version = '0.0.1-SNAPSHOT' - sourceCompatibility = '17' + group = 'kr.co' + version = '0.0.1-SNAPSHOT' + sourceCompatibility = '17' } subprojects { - apply plugin: "java" - apply plugin: 'java-library' - apply plugin: "io.spring.dependency-management" - apply plugin: "org.springframework.boot" - - repositories { - mavenCentral() - } - - configurations { - compileOnly { - extendsFrom annotationProcessor - } - } - - dependencies { - compileOnly 'org.projectlombok:lombok' - annotationProcessor 'org.projectlombok:lombok' - annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" - - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testCompileOnly 'org.projectlombok:lombok' - testAnnotationProcessor 'org.projectlombok:lombok' - } + apply plugin: "java" + apply plugin: 'java-library' + apply plugin: "io.spring.dependency-management" + apply plugin: "org.springframework.boot" + + repositories { + mavenCentral() + } + + configurations { + compileOnly { + extendsFrom annotationProcessor + } + } + + dependencies { + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" + + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' + } + + test { + useJUnitPlatform() + testLogging { + showStandardStreams = true + showCauses = true + showExceptions = true + showStackTraces = true + exceptionFormat = 'full' + } + } } \ No newline at end of file diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/auth/helper/UserSyncHelper.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/auth/helper/UserSyncHelper.java index 8dce3c4fe..1fd1dc45d 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/auth/helper/UserSyncHelper.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/auth/helper/UserSyncHelper.java @@ -14,29 +14,31 @@ @Helper @RequiredArgsConstructor public class UserSyncHelper { - private final UserService userService; - /** - * 일반 회원가입 시 이미 가입된 회원인지 확인 - * - * @param phone String : 전화번호 - * @return Pair : 이미 가입된 회원인지 여부 (TRUE: 가입되지 않은 회원, FALSE: 가입된 회원), 가입된 회원인 경우 회원 ID 반환 - * @throws UserErrorException : 이미 일반 회원가입을 한 유저인 경우 - */ - public Pair isSignedUserWhenGeneral(String phone) { - User user; - try { - user = userService.readUserByPhone(phone); - } catch (GlobalErrorException e) { - log.info("User not found. phone: {}", phone); - return Pair.of(Boolean.TRUE, null); - } + private final UserService userService; - if (user.getPassword() != null) { - log.warn("User already exists. phone: {}", phone); - throw new UserErrorException(UserErrorCode.ALREADY_SIGNUP); - } + /** + * 일반 회원가입 시 이미 가입된 회원인지 확인 + * + * @param phone String : 전화번호 + * @return Pair : 이미 가입된 회원인지 여부 (TRUE: 가입되지 않은 회원, FALSE: 가입된 회원), 가입된 회원인 경우 회원 + * ID 반환 + * @throws UserErrorException : 이미 일반 회원가입을 한 유저인 경우 + */ + public Pair isSignedUserWhenGeneral(String phone) { + User user; + try { + user = userService.readUserByPhone(phone); + } catch (GlobalErrorException e) { + log.info("User not found. phone: {}", phone); + return Pair.of(Boolean.FALSE, null); + } - return Pair.of(Boolean.FALSE, user.getUsername()); + if (user.getPassword() != null) { + log.warn("User already exists. phone: {}", phone); + throw new UserErrorException(UserErrorCode.ALREADY_SIGNUP); } + + return Pair.of(Boolean.TRUE, user.getUsername()); + } } diff --git a/pennyway-app-external-api/src/test/java/kr/co/pennyway/api/apis/auth/controller/AuthControllerValidationTest.java b/pennyway-app-external-api/src/test/java/kr/co/pennyway/api/apis/auth/controller/AuthControllerValidationTest.java index 832be89eb..ddf906023 100644 --- a/pennyway-app-external-api/src/test/java/kr/co/pennyway/api/apis/auth/controller/AuthControllerValidationTest.java +++ b/pennyway-app-external-api/src/test/java/kr/co/pennyway/api/apis/auth/controller/AuthControllerValidationTest.java @@ -1,6 +1,14 @@ package kr.co.pennyway.api.apis.auth.controller; +import static org.mockito.BDDMockito.given; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + import com.fasterxml.jackson.databind.ObjectMapper; +import java.time.Duration; import kr.co.pennyway.api.apis.auth.dto.SignUpReq; import kr.co.pennyway.api.apis.auth.usecase.AuthUseCase; import kr.co.pennyway.api.common.security.jwt.Jwts; @@ -17,199 +25,202 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; -import java.time.Duration; - -import static org.mockito.BDDMockito.given; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - @WebMvcTest(controllers = {AuthController.class}) @ActiveProfiles("local") public class AuthControllerValidationTest { - @Autowired - private MockMvc mockMvc; - - @Autowired - private ObjectMapper objectMapper; - - @MockBean - private AuthUseCase authUseCase; - - @MockBean - private CookieUtil cookieUtil; - - @DisplayName("[1] 아이디, 이름, 비밀번호, 전화번호, 인증번호 필수 입력") - @Test - void requiredInputError() throws Exception { - // given - SignUpReq.General request = new SignUpReq.General("", "", "", "", ""); - - // when - ResultActions resultActions = mockMvc.perform( - post("/v1/auth/sign-up") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request)) - ); - - // then - resultActions - .andExpect(status().isUnprocessableEntity()) - .andExpect(jsonPath("$.fieldErrors.username").exists()) - .andExpect(jsonPath("$.fieldErrors.name").exists()) - .andExpect(jsonPath("$.fieldErrors.password").exists()) - .andExpect(jsonPath("$.fieldErrors.phone").exists()) - .andExpect(jsonPath("$.fieldErrors.code").exists()) - .andDo(print()); - } - - @DisplayName("[2] 아이디는 5~20자의 영문 소문자, -, _, . 만 사용 가능합니다.") - @Test - void idValidError() throws Exception { - // given - SignUpReq.General request = new SignUpReq.General("#pennyway", "페니웨이", "pennyway1234", "010-1234-5678", "123456"); - - // when - ResultActions resultActions = mockMvc.perform( - post("/v1/auth/sign-up") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request)) - ); - - // then - resultActions - .andExpect(status().isUnprocessableEntity()) - .andExpect(jsonPath("$.fieldErrors.username").value("5~20자의 영문 소문자, -, _, . 만 사용 가능합니다.")) - .andDo(print()); - } - - @DisplayName("[3] 이름은 2~20자의 한글, 영문 대/소문자만 사용 가능합니다.") - @Test - void nameValidError() throws Exception { - // given - SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이1", "pennyway1234", "010-1234-5678", "123456"); - - // when - ResultActions resultActions = mockMvc.perform( - post("/v1/auth/sign-up") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request)) - ); - - // then - resultActions - .andExpect(status().isUnprocessableEntity()) - .andExpect(jsonPath("$.fieldErrors.name").value("2~20자의 한글, 영문 대/소문자만 사용 가능합니다.")) - .andDo(print()); - } - - @DisplayName("[4] 비밀번호는 8~16자의 영문 대/소문자, 숫자, 특수문자를 사용해주세요. (적어도 하나의 영문 소문자, 숫자 포함)") - @Test - void passwordValidError() throws Exception { - // given - SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway", "010-1234-5678", "123456"); - - // when - ResultActions resultActions = mockMvc.perform( - post("/v1/auth/sign-up") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request)) - ); - - // then - resultActions - .andExpect(status().isUnprocessableEntity()) - .andExpect(jsonPath("$.fieldErrors.password").value("8~16자의 영문 대/소문자, 숫자, 특수문자를 사용해주세요. (적어도 하나의 영문 소문자, 숫자 포함)")) - .andDo(print()); - } - - @DisplayName("[5] 전화번호는 010 혹은 011로 시작하는, 010-0000-0000 형식이어야 합니다.") - @Test - void phoneValidError() throws Exception { - // given - SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway1234", "01012345673", "123456"); - - // when - ResultActions resultActions = mockMvc.perform( - post("/v1/auth/sign-up") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request)) - ); - - // then - resultActions - .andExpect(status().isUnprocessableEntity()) - .andExpect(jsonPath("$.fieldErrors.phone").value("전화번호 형식이 올바르지 않습니다.")) - .andDo(print()); - } - - @DisplayName("[6] 인증번호는 6자리 숫자여야 합니다.") - @Test - void codeValidError() throws Exception { - // given - SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway1234", "010-1234-5678", "12345"); - - // when - ResultActions resultActions = mockMvc.perform( - post("/v1/auth/sign-up") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request)) - ); - - // then - resultActions - .andExpect(status().isUnprocessableEntity()) - .andExpect(jsonPath("$.fieldErrors.code").value("인증번호는 6자리 숫자여야 합니다.")) - .andDo(print()); - } - - @DisplayName("[7] 일부 필드 누락") - @Test - void someFieldMissingError() throws Exception { - // given - SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway1234", "010-1234-5678", "123456"); - - // when - ResultActions resultActions = mockMvc.perform( - post("/v1/auth/sign-up") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request) - .replace("\"username\":\"pennyway\",", "") - .replace("\"phone\":\"010-1234-5678\",", ""))); - - // then - resultActions - .andExpect(status().isUnprocessableEntity()) - .andExpect(jsonPath("$.fieldErrors.username").value("아이디를 입력해주세요")) - .andExpect(jsonPath("$.fieldErrors.phone").value("전화번호를 입력해주세요")) - .andDo(print()); - } - - @DisplayName("[8] 정상적인 회원가입 요청 - 쿠키/인증 헤더와 회원 pk 반환") - @Test - void signUp() throws Exception { - // given - SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway1234", "010-1234-5678", "123456"); - ResponseCookie expectedCookie = ResponseCookie.from("refreshToken", "refreshToken").maxAge(Duration.ofDays(7).toSeconds()).httpOnly(true).path("/").build(); - - given(authUseCase.signUp(request)) - .willReturn(Pair.of(1L, Jwts.of("accessToken", "refreshToken"))); - given(cookieUtil.createCookie("refreshToken", "refreshToken", Duration.ofDays(7).toSeconds())) - .willReturn(expectedCookie); - - // when - ResultActions resultActions = mockMvc.perform( - post("/v1/auth/sign-up") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request)) - ); - - // then - resultActions - .andExpect(status().isOk()) - .andExpect(header().string("Set-Cookie", expectedCookie.toString())) - .andExpect(header().string("Authorization", "accessToken")) - .andExpect(jsonPath("$.data.user.id").value(1)) - .andDo(print()); - } + + @Autowired + private MockMvc mockMvc; + + @Autowired + private ObjectMapper objectMapper; + + @MockBean + private AuthUseCase authUseCase; + + @MockBean + private CookieUtil cookieUtil; + + @DisplayName("[1] 아이디, 이름, 비밀번호, 전화번호, 인증번호 필수 입력") + @Test + void requiredInputError() throws Exception { + // given + SignUpReq.General request = new SignUpReq.General("", "", "", "", ""); + + // when + ResultActions resultActions = mockMvc.perform( + post("/v1/auth/sign-up") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ); + + // then + resultActions + .andExpect(status().isUnprocessableEntity()) + .andExpect(jsonPath("$.fieldErrors.username").exists()) + .andExpect(jsonPath("$.fieldErrors.name").exists()) + .andExpect(jsonPath("$.fieldErrors.password").exists()) + .andExpect(jsonPath("$.fieldErrors.phone").exists()) + .andExpect(jsonPath("$.fieldErrors.code").exists()) + .andDo(print()); + } + + @DisplayName("[2] 아이디는 5~20자의 영문 소문자, -, _, . 만 사용 가능합니다.") + @Test + void idValidError() throws Exception { + // given + SignUpReq.General request = new SignUpReq.General("#pennyway", "페니웨이", "pennyway1234", + "010-1234-5678", "123456"); + + // when + ResultActions resultActions = mockMvc.perform( + post("/v1/auth/sign-up") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ); + + // then + resultActions + .andExpect(status().isUnprocessableEntity()) + .andExpect(jsonPath("$.fieldErrors.username").value("5~20자의 영문 소문자, -, _, . 만 사용 가능합니다.")) + .andDo(print()); + } + + @DisplayName("[3] 이름은 2~20자의 한글, 영문 대/소문자만 사용 가능합니다.") + @Test + void nameValidError() throws Exception { + // given + SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이1", "pennyway1234", + "010-1234-5678", "123456"); + + // when + ResultActions resultActions = mockMvc.perform( + post("/v1/auth/sign-up") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ); + + // then + resultActions + .andExpect(status().isUnprocessableEntity()) + .andExpect(jsonPath("$.fieldErrors.name").value("2~20자의 한글, 영문 대/소문자만 사용 가능합니다.")) + .andDo(print()); + } + + @DisplayName("[4] 비밀번호는 8~16자의 영문 대/소문자, 숫자, 특수문자를 사용해주세요. (적어도 하나의 영문 소문자, 숫자 포함)") + @Test + void passwordValidError() throws Exception { + // given + SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway", + "010-1234-5678", "123456"); + + // when + ResultActions resultActions = mockMvc.perform( + post("/v1/auth/sign-up") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ); + + // then + resultActions + .andExpect(status().isUnprocessableEntity()) + .andExpect(jsonPath("$.fieldErrors.password").value( + "8~16자의 영문 대/소문자, 숫자, 특수문자를 사용해주세요. (적어도 하나의 영문 소문자, 숫자 포함)")) + .andDo(print()); + } + + @DisplayName("[5] 전화번호는 010 혹은 011로 시작하는, 010-0000-0000 형식이어야 합니다.") + @Test + void phoneValidError() throws Exception { + // given + SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway1234", + "01012345673", "123456"); + + // when + ResultActions resultActions = mockMvc.perform( + post("/v1/auth/sign-up") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ); + + // then + resultActions + .andExpect(status().isUnprocessableEntity()) + .andExpect(jsonPath("$.fieldErrors.phone").value("전화번호 형식이 올바르지 않습니다.")) + .andDo(print()); + } + + @DisplayName("[6] 인증번호는 6자리 숫자여야 합니다.") + @Test + void codeValidError() throws Exception { + // given + SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway1234", + "010-1234-5678", "12345"); + + // when + ResultActions resultActions = mockMvc.perform( + post("/v1/auth/sign-up") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ); + + // then + resultActions + .andExpect(status().isUnprocessableEntity()) + .andExpect(jsonPath("$.fieldErrors.code").value("인증번호는 6자리 숫자여야 합니다.")) + .andDo(print()); + } + + @DisplayName("[7] 일부 필드 누락") + @Test + void someFieldMissingError() throws Exception { + // given + SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway1234", + "010-1234-5678", "123456"); + + // when + ResultActions resultActions = mockMvc.perform( + post("/v1/auth/sign-up") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request) + .replace("\"username\":\"pennyway\",", "") + .replace("\"phone\":\"010-1234-5678\",", ""))); + + // then + resultActions + .andExpect(status().isUnprocessableEntity()) + .andExpect(jsonPath("$.fieldErrors.username").value("아이디를 입력해주세요")) + .andExpect(jsonPath("$.fieldErrors.phone").value("전화번호를 입력해주세요")) + .andDo(print()); + } + + @DisplayName("[8] 정상적인 회원가입 요청 - 쿠키/인증 헤더와 회원 pk 반환") + @Test + void signUp() throws Exception { + // given + SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway1234", + "010-1234-5678", "123456"); + ResponseCookie expectedCookie = ResponseCookie.from("refreshToken", "refreshToken") + .maxAge(Duration.ofDays(7).toSeconds()).httpOnly(true).path("/").build(); + + given(authUseCase.signUp(request)) + .willReturn(Pair.of(1L, Jwts.of("accessToken", "refreshToken"))); + given(cookieUtil.createCookie("refreshToken", "refreshToken", Duration.ofDays(7).toSeconds())) + .willReturn(expectedCookie); + + // when + ResultActions resultActions = mockMvc.perform( + post("/v1/auth/sign-up") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ); + + // then + resultActions + .andExpect(status().isOk()) + .andExpect(header().exists("Set-Cookie")) + .andExpect(header().string("Authorization", "accessToken")) + .andExpect(jsonPath("$.data.user.id").value(1)) + .andDo(print()); + } } diff --git a/pennyway-app-external-api/src/test/java/kr/co/pennyway/api/apis/auth/helper/UserSyncHelperTest.java b/pennyway-app-external-api/src/test/java/kr/co/pennyway/api/apis/auth/helper/UserSyncHelperTest.java index 12f01b378..4e04a32ba 100644 --- a/pennyway-app-external-api/src/test/java/kr/co/pennyway/api/apis/auth/helper/UserSyncHelperTest.java +++ b/pennyway-app-external-api/src/test/java/kr/co/pennyway/api/apis/auth/helper/UserSyncHelperTest.java @@ -1,5 +1,8 @@ package kr.co.pennyway.api.apis.auth.helper; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.BDDMockito.given; + import kr.co.pennyway.domain.domains.user.domain.User; import kr.co.pennyway.domain.domains.user.exception.UserErrorCode; import kr.co.pennyway.domain.domains.user.exception.UserErrorException; @@ -11,55 +14,56 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.BDDMockito.given; - @ExtendWith(MockitoExtension.class) public class UserSyncHelperTest { - private final String phone = "010-1234-5678"; - private UserSyncHelper userSyncHelper; - @Mock - private UserService userService; - @BeforeEach - void setUp() { - userSyncHelper = new UserSyncHelper(userService); - } + private final String phone = "010-1234-5678"; + private UserSyncHelper userSyncHelper; + @Mock + private UserService userService; + + @BeforeEach + void setUp() { + userSyncHelper = new UserSyncHelper(userService); + } - @DisplayName("일반 회원가입 시, 회원 정보가 없으면 FALSE를 반환한다.") - @Test - void isSignedUserWhenGeneralReturnFalse() { - // given - given(userService.readUserByPhone(phone)).willThrow(new UserErrorException(UserErrorCode.NOT_FOUND)); + @DisplayName("일반 회원가입 시, 회원 정보가 없으면 FALSE를 반환한다.") + @Test + void isSignedUserWhenGeneralReturnFalse() { + // given + given(userService.readUserByPhone(phone)).willThrow( + new UserErrorException(UserErrorCode.NOT_FOUND)); - // when - Boolean result = userSyncHelper.isSignedUserWhenGeneral(phone); + // when + Boolean result = userSyncHelper.isSignedUserWhenGeneral(phone).getKey(); - // then - assertEquals(result, Boolean.FALSE); - } + // then + assertEquals(result, Boolean.FALSE); + } - @DisplayName("일반 회원가입 시, oauth 회원 정보가 있으면 TRUE를 반환한다.") - @Test - void isSignedUserWhenGeneralReturnTrue() { - // given - given(userService.readUserByPhone(phone)).willReturn(User.builder().password(null).build()); + @DisplayName("일반 회원가입 시, oauth 회원 정보가 있으면 TRUE를 반환한다.") + @Test + void isSignedUserWhenGeneralReturnTrue() { + // given + given(userService.readUserByPhone(phone)).willReturn(User.builder().password(null).build()); - // when - Boolean result = userSyncHelper.isSignedUserWhenGeneral(phone); + // when + Boolean result = userSyncHelper.isSignedUserWhenGeneral(phone).getKey(); - // then - assertEquals(result, Boolean.TRUE); - } + // then + assertEquals(result, Boolean.TRUE); + } - @DisplayName("일반 회원가입 시, 이미 일반회원 가입된 회원인 경우 UserErrorException을 발생시킨다.") - @Test - void isSignedUserWhenGeneralThrowUserErrorException() { - // given - given(userService.readUserByPhone(phone)).willReturn(User.builder().password("password").build()); + @DisplayName("일반 회원가입 시, 이미 일반회원 가입된 회원인 경우 UserErrorException을 발생시킨다.") + @Test + void isSignedUserWhenGeneralThrowUserErrorException() { + // given + given(userService.readUserByPhone(phone)).willReturn( + User.builder().password("password").build()); - // when - then - UserErrorException exception = org.junit.jupiter.api.Assertions.assertThrows(UserErrorException.class, () -> userSyncHelper.isSignedUserWhenGeneral(phone)); - System.out.println(exception.getExplainError()); - } + // when - then + UserErrorException exception = org.junit.jupiter.api.Assertions.assertThrows( + UserErrorException.class, () -> userSyncHelper.isSignedUserWhenGeneral(phone)); + System.out.println(exception.getExplainError()); + } } diff --git a/pennyway-app-external-api/src/test/java/kr/co/pennyway/api/common/response/SuccessResponseTest.java b/pennyway-app-external-api/src/test/java/kr/co/pennyway/api/common/response/SuccessResponseTest.java index 8e9e44ba9..28fdf2b69 100644 --- a/pennyway-app-external-api/src/test/java/kr/co/pennyway/api/common/response/SuccessResponseTest.java +++ b/pennyway-app-external-api/src/test/java/kr/co/pennyway/api/common/response/SuccessResponseTest.java @@ -1,77 +1,78 @@ package kr.co.pennyway.api.common.response; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; - @ExtendWith(MockitoExtension.class) public class SuccessResponseTest { - private TestDto dto; - - @BeforeEach - void setUp() { - dto = new TestDto("test", 1); - } - - @Test - @DisplayName("SuccessResponse.from() - data가 존재하는 성공 응답") - public void successResponseWithData() { - // Given - String key = "example"; - String value = "data"; - - // When - SuccessResponse response = SuccessResponse.from(key, value); - - // Then - assertEquals("2000000", response.getCode()); - assertEquals(Map.of(key, value), response.getData()); - } - - @Test - @DisplayName("SuccessResponse.from() - data가 존재하는 성공 응답") - public void successResponseWithNoContent() { - // When - SuccessResponse response = SuccessResponse.noContent(); - - // Then - assertEquals("2000000", response.getCode()); - assertEquals(Map.of(), response.getData()); - } - - @Test - @DisplayName("SuccessResponse.from() - DTO를 통한 성공 응답") - public void successResponseFromDto() { - // When - SuccessResponse response = SuccessResponse.from(dto); - - // Then - assertEquals("2000000", response.getCode()); - assertEquals(dto, response.getData()); - System.out.println(response); - } - - @Test - @DisplayName("SuccessResponse.from() - key와 DTO를 통한 성공 응답") - public void successResponseFromDtoWithKey() { - // Given - String key = "test"; - - // When - SuccessResponse> response = SuccessResponse.from(key, dto); - - // Then - assertEquals("2000000", response.getCode()); - assertEquals(Map.of(key, dto), response.getData()); - System.out.println(response); - } - - private record TestDto(String name, int age) { - } + + private TestDto dto; + + @BeforeEach + void setUp() { + dto = new TestDto("test", 1); + } + + @Test + @DisplayName("SuccessResponse.from() - data가 존재하는 성공 응답") + public void successResponseWithData() { + // Given + String key = "example"; + String value = "data"; + + // When + SuccessResponse response = SuccessResponse.from(key, value); + + // Then + assertEquals("2000", response.getCode()); + assertEquals(Map.of(key, value), response.getData()); + } + + @Test + @DisplayName("SuccessResponse.from() - data가 존재하는 성공 응답") + public void successResponseWithNoContent() { + // When + SuccessResponse response = SuccessResponse.noContent(); + + // Then + assertEquals("2000", response.getCode()); + assertEquals(Map.of(), response.getData()); + } + + @Test + @DisplayName("SuccessResponse.from() - DTO를 통한 성공 응답") + public void successResponseFromDto() { + // When + SuccessResponse response = SuccessResponse.from(dto); + + // Then + assertEquals("2000", response.getCode()); + assertEquals(dto, response.getData()); + System.out.println(response); + } + + @Test + @DisplayName("SuccessResponse.from() - key와 DTO를 통한 성공 응답") + public void successResponseFromDtoWithKey() { + // Given + String key = "test"; + + // When + SuccessResponse> response = SuccessResponse.from(key, dto); + + // Then + assertEquals("2000", response.getCode()); + assertEquals(Map.of(key, dto), response.getData()); + System.out.println(response); + } + + private record TestDto(String name, int age) { + + } } diff --git a/pennyway-infra/src/main/java/kr/co/pennyway/PennywayInfraApplication.java b/pennyway-infra/src/main/java/kr/co/pennyway/PennywayInfraApplication.java index 8adc2e7b2..0bc66b4bb 100644 --- a/pennyway-infra/src/main/java/kr/co/pennyway/PennywayInfraApplication.java +++ b/pennyway-infra/src/main/java/kr/co/pennyway/PennywayInfraApplication.java @@ -1,7 +1,5 @@ package kr.co.pennyway; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication public class PennywayInfraApplication { + }