-
Notifications
You must be signed in to change notification settings - Fork 1
[LNK-45] 링크 테스트 코드 작성 (Usecase) #80
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
Open
soo0711
wants to merge
41
commits into
dev
Choose a base branch
from
LNK-45-Leenk-링크-테스트-코드-작성
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "LNK-45-Leenk-\uB9C1\uD06C-\uD14C\uC2A4\uD2B8-\uCF54\uB4DC-\uC791\uC131"
Open
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
25374c6
feat: test 의존성 추가
soo0711 461acbd
refactor: 불필요 설정 제거
soo0711 54933fb
refactor: 몽고디비용 base entity 추가
soo0711 8ba89bd
test: TestContainers 설정 및 테스트 추가
soo0711 f4edce1
test: 예시 테스트 추가
soo0711 e54aa3f
refactor: 불필요한 test 의존성 중복 제거
soo0711 a243241
refactor: Kotlin 테스트 의존성 추가
soo0711 fc5c53c
test: User 테스트 Fixture 추가
soo0711 ebd4a1c
test: Leenk 테스트 Fixture 추가
soo0711 ec64a2e
test: LeenkParticipants 테스트 Fixture 추가
soo0711 e217a14
test: Location 테스트 Fixture 추가
soo0711 74e0cb7
refactor: MockK 의존성 추가
soo0711 738d76b
fix: Java 21 빌드 오류 해결을 위한 Kotlin 버전 업그레이드
soo0711 fdefb58
test: LeenkUsecase Leenk 참여 기능 성공 테스트 추가
soo0711 2a3ec53
test: LeenkUsecase Leenk 모집 중이 아닌 링크 참여 시 예외 발생 테스트 추가
soo0711 b3560c0
test: LeenkUsecase Leenk 이미 참여한 사용자가 다시 참여 시 예외 발생 테스트 추가
soo0711 93d73d9
test: LeenkUsecase Leenk 최대 참여 인원 초과 시 예외 발생 테스트 추가
soo0711 fc47819
test: LeenkUsecase Leenk 최대 참여 인원 직전 참여 정상 처리 경계값 테스트 추가
soo0711 cf62bb2
test: participateLeenk 관련 모든 테스트를 @Nested 클래스로 통합
soo0711 990f4e4
test: LeenkUsecase closeLeenk 정상 동작 검증 테스트 추가
soo0711 4e606a4
test: LeenkUsecase Leenk 작성자가 아닌 사용자가 링크 마감 시도 시 예외 발생 검증
soo0711 ae7d5b6
test: LeenkUsecase Leenk 이미 마감된 링크를 다시 마감할 때 예외 발생 검증 테스트 추가
soo0711 adcb4c0
test: LeenkTestFixture에 마감된 링크 생성 createClosedLeenk 추가
soo0711 6686587
test: 중복된 closedLeenk 생성 코드를 Fixture로 해결
soo0711 5589dbe
test: LeenkTestFixture에 최대 참여 인원인 Leenk 생성 createFullLeenk 추가
soo0711 a750d78
test: fullLeenk 생성 코드를 Fixture로 해결
soo0711 18ac943
test: LeenkTestFixture에 거의 꽉 찬 링크 생성 createAlmostFullLeenk 추가
soo0711 7e5511f
test: almostFullLeenk 생성 코드를 Fixture로 해결
soo0711 9a18f93
test: 불필요한 Location 생성 제거
soo0711 2271960
test: finishedLeenk 생성 코드를 Fixture로 해결
soo0711 ef9b3a8
test: LeenkUsecase Leenk 완료된 상태의 링크 마감 시 예외 발생 검증 테스트 추가
soo0711 10d5349
chore: build.gradle~ 백업 파일 제거
soo0711 b9ce301
style: 개행 추가
soo0711 f5db8cf
refactor: 불필요한 의존성, 어노테이션 제거
soo0711 77b54de
refactor: LeenkUsecaseTest 생성자 의존성 가독성 개선
soo0711 15a9cff
refactor: LeenkUsecaseTest 최대 참여 인원 검증 하드코딩 제거
soo0711 ae4792c
refactor: LeenkUsecaseTest 불필요한 테스트 데이터 제거
soo0711 56ed51c
Merge branch 'dev' of https://github.com/Leets-Makers/Leenk-BE into L…
soo0711 aa4c05d
test: Kotlin 테스트 의존성 추가
soo0711 c9c818f
test: Kotlin 테스트 의존성 변경에 따라 테스트 코드 수정
soo0711 140c5b3
chore: Kotlin 소스 디렉터리 구조 변경
soo0711 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 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
12 changes: 4 additions & 8 deletions
12
src/main/java/leets/leenk/domain/notification/domain/entity/Notification.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
21 changes: 21 additions & 0 deletions
21
src/main/java/leets/leenk/global/common/entity/MongoBaseEntity.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,21 @@ | ||
| package leets.leenk.global.common.entity; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.experimental.SuperBuilder; | ||
| import org.springframework.data.annotation.CreatedDate; | ||
| import org.springframework.data.annotation.LastModifiedDate; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Getter | ||
| @SuperBuilder | ||
| @NoArgsConstructor | ||
| public abstract class MongoBaseEntity { | ||
|
|
||
| @CreatedDate | ||
| private LocalDateTime createDate; | ||
|
|
||
| @LastModifiedDate | ||
| private LocalDateTime updateDate; | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
| spring: | ||
| jpa: | ||
| hibernate: | ||
| ddl-auto: create-drop | ||
| show-sql: true | ||
| properties: | ||
| hibernate: | ||
| format_sql: true | ||
| dialect: org.hibernate.dialect.MySQL8Dialect |
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,19 @@ | ||
| package leets.leenk.config; | ||
|
|
||
| import org.springframework.boot.test.context.TestConfiguration; | ||
| import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.testcontainers.containers.MySQLContainer; | ||
|
|
||
| @TestConfiguration | ||
| public class MysqlTestConfig { | ||
|
|
||
| private static final String MYSQL_IMAGE = "mysql:8.0.41"; | ||
|
|
||
| @Bean | ||
| @ServiceConnection | ||
| public MySQLContainer<?> mysqlContainer() { | ||
| return new MySQLContainer<>(MYSQL_IMAGE) | ||
| .withDatabaseName("testdb"); | ||
| } | ||
| } |
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,30 @@ | ||
| package leets.leenk.config; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
| import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
| import org.springframework.context.annotation.Import; | ||
| import org.testcontainers.containers.MySQLContainer; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| @DataJpaTest | ||
| @Import(MysqlTestConfig.class) | ||
| @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) | ||
| class TestContainersTest { | ||
|
|
||
| @Autowired | ||
| private MySQLContainer<?> mysqlContainer; | ||
|
|
||
|
|
||
| @Test | ||
| void MySQL_컨테이너_정상_동작_테스트() { | ||
| // MySQL 컨테이너 테스트 | ||
| assertThat(mysqlContainer).isNotNull(); | ||
| assertThat(mysqlContainer.isRunning()).isTrue(); | ||
| assertThat(mysqlContainer.getDatabaseName()).isEqualTo("testdb"); | ||
|
|
||
| System.out.println("MySQL Container JDBC URL: " + mysqlContainer.getJdbcUrl()); | ||
| } | ||
| } |
83 changes: 83 additions & 0 deletions
83
src/test/java/leets/leenk/domain/user/domain/repository/UserRepositoryTest.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,83 @@ | ||
| package leets.leenk.domain.user.domain.repository; | ||
|
|
||
| import leets.leenk.config.MysqlTestConfig; | ||
| import leets.leenk.domain.user.domain.entity.User; | ||
| 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.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
| import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
| import org.springframework.context.annotation.Import; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| @DataJpaTest | ||
| @Import(MysqlTestConfig.class) | ||
| @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) | ||
| class UserRepositoryTest { | ||
|
|
||
| @Autowired | ||
| private UserRepository userRepository; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| userRepository.deleteAll(); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("특정 날짜에 생일인 활성 사용자만 이름순으로 조회한다") | ||
| void findAllUsersInBirthday() { | ||
| // given | ||
| LocalDate birthday = LocalDate.of(2000, 5, 15); | ||
|
|
||
| User activeUser1 = createUser(1L, "김철수", birthday, 1); | ||
| User activeUser2 = createUser(2L, "이영희", birthday, 1); | ||
| User activeUser3 = createUser(3L, "박민수", birthday, 1); | ||
|
|
||
| // 탈퇴한 사용자 (제외되어야 함) | ||
| User leftUser = createUser(4L, "탈퇴유저", birthday, 1); | ||
| leftUser.leave(); | ||
|
|
||
| // 삭제된 사용자 (제외되어야 함) | ||
| User deletedUser = createUser(5L, "삭제유저", birthday, 1); | ||
| deletedUser.delete(); | ||
|
|
||
| // 생일이 다른 사용자 (제외되어야 함) | ||
| User differentBirthdayUser = createUser(6L, "다른생일", LocalDate.of(2000, 6, 20), 1); | ||
|
|
||
| // 생일이 null인 사용자 (제외되어야 함) | ||
| User noBirthdayUser = createUser(7L, "생일없음", null, 1); | ||
|
|
||
| userRepository.saveAll(List.of( | ||
| activeUser1, activeUser2, activeUser3, | ||
| leftUser, deletedUser, differentBirthdayUser, noBirthdayUser | ||
| )); | ||
|
|
||
| // when | ||
| List<User> result = userRepository.findAllUsersInBirthday(5, 15); | ||
|
|
||
| // then | ||
| assertThat(result).hasSize(3); | ||
| assertThat(result).extracting(User::getName) | ||
| .containsExactly("김철수", "박민수", "이영희"); // 이름순 정렬 확인 | ||
| assertThat(result).allMatch(user -> user.getBirthday().equals(birthday)); | ||
| assertThat(result).allMatch(user -> user.getLeaveDate() == null); | ||
| assertThat(result).allMatch(user -> user.getDeleteDate() == null); | ||
| } | ||
|
|
||
| private User createUser(Long id, String name, LocalDate birthday, int cardinal) { | ||
| return User.builder() | ||
| .id(id) | ||
| .name(name) | ||
| .birthday(birthday) | ||
| .cardinal(cardinal) | ||
| .totalReactionCount(0) | ||
| .termsAgreement(true) | ||
| .privacyAgreement(true) | ||
| .build(); | ||
| } | ||
| } |
Oops, something went wrong.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: Leets-Makers/Leenk-BE
Length of output: 987
@EnableMongoAuditing어노테이션 설정이 누락되었습니다.@CreatedDate와@LastModifiedDate어노테이션이 작동하려면 애플리케이션 설정 클래스에@EnableMongoAuditing어노테이션을 추가해야 합니다. 현재 설정이 없으면createDate와updateDate필드가 자동으로 채워지지 않습니다. 애플리케이션 설정 파일(예:MongoConfig.java)에@EnableMongoAuditing을 추가하세요.🤖 Prompt for AI Agents