Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
[BE] test: 테스트 커버리지 개선 및 테스트 격리 (#501)
Browse files Browse the repository at this point in the history
* refactor: 사용하지 않는 테스트코드 제거

* test: 발행 상태 정보가 잘못 입력됐을때 예외테스트 추가

* refactor: 사용하지 않는 객체 삭제

* test: member의 token이 안전하게 삭제되는 테스트 추가

* test: JWT토큰 test 추가

* test: SocialType이 제대로 반환되는지 테스트

* test: Medium의 글을 발행할때 사용하는 외부 API 테스트 추가

* test: Tistory의 글을 발행할때 사용하는 외부 API 테스트 추가 및 카테고리 불러오는 API 테스트 추가

* test: 테스트 오류 수정

* test: test: Tistory의 글을 보호글 발행할때 사용하는 외부 API 테스트 추가

* test: 외부 API로 OAuth권한 부여 테스트 추가

* test: tistory의 accessToken을 제거하는 테스트 추가

* test: medium과 권한 연결하는 외부 API 테스트 추가

* test: notion과 권한 연결하는 외부 API 테스트 추

* test: mockWebServer down시켜주는 메소드 추가

* test: notion클라이언트에서 title을 가져오는 외부 API 테스트 추가

* test: notion의 글 내용을 가져오는 테스트 추가

* test: 외부 api 요청중 에러 처리 테스트 추가

* test: kakao OAuth를 이용한 외부 api 요청 테스트 추가

* test: blogType의 맞는 blog 조회 테스트 추가

* refactor: 사용하지 않는 메소드 삭제

* test: Authorization 해더값 추출 테스트 추가

* test: Exception의 반환할 수 있는 값 테스트 추가

* test: AuthFacadeService 테스트 추가

* test: mock테스트로 변경

* test: mock테스트로 변경

* test: 블로그 발생 테스트 추가

* test: getter테스트 제거 및 TrashService 테스트 추가

* test: Category의 순서 테스트 코드 추가

* test: WritingService 테스트 추가

* test: PublishService 테스트 추가

* test: AuthService 테스트 추가

* test: NotFound관련 에러 테스트 추가

* test: AuthController 테스트 추가

* test: BlogController 테스트 추가 및JwtSupporter 생성

* test: CategoryController 테스트 추가

* test: ConnectionController 테스트 추가

* test: MemberController 테스트 추가

* test: PublishController 테스트 추가

* test: TrashController 테스트 추가

* test: WritingController 테스트 추가

* test: BlogType 테스트 추가

* test: 동시성 테스트 추가

* test: memberFixture 변경

* test: BlogWritingRepository 테스트 추가

* test: CategoryRepository 테스트 추가

* test: MemberCredentialsRepositoryTest 테스트 추가

* test: MemberRepositoryTest 테스트 추가

* test: TokenRepository 테스트 추가

* test: Category생성자 id필드 제거

* test: WritingRepository 테스트 추가

* refactor: SpringBootTest어노테이션 제거 및 테스트 수정

* refactor:  Controller Application Context을 캐싱

* refactor:  todo 주석 추가

* refactor:  ObjectMapper빈으로 주입

* refactor: 오타 수정 및 테스트 병합

* refactor: ModifyCategoryOrderTest 복구

* refactor: MediumNotConnectedException 복구

* refactor: NotConnectedException.java 변경
  • Loading branch information
ingpyo authored Oct 6, 2023
1 parent a62f86a commit 6aba67c
Show file tree
Hide file tree
Showing 122 changed files with 4,902 additions and 1,334 deletions.
98 changes: 49 additions & 49 deletions .github/workflows/build-be-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,68 @@ on:
branches:
- develop
paths:
- "backend/**"
- 'backend/**'
workflow_dispatch:

permissions:
contents: read

jobs:
jobs:
build:
runs-on: ubuntu-latest
steps:
## jdk setting
- uses: actions/checkout@v3
with:
submodules: true
token: ${{ secrets.SUBMODULE_TOKEN }}
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "temurin" # https://github.com/actions/setup-java
cache: gradle
## jdk setting
- uses: actions/checkout@v3
with:
submodules: true
token: ${{ secrets.SUBMODULE_TOKEN }}
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin' # https://github.com/actions/setup-java
cache: gradle

## gradle caching
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
.gradle/caches
.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-
## gradle caching
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
.gradle/caches
.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-
## gradle build
- name: Test with Gradle
run: |
cd ./backend
./gradlew test
## gradle build
- name: Test with Gradle
run: |
cd ./backend
./gradlew test
- name: Build with Gradle
run: |
cd ./backend
./gradlew build -x test
- name: Build with Gradle
run: |
cd ./backend
./gradlew build -x test
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and push
uses: docker/build-push-action@v4
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/dong-gle-backend-dev:latest
platforms: linux/arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and push
uses: docker/build-push-action@v4
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/dong-gle-backend:latest
platforms: linux/arm64

deploy:
needs: build
uses: ./.github/workflows/deploy-dev.yml
Expand Down
100 changes: 50 additions & 50 deletions .github/workflows/build-be-prod.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
name: CICD for Backend Production
name: CICD for Backend Production

on:
push:
branches:
- main
paths:
- "backend/**"
- 'backend/**'
workflow_dispatch:

permissions:
contents: read

jobs:
jobs:
build:
runs-on: ubuntu-latest
steps:
## jdk setting
- uses: actions/checkout@v3
with:
submodules: true
token: ${{ secrets.SUBMODULE_TOKEN }}
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "temurin" # https://github.com/actions/setup-java
cache: gradle
## jdk setting
- uses: actions/checkout@v3
with:
submodules: true
token: ${{ secrets.SUBMODULE_TOKEN }}
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin' # https://github.com/actions/setup-java
cache: gradle

## gradle caching
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
.gradle/caches
.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-
## gradle caching
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
.gradle/caches
.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-
## gradle build
- name: Test with Gradle
run: |
cd ./backend
./gradlew test
## gradle build
- name: Test with Gradle
run: |
cd ./backend
./gradlew test
- name: Build with Gradle
run: |
cd ./backend
./gradlew build -x test
- name: Build with Gradle
run: |
cd ./backend
./gradlew build -x test
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and push
uses: docker/build-push-action@v4
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/dong-gle-backend-prod:latest
platforms: linux/arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and push
uses: docker/build-push-action@v4
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/dong-gle-backend:latest
platforms: linux/arm64

deploy:
needs: build
uses: ./.github/workflows/deploy-prod.yml
Expand Down
2 changes: 2 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ out/

### VS Code ###
.vscode/

*.DS_Store
1 change: 1 addition & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
runtimeOnly 'com.h2database:h2'
runtimeOnly 'mysql:mysql-connector-java:8.0.28'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'com.squareup.okhttp3:mockwebserver'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ w.status in (:statuses)
where w.id = :writingId and
w.status = 'ACTIVE'
""")
Optional<Writing> findByIdWithBlocks(@Param("writingId") Long writingId);
Optional<Writing> findByIdWithBlocks(@Param("writingId") final Long writingId);

@Query("SELECT b FROM NormalBlock b LEFT JOIN FETCH b.styles WHERE b IN :blocks")
List<NormalBlock> findStylesForBlocks(@Param("blocks") List<NormalBlock> blocks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
@Service
@RequiredArgsConstructor
public class AuthFacadeService {
private final LoginClients oauthClients; //APi
private final AuthService authService; //
private final LoginClients oauthClients;
private final AuthService authService;

public String createAuthorizeRedirectUri(final String socialType, final String redirect_uri) {
return oauthClients.redirectUri(SocialType.from(socialType), redirect_uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.donggle.backend.domain.writing.Writing;
import org.donggle.backend.domain.writing.block.Block;
import org.donggle.backend.domain.writing.block.NormalBlock;
import org.donggle.backend.exception.business.TistoryNotConnectedException;
import org.donggle.backend.exception.business.NotConnectedException;
import org.donggle.backend.exception.business.WritingAlreadyPublishedException;
import org.donggle.backend.exception.notfound.BlogNotFoundException;
import org.donggle.backend.exception.notfound.MemberNotFoundException;
Expand Down Expand Up @@ -45,15 +45,13 @@ public class PublishService {
public PublishWritingRequest findPublishWriting(final Long memberId, final Long writingId, final BlogType blogType) {
final Blog blog = findBlog(blogType);
final Member member = findMember(memberId);
final Writing writing = writingRepository.findByIdWithBlocks(writingId)
.orElseThrow(() -> new WritingNotFoundException(writingId));
final Writing writing = writingRepository.findByIdWithBlocks(writingId).orElseThrow(() -> new WritingNotFoundException(writingId));
findStylesByNomalBlocks(writing);

validateAuthorization(member.getId(), writing);

final MemberCredentials memberCredentials = findMemberCredentials(member);
final String accessToken = memberCredentials.getBlogToken(blogType)
.orElseThrow(TistoryNotConnectedException::new);
final String accessToken = memberCredentials.getBlogToken(blogType).orElseThrow(() -> new NotConnectedException(blogType));
final List<BlogWriting> publishedBlogs = blogWritingRepository.findByWritingId(writingId);

checkWritingAlreadyPublished(publishedBlogs, blog.getBlogType(), writing);
Expand All @@ -63,10 +61,7 @@ public PublishWritingRequest findPublishWriting(final Long memberId, final Long
private void findStylesByNomalBlocks(final Writing writing) {
final List<Block> blocks = writing.getBlocks();
final Set<BlockType> notNormalType = Set.of(CODE_BLOCK, IMAGE, HORIZONTAL_RULES);
final List<NormalBlock> normalBlocks = blocks.stream()
.filter(block -> !notNormalType.contains(block.getBlockType()))
.map(NormalBlock.class::cast)
.toList();
final List<NormalBlock> normalBlocks = blocks.stream().filter(block -> !notNormalType.contains(block.getBlockType())).map(NormalBlock.class::cast).toList();
writingRepository.findStylesForBlocks(normalBlocks);
}

Expand All @@ -76,19 +71,15 @@ public void saveProperties(final Blog blog, final Writing writing, final Publish


private MemberCredentials findMemberCredentials(final Member member) {
return memberCredentialsRepository.findByMember(member)
.orElseThrow(NoSuchElementException::new);
return memberCredentialsRepository.findByMember(member).orElseThrow(NoSuchElementException::new);
}

private Member findMember(final Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new MemberNotFoundException(memberId));
return memberRepository.findById(memberId).orElseThrow(() -> new MemberNotFoundException(memberId));
}

private void checkWritingAlreadyPublished(final List<BlogWriting> publishedBlogs, final BlogType blogType, final Writing writing) {
final boolean isAlreadyPublished = publishedBlogs.stream()
.anyMatch(blogWriting -> blogWriting.isSameBlogType(blogType)
&& writing.getUpdatedAt().isBefore(blogWriting.getPublishedAt()));
final boolean isAlreadyPublished = publishedBlogs.stream().anyMatch(blogWriting -> blogWriting.isSameBlogType(blogType) && writing.getUpdatedAt().isBefore(blogWriting.getPublishedAt()));

if (isAlreadyPublished) {
throw new WritingAlreadyPublishedException(writing.getId(), blogType);
Expand All @@ -104,8 +95,7 @@ private void validateAuthorization(final Long memberId, final Writing writing) {
private Blog findBlog(final BlogType blogType) {
for (final BlogType type : BlogType.values()) {
if (type.name().equals(blogType.name())) {
return blogRepository.findByBlogType(type)
.orElseThrow(() -> new BlogNotFoundException(blogType.name()));
return blogRepository.findByBlogType(type).orElseThrow(() -> new BlogNotFoundException(blogType.name()));
}
}
throw new BlogNotFoundException(blogType.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private List<PublishedDetailSimpleResponse> convertToPublishedDetailSimpleRespon
.toList();
}

private Writing findActiveWriting(Long writingId) {
private Writing findActiveWriting(final Long writingId) {
return writingRepository.findByIdAndStatus(writingId, ACTIVE)
.orElseThrow(() -> new WritingNotFoundException(writingId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ public class Category {
@JoinColumn(name = "member_id")
private Member member;

private Category(final CategoryName categoryName, final Category nextCategory, final Member member) {
public Category(final CategoryName categoryName, final Category nextCategory, final Member member) {
this.categoryName = categoryName;
this.nextCategory = nextCategory;
this.member = member;
}

public Category(final Long id, final CategoryName categoryName, final Category nextCategory, final Member member) {
this.id = id;
this.categoryName = categoryName;
this.nextCategory = nextCategory;
this.member = member;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public class AESEncryptionUtil {
private final SecretKeySpec secretKey;
private final IvParameterSpec iv;

public AESEncryptionUtil(@Value("${encrypt_secret_key}") final String secretKey, @Value("${encrypt_iv}") final String iv) {
public AESEncryptionUtil(
@Value("${encrypt_secret_key}") final String secretKey,
@Value("${encrypt_iv}") final String iv) {
this.secretKey = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), "AES");
this.iv = new IvParameterSpec(iv.getBytes(StandardCharsets.UTF_8));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Member extends BaseEntity {
@Enumerated(value = EnumType.STRING)
private SocialType socialType;

private Member(final Long id, final MemberName memberName, final Long socialId, final SocialType socialType) {
public Member(final Long id, final MemberName memberName, final Long socialId, final SocialType socialType) {
this.id = id;
this.memberName = memberName;
this.socialId = socialId;
Expand Down
Loading

0 comments on commit 6aba67c

Please sign in to comment.