-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/5 커뮤니티 게시글 생성 기능 #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
67262e0
test(community): communityBoard 생성 기능 테스트 작성
ayoung-dev 71cc807
feat(community): communityBoard Entity, Repository 추가
ayoung-dev ed349aa
feat(community): communityBoard RequestDto, Usercase 추가 및 Service 구현
ayoung-dev d6e8c5f
refactor(community): community -> communityBoard 파일 및 변수명 일괄 변경
ayoung-dev 15d32e6
Merge branch 'main' of https://github.com/prgrms-web-devcourse-final-…
ayoung-dev c2a8a73
test(community): communityBoard 생성 기능 테스트 수정
ayoung-dev bbd1b17
test(community): communityBoard 생성 기능 테스트 수정
ayoung-dev 1059054
refactor(community): Service 디렉토리 수정
ayoung-dev d0e0190
chore(community): CommunityBoard 엔티티 수정
ayoung-dev 61d8b41
chore(community): Service 수정
ayoung-dev d41a8c8
style(community): CommunityBoard 엔티티 공백 수정
ayoung-dev 3ebca85
Merge branch 'main' of https://github.com/prgrms-web-devcourse-final-…
ayoung-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/test/java/com/somemore/community/service/CreateCommunityServiceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package com.somemore.community.service; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import com.somemore.community.domain.CommunityBoard; | ||
| import com.somemore.community.dto.request.CommunityCreateRequestDto; | ||
| import com.somemore.community.repository.CommunityRepository; | ||
| import com.somemore.community.service.command.CreateCommunityService; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
| import org.springframework.test.context.ActiveProfiles; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
||
| @ActiveProfiles("test") | ||
| @EnableJpaAuditing | ||
| @SpringBootTest | ||
| public class CreateCommunityServiceTest { | ||
| @Autowired | ||
| private CreateCommunityService createCommunityService; | ||
| @Autowired | ||
| private CommunityRepository communityRepository; | ||
|
|
||
| @DisplayName("커뮤니티에 게시글을 등록한다.") | ||
| @Test | ||
| void createCommunityWithDto() { | ||
| //given | ||
| CommunityCreateRequestDto dto = CommunityCreateRequestDto.builder() | ||
| .title("커뮤니티 테스트 제목") | ||
| .content("커뮤니티 테스트 내용") | ||
| .build(); | ||
|
|
||
| UUID writerId = UUID.randomUUID(); | ||
| String imgUrl = "https://image.test.url/123"; | ||
|
|
||
| //when | ||
| Long communityId = createCommunityService.createCommunityBoard(dto, writerId, imgUrl); | ||
|
|
||
| //then | ||
| Optional<CommunityBoard> communityBoard = communityRepository.findById(communityId); | ||
|
|
||
| assertThat(communityBoard.isPresent()).isTrue(); | ||
| assertThat(communityBoard.get().getId()).isEqualTo(communityId); | ||
| assertThat(communityBoard.get().getWriterId()).isEqualTo(writerId); | ||
| assertThat(communityBoard.get().getTitle()).isEqualTo(dto.title()); | ||
| assertThat(communityBoard.get().getContent()).isEqualTo(dto.content()); | ||
| assertThat(communityBoard.get().getImgUrl()).isEqualTo(imgUrl); | ||
| } | ||
|
|
||
| @DisplayName("커뮤니티 게시글을 이미지 링크 없이 등록할 시 빈 문자열을 저장한다.") | ||
| @Test | ||
| void createCommunityWithoutImgUrl() { | ||
| //given | ||
| CommunityCreateRequestDto dto = CommunityCreateRequestDto.builder() | ||
| .title("커뮤니티 테스트 제목") | ||
| .content("커뮤니티 테스트 내용") | ||
| .build(); | ||
|
|
||
| UUID writerId = UUID.randomUUID(); | ||
| String imgUrl = null; | ||
|
|
||
| //when | ||
| Long communityId = createCommunityService.createCommunityBoard(dto, writerId, imgUrl); | ||
|
|
||
| //then | ||
| Optional<CommunityBoard> communityBoard = communityRepository.findById(communityId); | ||
|
|
||
| assertThat(communityBoard.isPresent()).isTrue(); | ||
| assertThat(communityBoard.get().getId()).isEqualTo(communityId); | ||
| assertThat(communityBoard.get().getWriterId()).isEqualTo(writerId); | ||
| assertThat(communityBoard.get().getTitle()).isEqualTo(dto.title()); | ||
| assertThat(communityBoard.get().getContent()).isEqualTo(dto.content()); | ||
| assertThat(communityBoard.get().getImgUrl()).isEqualTo(""); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.