Skip to content

Commit

Permalink
fix: dev branch merge
Browse files Browse the repository at this point in the history
  • Loading branch information
psychology50 committed Mar 26, 2024
2 parents c7f3788 + e09ab66 commit d124c19
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 24 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Continuous Deployment

on:
push:
branches: [ "dev" ]
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- info
- warning
- debug
tags:
description: 'Test scenario tags'
required: false
type: boolean
environment:
description: 'Environment to run tests against'
type: environment
required: false

permissions:
contents: read

jobs:
deployment:
runs-on: ubuntu-20.04

steps:
# 1. Compare branch 코드 내려 받기
- name: Checkout PR
uses: actions/checkout@v3
with:
ref: ${{ github.event.push.base_ref }}

# 2. 자바 환경 설정
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

# 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
# 5. AWS SSM을 통한 Run-Command (Docker 이미지 pull 후 docker-compose를 통한 실행)
- name: AWS SSM Send-Command
uses: peterkimzz/aws-ssm-send-command@master
id: ssm
with:
aws-region: ${{ secrets.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
instance-ids: ${{ secrets.AWS_DEV_INSTANCE_ID }}
working-directory: /home/ubuntu
command: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker system prune -a -f
docker pull jinlee1703/pennyway-was
docker-compose up -d
51 changes: 51 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Continuous Integration

on:
pull_request:
branches: [ "dev" ]
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- info
- warning
- debug
tags:
description: 'Test scenario tags'
required: false
type: boolean
environment:
description: 'Environment to run tests against'
type: environment
required: false

permissions:
contents: read

jobs:
testing:
runs-on: ubuntu-20.04

steps:
# 1. Compare branch 코드 내려 받기
- name: Checkout PR
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}

# 2. 자바 환경 설정
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

# 3. Gradle Test 실행
- name: Test with Gradle
run: |
chmod +x ./gradlew
./gradlew --info test
Empty file modified gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class UserSyncHelper {
* 일반 회원가입 시 이미 가입된 회원인지 확인
*
* @param phone String : 전화번호
* @return Pair<Boolean, String> : 이미 가입된 회원인지 여부 (TRUE: 가입되지 않은 회원, FALSE: 가입된 회원), 가입된 회원인 경우 회원 ID 반환
* @return Pair<Boolean, String> : 이미 가입된 회원인지 여부 (TRUE: 가입되지 않은 회원, FALSE: 가입된 회원), 가입된 회원인 경우 회원
* ID 반환
* @throws UserErrorException : 이미 일반 회원가입을 한 유저인 경우
*/
public Pair<Boolean, String> isSignedUserWhenGeneral(String phone) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
@WebMvcTest(controllers = {AuthController.class})
@ActiveProfiles("local")
public class AuthControllerValidationTest {

@Autowired
private MockMvc mockMvc;

Expand Down Expand Up @@ -79,7 +80,8 @@ void requiredInputError() throws Exception {
@Test
void idValidError() throws Exception {
// given
SignUpReq.General request = new SignUpReq.General("#pennyway", "페니웨이", "pennyway1234", "010-1234-5678", "123456");
SignUpReq.General request = new SignUpReq.General("#pennyway", "페니웨이", "pennyway1234",
"010-1234-5678", "123456");

// when
ResultActions resultActions = mockMvc.perform(
Expand All @@ -99,7 +101,8 @@ void idValidError() throws Exception {
@Test
void nameValidError() throws Exception {
// given
SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이1", "pennyway1234", "010-1234-5678", "123456");
SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이1", "pennyway1234",
"010-1234-5678", "123456");

// when
ResultActions resultActions = mockMvc.perform(
Expand All @@ -119,7 +122,8 @@ void nameValidError() throws Exception {
@Test
void passwordValidError() throws Exception {
// given
SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway", "010-1234-5678", "123456");
SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway",
"010-1234-5678", "123456");

// when
ResultActions resultActions = mockMvc.perform(
Expand All @@ -131,15 +135,17 @@ void passwordValidError() throws Exception {
// then
resultActions
.andExpect(status().isUnprocessableEntity())
.andExpect(jsonPath("$.fieldErrors.password").value("8~16자의 영문 대/소문자, 숫자, 특수문자를 사용해주세요. (적어도 하나의 영문 소문자, 숫자 포함)"))
.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");
SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway1234",
"01012345673", "123456");

// when
ResultActions resultActions = mockMvc.perform(
Expand All @@ -159,7 +165,8 @@ void phoneValidError() throws Exception {
@Test
void codeValidError() throws Exception {
// given
SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway1234", "010-1234-5678", "12345");
SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway1234",
"010-1234-5678", "12345");

// when
ResultActions resultActions = mockMvc.perform(
Expand All @@ -179,7 +186,8 @@ void codeValidError() throws Exception {
@Test
void someFieldMissingError() throws Exception {
// given
SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway1234", "010-1234-5678", "123456");
SignUpReq.General request = new SignUpReq.General("pennyway", "페니웨이", "pennyway1234",
"010-1234-5678", "123456");

// when
ResultActions resultActions = mockMvc.perform(
Expand All @@ -201,8 +209,10 @@ void someFieldMissingError() throws Exception {
@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();
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")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import kr.co.pennyway.domain.domains.user.exception.UserErrorCode;
import kr.co.pennyway.domain.domains.user.exception.UserErrorException;
import kr.co.pennyway.domain.domains.user.service.UserService;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -13,7 +12,6 @@
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.BDDMockito.given;

@ExtendWith(MockitoExtension.class)
Expand All @@ -28,42 +26,43 @@ void setUp() {
userSyncHelper = new UserSyncHelper(userService);
}

@DisplayName("일반 회원가입 시, 회원 정보가 없으면 oauth == false, username == null을 반환한다.")
@DisplayName("일반 회원가입 시, 회원 정보가 없으면 FALSE를 반환한다.")
@Test
void isSignedUserWhenGeneralReturnFalse() {
// given
given(userService.readUserByPhone(phone)).willThrow(new UserErrorException(UserErrorCode.NOT_FOUND));
given(userService.readUserByPhone(phone)).willThrow(
new UserErrorException(UserErrorCode.NOT_FOUND));

// when
Pair<Boolean, String> result = userSyncHelper.isSignedUserWhenGeneral(phone);
Boolean result = userSyncHelper.isSignedUserWhenGeneral(phone).getKey();

// then
assertEquals(result.getKey(), Boolean.FALSE);
assertNull(result.getValue());
assertEquals(result, Boolean.FALSE);
}

@DisplayName("일반 회원가입 시, oauth 회원 정보가 있으면 oauth == true, username을 반환한다.")
@DisplayName("일반 회원가입 시, oauth 회원 정보가 있으면 TRUE를 반환한다.")
@Test
void isSignedUserWhenGeneralReturnTrue() {
// given
given(userService.readUserByPhone(phone)).willReturn(User.builder().username("pennyway").password(null).build());
given(userService.readUserByPhone(phone)).willReturn(User.builder().password(null).build());

// when
Pair<Boolean, String> result = userSyncHelper.isSignedUserWhenGeneral(phone);
Boolean result = userSyncHelper.isSignedUserWhenGeneral(phone).getKey();

// then
assertEquals(result.getKey(), Boolean.TRUE);
assertEquals(result.getValue(), "pennyway");
assertEquals(result, Boolean.TRUE);
}

@DisplayName("일반 회원가입 시, 이미 일반회원 가입된 회원인 경우 UserErrorException을 발생시킨다.")
@Test
void isSignedUserWhenGeneralThrowUserErrorException() {
// given
given(userService.readUserByPhone(phone)).willReturn(User.builder().password("password").build());
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));
UserErrorException exception = org.junit.jupiter.api.Assertions.assertThrows(
UserErrorException.class, () -> userSyncHelper.isSignedUserWhenGeneral(phone));
System.out.println(exception.getExplainError());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

@ExtendWith(MockitoExtension.class)
public class SuccessResponseTest {

private TestDto dto;

@BeforeEach
Expand Down Expand Up @@ -73,5 +74,6 @@ public void successResponseFromDtoWithKey() {
}

private record TestDto(String name, int age) {

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package kr.co.pennyway;

public class PennywayInfraApplication {

}

0 comments on commit d124c19

Please sign in to comment.