-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Feat] 인사이트 작성 시 챌린지 기록 #133
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2ceeb83
[Feat] 인사이트 등록 시 챌린지 기록
heoboseong7 0f3d9ab
[Fix] 현재 참가중인 챌린지 조회 id 대신 엔티티로 조회
heoboseong7 12a4ab4
[Feat] 인서이트 생성 도메인 서비스 테스트, [Fix] ddl 오타 수정, 서랍 find 실패 시 예외 반환 코드 수정
heoboseong7 417b446
[Fix] 불필요 코드 삭제
heoboseong7 a0b1064
[Chore] getCurrentWeek 이름 변경
heoboseong7 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,2 @@ | ||
ALTER TABLE insight | ||
ADD COLUMN valid BIT NOT NULL |
This file contains 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 |
---|---|---|
|
@@ -49,8 +49,8 @@ public class CommentDomainServiceTest { | |
DatabaseCleaner databaseCleaner; | ||
|
||
User user = User.from(UserSignUpDto.of("vendorId", VendorType.NAVER, "[email protected]", null, null));; | ||
Insight insight = Insight.of(user, null, null, "인사이트 내용", Link.of("https://naver.com"));; | ||
Comment comment = Comment.of(insight, user, null, "댓글 내용");; | ||
Insight insight = Insight.of(user, null, null, "인사이트 내용", Link.of("https://naver.com"), false);; | ||
Comment comment = Comment.of(insight, user, null, "댓글 내용"); | ||
|
||
@BeforeEach | ||
void setup() { | ||
|
176 changes: 176 additions & 0 deletions
176
keewe-domain/src/test/java/ccc/keewedomain/service/insight/InsightDomainServiceTest.java
This file contains 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,176 @@ | ||
package ccc.keewedomain.service.insight; | ||
|
||
import ccc.keewecore.consts.KeeweRtnConsts; | ||
import ccc.keewecore.exception.KeeweException; | ||
import ccc.keewedomain.KeeweDomainApplication; | ||
import ccc.keewedomain.dto.insight.InsightCreateDto; | ||
import ccc.keewedomain.dto.user.UserSignUpDto; | ||
import ccc.keewedomain.persistence.domain.challenge.Challenge; | ||
import ccc.keewedomain.persistence.domain.challenge.ChallengeParticipation; | ||
import ccc.keewedomain.persistence.domain.common.Link; | ||
import ccc.keewedomain.persistence.domain.insight.Drawer; | ||
import ccc.keewedomain.persistence.domain.insight.Insight; | ||
import ccc.keewedomain.persistence.domain.user.User; | ||
import ccc.keewedomain.persistence.domain.user.enums.VendorType; | ||
import ccc.keewedomain.persistence.repository.challenge.ChallengeParticipationRepository; | ||
import ccc.keewedomain.persistence.repository.challenge.ChallengeRepository; | ||
import ccc.keewedomain.persistence.repository.insight.DrawerRepository; | ||
import ccc.keewedomain.persistence.repository.insight.InsightQueryRepository; | ||
import ccc.keewedomain.persistence.repository.insight.InsightRepository; | ||
import ccc.keewedomain.persistence.repository.insight.ReactionAggregationRepository; | ||
import ccc.keewedomain.persistence.repository.user.UserRepository; | ||
import ccc.keewedomain.utils.DatabaseCleaner; | ||
import ccc.keeweinfra.KeeweInfraApplication; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
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.test.context.ActiveProfiles; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
@SpringBootTest(classes = {KeeweDomainApplication.class, KeeweInfraApplication.class}) | ||
@TestPropertySource(properties = {"spring.config.location = classpath:application-domain.yml"}) | ||
@ActiveProfiles("test") | ||
public class InsightDomainServiceTest { | ||
|
||
@Autowired | ||
InsightDomainService insightDomainService; | ||
|
||
@Autowired | ||
UserRepository userRepository; | ||
|
||
@Autowired | ||
InsightRepository insightRepository; | ||
|
||
@Autowired | ||
InsightQueryRepository insightQueryRepository; | ||
|
||
@Autowired | ||
ChallengeRepository challengeRepository; | ||
|
||
@Autowired | ||
ChallengeParticipationRepository challengeParticipationRepository; | ||
|
||
@Autowired | ||
ReactionAggregationRepository reactionAggregationRepository; | ||
|
||
@Autowired | ||
DrawerRepository drawerRepository; | ||
|
||
@Autowired | ||
DatabaseCleaner databaseCleaner; | ||
|
||
User user = User.from(UserSignUpDto.of("vendorId", VendorType.NAVER, "[email protected]", null, null)); | ||
Insight insight = Insight.of(user, null, null, "인사이트 내용", Link.of("https://naver.com"), false); | ||
Challenge challenge = Challenge.of(user, "챌린지", "개발", "챌린지의 소개입니다."); | ||
ChallengeParticipation challengeParticipation = challenge.participate(user, "참가자 토픽", 2, 3); | ||
|
||
@BeforeEach | ||
void setup() { | ||
userRepository.save(user); | ||
insightRepository.save(insight); | ||
challengeRepository.save(challenge); | ||
} | ||
|
||
@AfterEach | ||
void clean() { | ||
databaseCleaner.execute(); | ||
} | ||
|
||
@Test | ||
@DisplayName("챌린지 기록 없이 인사이트 생성") | ||
void create_without_participate() { | ||
//given | ||
InsightCreateDto dto = InsightCreateDto.of(user.getId(), "인사이트 내용", "https://comic.naver.com", false, null); | ||
//when | ||
Insight insight = insightDomainService.create(dto); | ||
|
||
//then | ||
assertAll( | ||
() -> assertThat(insight.isValid()).isFalse(), | ||
() -> assertThat(insightRepository.findById(insight.getId())).isPresent() | ||
); | ||
} | ||
|
||
@Test | ||
@DisplayName("챌린지 기록하면서 인사이트 생성") | ||
void create_with_participate() { | ||
//given | ||
InsightCreateDto dto = InsightCreateDto.of(user.getId(), "인사이트 내용", "https://comic.naver.com", true, null); | ||
//when | ||
Insight newInsight = insightDomainService.create(dto); | ||
|
||
//then | ||
assertAll( | ||
() -> assertThat(newInsight.isValid()).isTrue(), | ||
() -> assertThat(insightRepository.findById(newInsight.getId())).isPresent(), | ||
() -> assertThat(insightQueryRepository.countValidForParticipation(newInsight.getChallengeParticipation())) | ||
.isEqualTo(1L) | ||
); | ||
} | ||
|
||
@Test | ||
@DisplayName("이번 주 목표 기록 완료 시 기록 불가능") | ||
void valid_false_if_completed() { | ||
//given | ||
List<InsightCreateDto> dtos = List.of( | ||
InsightCreateDto.of(user.getId(), "인사이트 내용1", "https://comic.naver.com", true, null), | ||
InsightCreateDto.of(user.getId(), "인사이트 내용2", "https://comic.naver.com", true, null), | ||
InsightCreateDto.of(user.getId(), "인사이트 내용3", "https://comic.naver.com", true, null) | ||
); | ||
|
||
//when | ||
List<Insight> insights = dtos.stream() | ||
.map(dto -> insightDomainService.create(dto)) | ||
.collect(Collectors.toList()); | ||
|
||
Insight insight1 = insights.get(0); | ||
Insight insight2 = insights.get(1); | ||
Insight insight3 = insights.get(2); | ||
|
||
//then | ||
assertAll( | ||
() -> assertThat(insight1.isValid()).isTrue(), | ||
() -> assertThat(insight2.isValid()).isTrue(), | ||
() -> assertThat(insight3.isValid()).isFalse(), | ||
() -> assertThat(insightQueryRepository.countValidForParticipation(insight3.getChallengeParticipation())) | ||
.isEqualTo(2L) | ||
); | ||
} | ||
|
||
@Test | ||
@DisplayName("서랍이 존재하지 않으면 실패") | ||
void throw_if_drawer_not_exist() { | ||
//given | ||
InsightCreateDto dto = InsightCreateDto.of(user.getId(), "인사이트 내용", "https://comic.naver.com", true, 9999L); | ||
|
||
//when, then | ||
assertThatThrownBy(() -> insightDomainService.create(dto)) | ||
.isExactlyInstanceOf(KeeweException.class) | ||
.hasMessage(KeeweRtnConsts.ERR440.getDescription()); | ||
} | ||
|
||
@Test | ||
@DisplayName("자신의 서랍이 아니면 실패") | ||
void throw_if_not_owner_of_drawer() { | ||
//given | ||
User other = User.from(UserSignUpDto.of("vendorId222", VendorType.NAVER, "[email protected]", null, null)); | ||
userRepository.save(other); | ||
Drawer drawer = drawerRepository.save(Drawer.of(other, "서랍")); | ||
InsightCreateDto dto = InsightCreateDto.of(user.getId(), "인사이트 내용", "https://comic.naver.com", true, drawer.getId()); | ||
|
||
//when, then | ||
assertThatThrownBy(() -> insightDomainService.create(dto)) | ||
.isExactlyInstanceOf(KeeweException.class) | ||
.hasMessage(KeeweRtnConsts.ERR444.getDescription()); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weeks 하니까 먼가 여려 주의 정보를 가져올거 같아여 ㅋㅋ 중요한건 아니긴 합니당
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요거만 바꾸고 머지할게요~