diff --git a/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/betting/BettingServiceTest.kt b/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/betting/BettingServiceTest.kt index 890280e..537785d 100644 --- a/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/betting/BettingServiceTest.kt +++ b/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/betting/BettingServiceTest.kt @@ -41,21 +41,25 @@ class BettingServiceTest : IntegrationTestSupport { val userEntity = UserEntity(nickname = Nickname("User1")) userRepository.save(userEntity) - val goalEntity = createGoalEntity(userEntity, BILLING, PROCEEDING, LocalDateTime.now(), LocalDateTime.now().plusDays(7)) + val goalEntity = createGoalEntity(userEntity, + BILLING, + PROCEEDING, + LocalDateTime.now(), + LocalDateTime.now().plusDays(7)) goalRepository.save(goalEntity) // when val betting = bettingService.create( - userId = userEntity.id, - goalId = goalEntity.id, - bettingPredictionType = BettingPredictionType.FAIL + userId = userEntity.id, + goalId = goalEntity.id, + bettingPredictionType = BettingPredictionType.FAIL ) // then assertThat(betting) - .isInstanceOfBetting() - .extractingBettingProperties() - .containsExactly(betting.userId, betting.goalId, betting.bettingPredictionType, betting.bettingResult) + .isInstanceOfBetting() + .extractingBettingProperties() + .containsExactly(betting.userId, betting.goalId, betting.bettingPredictionType, betting.bettingResult) } @DisplayName("Betting을 생성하는 중 요청한 userId에 해당하는 유저가 없는경우 예외가 발생한다.") @@ -65,15 +69,19 @@ class BettingServiceTest : IntegrationTestSupport { val userEntity = UserEntity(nickname = Nickname("User1")) userRepository.save(userEntity) - val goalEntity = createGoalEntity(userEntity, BILLING, PROCEEDING, LocalDateTime.now(), LocalDateTime.now().plusDays(7)) + val goalEntity = createGoalEntity(userEntity, + BILLING, + PROCEEDING, + LocalDateTime.now(), + LocalDateTime.now().plusDays(7)) goalRepository.save(goalEntity) // when // then assertThatThrownBy { bettingService.create( - userId = -1L, - goalId = goalEntity.id, - bettingPredictionType = BettingPredictionType.FAIL + userId = -1L, + goalId = goalEntity.id, + bettingPredictionType = BettingPredictionType.FAIL ) }.isInstanceOf(BaseException::class.java).hasMessage(ExceptionCode.E404_NOT_FOUND.message) } @@ -85,15 +93,19 @@ class BettingServiceTest : IntegrationTestSupport { val userEntity = UserEntity(nickname = Nickname("User1")) userRepository.save(userEntity) - val goalEntity = createGoalEntity(userEntity, BILLING, PROCEEDING, LocalDateTime.now(), LocalDateTime.now().plusDays(7)) + val goalEntity = createGoalEntity(userEntity, + BILLING, + PROCEEDING, + LocalDateTime.now(), + LocalDateTime.now().plusDays(7)) goalRepository.save(goalEntity) // when // then assertThatThrownBy { bettingService.create( - userId = userEntity.id, - goalId = -1L, - bettingPredictionType = BettingPredictionType.FAIL + userId = userEntity.id, + goalId = -1L, + bettingPredictionType = BettingPredictionType.FAIL ) }.isInstanceOf(BaseException::class.java).hasMessage(ExceptionCode.E404_NOT_FOUND.message) } @@ -105,14 +117,18 @@ class BettingServiceTest : IntegrationTestSupport { val userEntity = UserEntity(nickname = Nickname("User1")) userRepository.save(userEntity) - val goalEntity = createGoalEntity(userEntity, BILLING, PROCEEDING, LocalDateTime.now(), LocalDateTime.now().plusDays(7)) + val goalEntity = createGoalEntity(userEntity, + BILLING, + PROCEEDING, + LocalDateTime.now(), + LocalDateTime.now().plusDays(7)) goalRepository.save(goalEntity) val bettingEntity = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.PROCEEDING ) bettingRepository.save(bettingEntity) @@ -121,9 +137,9 @@ class BettingServiceTest : IntegrationTestSupport { // then assertThat(foundBetting) - .isInstanceOfBetting() - .extractingBettingProperties() - .contains(userEntity.id, goalEntity.id, BettingPredictionType.SUCCESS, BettingResult.PROCEEDING) + .isInstanceOfBetting() + .extractingBettingProperties() + .contains(userEntity.id, goalEntity.id, BettingPredictionType.SUCCESS, BettingResult.PROCEEDING) } @DisplayName("userId와 goalId를 갖는 Betting이 없는 경우 null를 반환한다.") @@ -134,14 +150,18 @@ class BettingServiceTest : IntegrationTestSupport { val userEntity2 = UserEntity(nickname = Nickname("User2")) userRepository.saveAll(listOf(userEntity1, userEntity2)) - val goalEntity = createGoalEntity(userEntity1, BILLING, PROCEEDING, LocalDateTime.now(), LocalDateTime.now().plusDays(7)) + val goalEntity = createGoalEntity(userEntity1, + BILLING, + PROCEEDING, + LocalDateTime.now(), + LocalDateTime.now().plusDays(7)) goalRepository.save(goalEntity) val bettingEntity = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity2, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.PROCEEDING ) bettingRepository.save(bettingEntity) @@ -160,20 +180,24 @@ class BettingServiceTest : IntegrationTestSupport { val userEntity2 = UserEntity(nickname = Nickname("User2")) userRepository.saveAll(listOf(userEntity1, userEntity2)) - val goalEntity = createGoalEntity(userEntity1, BILLING, PROCEEDING, LocalDateTime.now(), LocalDateTime.now().plusDays(7)) + val goalEntity = createGoalEntity(userEntity1, + BILLING, + PROCEEDING, + LocalDateTime.now(), + LocalDateTime.now().plusDays(7)) goalRepository.save(goalEntity) val bettingEntity = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity2, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.PROCEEDING ) bettingRepository.save(bettingEntity) // when // then assertThatThrownBy { bettingService.loadUserAndGoal(-1L, goalEntity.id) } - .isInstanceOf(BaseException::class.java).hasMessage(ExceptionCode.E404_NOT_FOUND.message) + .isInstanceOf(BaseException::class.java).hasMessage(ExceptionCode.E404_NOT_FOUND.message) } @DisplayName("userId와 goalId를 갖는 Betting을 조회할 때 goalId 해당하는 Goal이 없는 경우 예외가 발생한다.") @@ -184,20 +208,24 @@ class BettingServiceTest : IntegrationTestSupport { val userEntity2 = UserEntity(nickname = Nickname("User2")) userRepository.saveAll(listOf(userEntity1, userEntity2)) - val goalEntity = createGoalEntity(userEntity1, BILLING, PROCEEDING, LocalDateTime.now(), LocalDateTime.now().plusDays(7)) + val goalEntity = createGoalEntity(userEntity1, + BILLING, + PROCEEDING, + LocalDateTime.now(), + LocalDateTime.now().plusDays(7)) goalRepository.save(goalEntity) val bettingEntity = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity2, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.PROCEEDING ) bettingRepository.save(bettingEntity) // when // then assertThatThrownBy { bettingService.loadUserAndGoal(userEntity2.id, -1L) } - .isInstanceOf(BaseException::class.java).hasMessage(ExceptionCode.E404_NOT_FOUND.message) + .isInstanceOf(BaseException::class.java).hasMessage(ExceptionCode.E404_NOT_FOUND.message) } @DisplayName("goalId가 같은 Betting을 모두 조회한다.") @@ -208,44 +236,44 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.save(userEntity) val goalEntity1 = createGoalEntity( - userEntity = userEntity, - goalType = FREE, - goalResult = PROCEEDING, - startDateTime = LocalDateTime.now(), - endDateTime = LocalDateTime.now().plusDays(7) + userEntity = userEntity, + goalType = FREE, + goalResult = PROCEEDING, + startDateTime = LocalDateTime.now(), + endDateTime = LocalDateTime.now().plusDays(7) ) val goalEntity2 = createGoalEntity( - userEntity = userEntity, - goalType = BILLING, - goalResult = SUCCESS, - startDateTime = LocalDateTime.now(), - endDateTime = LocalDateTime.now().plusDays(7) + userEntity = userEntity, + goalType = BILLING, + goalResult = SUCCESS, + startDateTime = LocalDateTime.now(), + endDateTime = LocalDateTime.now().plusDays(7) ) goalRepository.saveAll(listOf(goalEntity1, goalEntity2)) val bettingEntity1 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity1, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity, + goalEntity = goalEntity1, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) val bettingEntity2 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity1, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity1, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) val bettingEntity3 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity2, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON, + userEntity = userEntity, + goalEntity = goalEntity2, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON, ) val bettingEntity4 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity2, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity2, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) bettingRepository.saveAll(listOf(bettingEntity1, bettingEntity2, bettingEntity3, bettingEntity4)) @@ -254,11 +282,17 @@ class BettingServiceTest : IntegrationTestSupport { // then assertThat(foundBettingList).hasSize(2) - .extractingBettingProperties() - .containsExactlyInAnyOrder( - tuple(bettingEntity1.userEntity.id, bettingEntity1.goalEntity.id, BettingPredictionType.FAIL, BettingResult.PROCEEDING), - tuple(bettingEntity2.userEntity.id, bettingEntity2.goalEntity.id, BettingPredictionType.SUCCESS, BettingResult.NO_GIFTICON), - ) + .extractingBettingProperties() + .containsExactlyInAnyOrder( + tuple(bettingEntity1.userEntity.id, + bettingEntity1.goalEntity.id, + BettingPredictionType.FAIL, + BettingResult.PROCEEDING), + tuple(bettingEntity2.userEntity.id, + bettingEntity2.goalEntity.id, + BettingPredictionType.SUCCESS, + BettingResult.NO_GIFTICON), + ) } @DisplayName("goalId가 같은 Betting을 모두 조회하는 중 goalId에 해당하는 Goal이 없는 경우 예외가 발생한다.") @@ -269,51 +303,51 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.save(userEntity) val goalEntity1 = createGoalEntity( - userEntity = userEntity, - goalType = FREE, - goalResult = PROCEEDING, - startDateTime = LocalDateTime.now(), - endDateTime = LocalDateTime.now().plusDays(7) + userEntity = userEntity, + goalType = FREE, + goalResult = PROCEEDING, + startDateTime = LocalDateTime.now(), + endDateTime = LocalDateTime.now().plusDays(7) ) val goalEntity2 = createGoalEntity( - userEntity = userEntity, - goalType = BILLING, - goalResult = SUCCESS, - startDateTime = LocalDateTime.now(), - endDateTime = LocalDateTime.now().plusDays(7) + userEntity = userEntity, + goalType = BILLING, + goalResult = SUCCESS, + startDateTime = LocalDateTime.now(), + endDateTime = LocalDateTime.now().plusDays(7) ) goalRepository.saveAll(listOf(goalEntity1, goalEntity2)) val bettingEntity1 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity1, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity, + goalEntity = goalEntity1, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) val bettingEntity2 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity1, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity1, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) val bettingEntity3 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity2, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON, + userEntity = userEntity, + goalEntity = goalEntity2, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON, ) val bettingEntity4 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity2, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity2, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) bettingRepository.saveAll(listOf(bettingEntity1, bettingEntity2, bettingEntity3, bettingEntity4)) // when // then assertThatThrownBy { bettingService.findAllByGoalId(-1L) } - .isInstanceOf(BaseException::class.java) - .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) } @DisplayName("id에 해당하는 Betting이 있으면 조회한다.") @@ -324,37 +358,37 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.save(userEntity) val goalEntity = createGoalEntity( - userEntity = userEntity, - goalType = FREE, - goalResult = PROCEEDING, - startDateTime = LocalDateTime.now(), - endDateTime = LocalDateTime.now().plusDays(7) + userEntity = userEntity, + goalType = FREE, + goalResult = PROCEEDING, + startDateTime = LocalDateTime.now(), + endDateTime = LocalDateTime.now().plusDays(7) ) goalRepository.save(goalEntity) val bettingEntity1 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) val bettingEntity2 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) val bettingEntity3 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON, + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON, ) val bettingEntity4 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) bettingRepository.saveAll(listOf(bettingEntity1, bettingEntity2, bettingEntity3, bettingEntity4)) @@ -363,10 +397,10 @@ class BettingServiceTest : IntegrationTestSupport { // then assertThat(foundBetting) - .isNotNull - .isInstanceOfBetting() - .extractingBettingProperties() - .containsExactly(userEntity.id, goalEntity.id, BettingPredictionType.FAIL, BettingResult.PROCEEDING) + .isNotNull + .isInstanceOfBetting() + .extractingBettingProperties() + .containsExactly(userEntity.id, goalEntity.id, BettingPredictionType.FAIL, BettingResult.PROCEEDING) } @DisplayName("id에 해당하는 Betting이 없으면 null을 반환한다.") @@ -377,25 +411,25 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.save(userEntity) val goalEntity = createGoalEntity( - userEntity = userEntity, - goalType = FREE, - goalResult = PROCEEDING, - startDateTime = LocalDateTime.now(), - endDateTime = LocalDateTime.now().plusDays(7) + userEntity = userEntity, + goalType = FREE, + goalResult = PROCEEDING, + startDateTime = LocalDateTime.now(), + endDateTime = LocalDateTime.now().plusDays(7) ) goalRepository.save(goalEntity) val bettingEntity1 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) val bettingEntity2 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) bettingRepository.saveAll(listOf(bettingEntity1, bettingEntity2)) @@ -404,7 +438,7 @@ class BettingServiceTest : IntegrationTestSupport { // then assertThat(foundBetting) - .isNull() + .isNull() } @DisplayName("요청한 userId에 해당하는 Betting을 모두 조회한다.") @@ -416,37 +450,37 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.saveAll(listOf(userEntity1, userEntity2)) val goalEntity = createGoalEntity( - userEntity = userEntity1, - goalType = FREE, - goalResult = PROCEEDING, - startDateTime = LocalDateTime.now(), - endDateTime = LocalDateTime.now().plusDays(7) + userEntity = userEntity1, + goalType = FREE, + goalResult = PROCEEDING, + startDateTime = LocalDateTime.now(), + endDateTime = LocalDateTime.now().plusDays(7) ) goalRepository.save(goalEntity) val bettingEntity1 = BettingEntity( - userEntity = userEntity1, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity1, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) val bettingEntity2 = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity2, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) val bettingEntity3 = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON, + userEntity = userEntity2, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON, ) val bettingEntity4 = BettingEntity( - userEntity = userEntity1, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity1, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) bettingRepository.saveAll(listOf(bettingEntity1, bettingEntity2, bettingEntity3, bettingEntity4)) @@ -455,11 +489,11 @@ class BettingServiceTest : IntegrationTestSupport { // then assertThat(foundBettingList).hasSize(2) - .extractingBettingProperties() - .containsExactlyInAnyOrder( - tuple(userEntity1.id, goalEntity.id, BettingPredictionType.FAIL, BettingResult.PROCEEDING), - tuple(userEntity1.id, goalEntity.id, BettingPredictionType.SUCCESS, BettingResult.NO_GIFTICON), - ) + .extractingBettingProperties() + .containsExactlyInAnyOrder( + tuple(userEntity1.id, goalEntity.id, BettingPredictionType.FAIL, BettingResult.PROCEEDING), + tuple(userEntity1.id, goalEntity.id, BettingPredictionType.SUCCESS, BettingResult.NO_GIFTICON), + ) } @DisplayName("요청한 userId에 해당하는 Betting을 모두 조회하는 중 userId에 해당하는 사용자가 없으면 예외가 발생한다.") @@ -471,43 +505,43 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.saveAll(listOf(userEntity1, userEntity2)) val goalEntity = createGoalEntity( - userEntity = userEntity1, - goalType = FREE, - goalResult = PROCEEDING, - startDateTime = LocalDateTime.now(), - endDateTime = LocalDateTime.now().plusDays(7) + userEntity = userEntity1, + goalType = FREE, + goalResult = PROCEEDING, + startDateTime = LocalDateTime.now(), + endDateTime = LocalDateTime.now().plusDays(7) ) goalRepository.save(goalEntity) val bettingEntity1 = BettingEntity( - userEntity = userEntity1, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity1, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) val bettingEntity2 = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity2, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) val bettingEntity3 = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON, + userEntity = userEntity2, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON, ) val bettingEntity4 = BettingEntity( - userEntity = userEntity1, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity1, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) bettingRepository.saveAll(listOf(bettingEntity1, bettingEntity2, bettingEntity3, bettingEntity4)) // when // then assertThatThrownBy { bettingService.findAllByUserId(-1L) } - .isInstanceOf(BaseException::class.java).hasMessage(ExceptionCode.E404_NOT_FOUND.message) + .isInstanceOf(BaseException::class.java).hasMessage(ExceptionCode.E404_NOT_FOUND.message) } @DisplayName("요청한 userId에 해당하며 Betting의 endDate가 현재보다 큰 경우의 Betting이 있으면 true를 반환한다.") @@ -521,44 +555,44 @@ class BettingServiceTest : IntegrationTestSupport { val startDateTime = LocalDateTime.now() val endDateTime = startDateTime.plusDays(7L) val goalEntity1 = createGoalEntity( - userEntity = userEntity1, - goalType = FREE, - goalResult = PROCEEDING, - startDateTime = startDateTime.minusSeconds(1L), - endDateTime = startDateTime, + userEntity = userEntity1, + goalType = FREE, + goalResult = PROCEEDING, + startDateTime = startDateTime.minusSeconds(1L), + endDateTime = startDateTime, ) val goalEntity2 = createGoalEntity( - userEntity = userEntity1, - goalType = FREE, - goalResult = PROCEEDING, - startDateTime = startDateTime, - endDateTime = endDateTime, + userEntity = userEntity1, + goalType = FREE, + goalResult = PROCEEDING, + startDateTime = startDateTime, + endDateTime = endDateTime, ) goalRepository.saveAll(listOf(goalEntity1, goalEntity2)) val bettingEntity1 = BettingEntity( - userEntity = userEntity1, - goalEntity = goalEntity1, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity1, + goalEntity = goalEntity1, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) val bettingEntity2 = BettingEntity( - userEntity = userEntity1, - goalEntity = goalEntity2, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity1, + goalEntity = goalEntity2, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) val bettingEntity3 = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity1, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON, + userEntity = userEntity2, + goalEntity = goalEntity1, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON, ) val bettingEntity4 = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity2, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity2, + goalEntity = goalEntity2, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) bettingRepository.saveAll(listOf(bettingEntity1, bettingEntity2, bettingEntity3, bettingEntity4)) @@ -580,44 +614,44 @@ class BettingServiceTest : IntegrationTestSupport { val startDateTime = LocalDateTime.now() val endDateTime = startDateTime.plusDays(7L) val goalEntity1 = createGoalEntity( - userEntity = userEntity1, - goalType = FREE, - goalResult = PROCEEDING, - startDateTime = startDateTime.minusSeconds(1L), - endDateTime = startDateTime, + userEntity = userEntity1, + goalType = FREE, + goalResult = PROCEEDING, + startDateTime = startDateTime.minusSeconds(1L), + endDateTime = startDateTime, ) val goalEntity2 = createGoalEntity( - userEntity = userEntity1, - goalType = FREE, - goalResult = PROCEEDING, - startDateTime = startDateTime, - endDateTime = endDateTime, + userEntity = userEntity1, + goalType = FREE, + goalResult = PROCEEDING, + startDateTime = startDateTime, + endDateTime = endDateTime, ) goalRepository.saveAll(listOf(goalEntity1, goalEntity2)) val bettingEntity1 = BettingEntity( - userEntity = userEntity1, - goalEntity = goalEntity1, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity1, + goalEntity = goalEntity1, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) val bettingEntity2 = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity2, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity2, + goalEntity = goalEntity2, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) val bettingEntity3 = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity1, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON, + userEntity = userEntity2, + goalEntity = goalEntity1, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON, ) val bettingEntity4 = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity2, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity2, + goalEntity = goalEntity2, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) bettingRepository.saveAll(listOf(bettingEntity1, bettingEntity2, bettingEntity3, bettingEntity4)) @@ -639,51 +673,51 @@ class BettingServiceTest : IntegrationTestSupport { val startDateTime = LocalDateTime.now() val endDateTime = startDateTime.plusDays(7L) val goalEntity1 = createGoalEntity( - userEntity = userEntity1, - goalType = FREE, - goalResult = PROCEEDING, - startDateTime = startDateTime.minusSeconds(1L), - endDateTime = startDateTime, + userEntity = userEntity1, + goalType = FREE, + goalResult = PROCEEDING, + startDateTime = startDateTime.minusSeconds(1L), + endDateTime = startDateTime, ) val goalEntity2 = createGoalEntity( - userEntity = userEntity1, - goalType = FREE, - goalResult = PROCEEDING, - startDateTime = startDateTime, - endDateTime = endDateTime, + userEntity = userEntity1, + goalType = FREE, + goalResult = PROCEEDING, + startDateTime = startDateTime, + endDateTime = endDateTime, ) goalRepository.saveAll(listOf(goalEntity1, goalEntity2)) val bettingEntity1 = BettingEntity( - userEntity = userEntity1, - goalEntity = goalEntity1, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity1, + goalEntity = goalEntity1, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) val bettingEntity2 = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity2, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity2, + goalEntity = goalEntity2, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) val bettingEntity3 = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity1, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON, + userEntity = userEntity2, + goalEntity = goalEntity1, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON, ) val bettingEntity4 = BettingEntity( - userEntity = userEntity2, - goalEntity = goalEntity2, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity2, + goalEntity = goalEntity2, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) bettingRepository.saveAll(listOf(bettingEntity1, bettingEntity2, bettingEntity3, bettingEntity4)) // when // then assertThatThrownBy { bettingService.existsBettingParticipantUser(-1L) } - .isInstanceOf(BaseException::class.java) - .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) } @DisplayName("요청한 id에 해당하는 Betting의 BettingPredictionType을 변경한다.") @@ -694,17 +728,17 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.save(userEntity) val goalEntity = createGoalEntity( - userEntity = userEntity, - goalType = FREE, - goalResult = PROCEEDING + userEntity = userEntity, + goalType = FREE, + goalResult = PROCEEDING ) goalRepository.save(goalEntity) val bettingEntity = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) bettingRepository.save(bettingEntity) @@ -713,7 +747,7 @@ class BettingServiceTest : IntegrationTestSupport { // then assertThat(foundBetting.bettingPredictionType) - .isEqualTo(BettingPredictionType.SUCCESS) + .isEqualTo(BettingPredictionType.SUCCESS) } @DisplayName("요청한 id에 해당하는 Betting의 Predictiontype을 변경하는 중 해당하는 id의 Betting이 없는 경우 예외가 발생한다.") @@ -724,24 +758,24 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.save(userEntity) val goalEntity = createGoalEntity( - userEntity = userEntity, - goalType = FREE, - goalResult = PROCEEDING + userEntity = userEntity, + goalType = FREE, + goalResult = PROCEEDING ) goalRepository.save(goalEntity) val bettingEntity = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) bettingRepository.save(bettingEntity) // when // then assertThatThrownBy { bettingService.updatePredictionType(-1L, BettingPredictionType.SUCCESS) } - .isInstanceOf(BaseException::class.java) - .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) } @DisplayName("요청한 id에 해당하는 Betting의 BettingResult를 변경한다.") @@ -752,17 +786,17 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.save(userEntity) val goalEntity = createGoalEntity( - userEntity = userEntity, - goalType = FREE, - goalResult = PROCEEDING + userEntity = userEntity, + goalType = FREE, + goalResult = PROCEEDING ) goalRepository.save(goalEntity) val bettingEntity = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) bettingRepository.save(bettingEntity) @@ -781,24 +815,24 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.save(userEntity) val goalEntity = createGoalEntity( - userEntity = userEntity, - goalType = FREE, - goalResult = PROCEEDING + userEntity = userEntity, + goalType = FREE, + goalResult = PROCEEDING ) goalRepository.save(goalEntity) val bettingEntity = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) bettingRepository.save(bettingEntity) // when // then assertThatThrownBy { bettingService.updateResult(-1L, BettingResult.NO_GIFTICON) } - .isInstanceOf(BaseException::class.java) - .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) } @DisplayName("ids 안에 포함된 id의 베팅의 Result를 변경한다.") @@ -809,47 +843,47 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.save(userEntity) val goalEntity = createGoalEntity( - userEntity = userEntity, - goalType = FREE, - goalResult = PROCEEDING + userEntity = userEntity, + goalType = FREE, + goalResult = PROCEEDING ) goalRepository.save(goalEntity) val bettingEntity1 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) val bettingEntity2 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) val bettingEntity3 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON, + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON, ) val bettingEntity4 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) bettingRepository.saveAll(listOf(bettingEntity1, bettingEntity2, bettingEntity3, bettingEntity4)) // when val updatedBettingCount = bettingService.bulkModifyingByResultWhereIdInIds( - bettingResult = BettingResult.GET_GIFTICON, - bettingIds = listOf(bettingEntity1, bettingEntity2, bettingEntity3).map { it.id }.toSet() + bettingResult = BettingResult.GET_GIFTICON, + bettingIds = listOf(bettingEntity1, bettingEntity2, bettingEntity3).map { it.id }.toSet() ) // then assertThat(updatedBettingCount) - .isEqualTo(3) + .isEqualTo(3) } @DisplayName("bettingId에 해당하는 Betting을 hard-delete 한다.") @@ -860,35 +894,35 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.save(userEntity) val goalEntity = createGoalEntity( - userEntity = userEntity, - goalType = FREE, - goalResult = PROCEEDING + userEntity = userEntity, + goalType = FREE, + goalResult = PROCEEDING ) goalRepository.save(goalEntity) val bettingEntity1 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) val bettingEntity2 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) val bettingEntity3 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON, + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON, ) val bettingEntity4 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) bettingRepository.saveAll(listOf(bettingEntity1, bettingEntity2, bettingEntity3, bettingEntity4)) @@ -897,7 +931,7 @@ class BettingServiceTest : IntegrationTestSupport { // then assertThat(bettingRepository.findByIdOrNull(bettingEntity1.id)) - .isNull() + .isNull() } @DisplayName("bettingId에 해당하는 Betting을 hard-delete 하는 중 bettingId 해당하는 Betting이 없는 경우 예외가 발생한다.") @@ -908,42 +942,42 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.save(userEntity) val goalEntity = createGoalEntity( - userEntity = userEntity, - goalType = FREE, - goalResult = PROCEEDING + userEntity = userEntity, + goalType = FREE, + goalResult = PROCEEDING ) goalRepository.save(goalEntity) val bettingEntity1 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) val bettingEntity2 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) val bettingEntity3 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON, + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON, ) val bettingEntity4 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) bettingRepository.saveAll(listOf(bettingEntity1, bettingEntity2, bettingEntity3, bettingEntity4)) // when // then assertThatThrownBy { bettingService.hardDelete(-1L) } - .isInstanceOf(BaseException::class.java) - .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) } @DisplayName("userId에 해당하는 Betting을 hard-delete한다.") @@ -954,35 +988,35 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.save(userEntity) val goalEntity = createGoalEntity( - userEntity = userEntity, - goalType = FREE, - goalResult = PROCEEDING + userEntity = userEntity, + goalType = FREE, + goalResult = PROCEEDING ) goalRepository.save(goalEntity) val bettingEntity1 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) val bettingEntity2 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) val bettingEntity3 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON, + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON, ) val bettingEntity4 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) bettingRepository.saveAll(listOf(bettingEntity1, bettingEntity2, bettingEntity3, bettingEntity4)) @@ -990,8 +1024,11 @@ class BettingServiceTest : IntegrationTestSupport { bettingService.hardDeleteByUserId(userEntity.id) // then - assertThat(bettingRepository.findAllById(setOf(bettingEntity1.id, bettingEntity2.id, bettingEntity3.id, bettingEntity4.id))) - .isEmpty() + assertThat(bettingRepository.findAllById(setOf(bettingEntity1.id, + bettingEntity2.id, + bettingEntity3.id, + bettingEntity4.id))) + .isEmpty() } @DisplayName("userId에 해당하는 Betting을 hard-delete하는 중 해당하는 userId가 없는 경우 예외가 발생한다.") @@ -1002,64 +1039,70 @@ class BettingServiceTest : IntegrationTestSupport { userRepository.save(userEntity) val goalEntity = createGoalEntity( - userEntity = userEntity, - goalType = FREE, - goalResult = PROCEEDING + userEntity = userEntity, + goalType = FREE, + goalResult = PROCEEDING ) goalRepository.save(goalEntity) val bettingEntity1 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.FAIL, - bettingResult = BettingResult.PROCEEDING + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.FAIL, + bettingResult = BettingResult.PROCEEDING ) val bettingEntity2 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) val bettingEntity3 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON, + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON, ) val bettingEntity4 = BettingEntity( - userEntity = userEntity, - goalEntity = goalEntity, - bettingPredictionType = BettingPredictionType.SUCCESS, - bettingResult = BettingResult.NO_GIFTICON + userEntity = userEntity, + goalEntity = goalEntity, + bettingPredictionType = BettingPredictionType.SUCCESS, + bettingResult = BettingResult.NO_GIFTICON ) bettingRepository.saveAll(listOf(bettingEntity1, bettingEntity2, bettingEntity3, bettingEntity4)) // when // then assertThatThrownBy { bettingService.hardDeleteByUserId(-1L) } - .isInstanceOf(BaseException::class.java) - .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) } private fun ObjectAssert<*>.isInstanceOfBetting() = isInstanceOf(Betting::class.java) - private fun ObjectAssert<*>.extractingBettingProperties() = extracting("userId", "goalId", "bettingPredictionType", "bettingResult") + private fun ObjectAssert<*>.extractingBettingProperties() = extracting("userId", + "goalId", + "bettingPredictionType", + "bettingResult") - private fun ListAssert<*>.extractingBettingProperties() = extracting("userId", "goalId", "bettingPredictionType", "bettingResult") + private fun ListAssert<*>.extractingBettingProperties() = extracting("userId", + "goalId", + "bettingPredictionType", + "bettingResult") private fun createGoalEntity( - userEntity: UserEntity, - goalType: GoalType, - goalResult: GoalResult, - startDateTime: LocalDateTime = LocalDateTime.now(), - endDateTime: LocalDateTime = startDateTime.plusDays(7L) + userEntity: UserEntity, + goalType: GoalType, + goalResult: GoalResult, + startDateTime: LocalDateTime = LocalDateTime.now(), + endDateTime: LocalDateTime = startDateTime.plusDays(7L) ): GoalEntity { return GoalEntity( - userEntity = userEntity, - goalType = goalType, - content = Content("sampleContent"), - goalResult = goalResult, - startDate = startDateTime, - endDate = endDateTime + userEntity = userEntity, + goalType = goalType, + content = Content("sampleContent"), + goalResult = goalResult, + startDate = startDateTime, + endDate = endDateTime ) } } \ No newline at end of file diff --git a/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/gifticon/GifticonServiceTest.kt b/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/gifticon/GifticonServiceTest.kt index b707bc5..e48c74e 100644 --- a/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/gifticon/GifticonServiceTest.kt +++ b/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/gifticon/GifticonServiceTest.kt @@ -31,9 +31,9 @@ class GifticonServiceTest : IntegrationTestSupport { fun create1() { // given val user = UserEntity( - oauthTokenPayload = null, - fcmTokenPayload = null, - nickname = Nickname("UserNickname1") + oauthTokenPayload = null, + fcmTokenPayload = null, + nickname = Nickname("UserNickname1") ) userRepository.save(user) @@ -44,9 +44,9 @@ class GifticonServiceTest : IntegrationTestSupport { // then assertThat(foundGifticon) - .isInstanceOfGifticon() - .extracting("userId", "url") - .contains(user.id, URL(url)) + .isInstanceOfGifticon() + .extracting("userId", "url") + .contains(user.id, URL(url)) } @DisplayName("userId와 url를 입력받아 Gifticon을 생성할 때 요청한 userId에 해당하는 유저가 없는 경우 예외가 발생한다.") @@ -54,9 +54,9 @@ class GifticonServiceTest : IntegrationTestSupport { fun create2() { // given val user = UserEntity( - oauthTokenPayload = null, - fcmTokenPayload = null, - nickname = Nickname("UserNickname1") + oauthTokenPayload = null, + fcmTokenPayload = null, + nickname = Nickname("UserNickname1") ) userRepository.save(user) @@ -64,8 +64,8 @@ class GifticonServiceTest : IntegrationTestSupport { // when // then assertThatThrownBy { gifticonService.create(-1L, url) } - .isInstanceOf(BaseException::class.java) - .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) } @DisplayName("요청한 id에 해당하는 Gifticon을 조회한다.") @@ -73,9 +73,9 @@ class GifticonServiceTest : IntegrationTestSupport { fun findById1() { // given val user = UserEntity( - oauthTokenPayload = null, - fcmTokenPayload = null, - nickname = Nickname("UserNickname1") + oauthTokenPayload = null, + fcmTokenPayload = null, + nickname = Nickname("UserNickname1") ) userRepository.save(user) @@ -88,9 +88,9 @@ class GifticonServiceTest : IntegrationTestSupport { // then assertThat(foundGifticon) - .isInstanceOfGifticon() - .extracting("userId", "url") - .contains(user.id, url) + .isInstanceOfGifticon() + .extracting("userId", "url") + .contains(user.id, url) } @DisplayName("요청한 id에 해당하는 Gifticon을 조회하는 중 해당하는 Gifticon이 없는 경우 예외가 발생한다.") @@ -98,9 +98,9 @@ class GifticonServiceTest : IntegrationTestSupport { fun findById2() { // given val user = UserEntity( - oauthTokenPayload = null, - fcmTokenPayload = null, - nickname = Nickname("UserNickname1") + oauthTokenPayload = null, + fcmTokenPayload = null, + nickname = Nickname("UserNickname1") ) userRepository.save(user) @@ -110,8 +110,8 @@ class GifticonServiceTest : IntegrationTestSupport { // when // then assertThatThrownBy { gifticonService.findById(-1L) } - .isInstanceOf(BaseException::class.java) - .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) } @DisplayName("요청한 userId를 갖는 Gifticon을 hard-delete한다.") @@ -119,9 +119,9 @@ class GifticonServiceTest : IntegrationTestSupport { fun hardDeleteByUserId1() { // given val user = UserEntity( - oauthTokenPayload = null, - fcmTokenPayload = null, - nickname = Nickname("UserNickname1") + oauthTokenPayload = null, + fcmTokenPayload = null, + nickname = Nickname("UserNickname1") ) userRepository.save(user) @@ -134,7 +134,7 @@ class GifticonServiceTest : IntegrationTestSupport { // then assertThat(gifticonRepositry.findByIdOrNull(gifticon1.id)) - .isNull() + .isNull() } @DisplayName("요청한 userId를 갖는 Gifticon을 hard-delete 하는 중 userId에 해당하는 User가 없으면 예외가 발생한다.") @@ -142,9 +142,9 @@ class GifticonServiceTest : IntegrationTestSupport { fun hardDeleteByUserId2() { // given val user = UserEntity( - oauthTokenPayload = null, - fcmTokenPayload = null, - nickname = Nickname("UserNickname1") + oauthTokenPayload = null, + fcmTokenPayload = null, + nickname = Nickname("UserNickname1") ) userRepository.save(user) @@ -154,8 +154,8 @@ class GifticonServiceTest : IntegrationTestSupport { // when // then assertThatThrownBy { gifticonService.hardDeleteByUserId(-1L) } - .isInstanceOf(BaseException::class.java) - .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) } private fun ObjectAssert<*>.isInstanceOfGifticon() = isInstanceOf(Gifticon::class.java) diff --git a/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/goalproof/GoalProofRepositoryTest.kt b/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/goalproof/GoalProofRepositoryTest.kt index daddeba..8442f94 100644 --- a/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/goalproof/GoalProofRepositoryTest.kt +++ b/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/goalproof/GoalProofRepositoryTest.kt @@ -38,8 +38,8 @@ class GoalProofRepositoryTest : IntegrationTestSupport { val userEntity2 = UserEntity(nickname = Nickname("User2")) userRepository.saveAll(listOf(userEntity1, userEntity2)) - val goalEntity1 = createGoalProofEntity(userEntity1, BILLING, PROCEEDING) - val goalEntity2 = createGoalProofEntity(userEntity1, FREE, SUCCESS) + val goalEntity1 = createGoalEntity(userEntity1, BILLING, PROCEEDING) + val goalEntity2 = createGoalEntity(userEntity1, FREE, SUCCESS) goalRepository.saveAll(listOf(goalEntity1, goalEntity2)) val goalProofEntity1 = createGoalProofEntity(userEntity1, goalEntity1) @@ -65,7 +65,7 @@ class GoalProofRepositoryTest : IntegrationTestSupport { val userEntity2 = UserEntity(nickname = Nickname("User2")) userRepository.saveAll(listOf(userEntity1, userEntity2)) - val goalEntity = createGoalProofEntity(userEntity1, BILLING, PROCEEDING) + val goalEntity = createGoalEntity(userEntity1, BILLING, PROCEEDING) goalRepository.save(goalEntity) val goalProofEntity1 = createGoalProofEntity(userEntity1, goalEntity) @@ -90,7 +90,7 @@ class GoalProofRepositoryTest : IntegrationTestSupport { val userEntity = UserEntity(nickname = Nickname("User1")) userRepository.save(userEntity) - val goalEntity = createGoalProofEntity(userEntity, BILLING, PROCEEDING) + val goalEntity = createGoalEntity(userEntity, BILLING, PROCEEDING) goalRepository.save(goalEntity) val todayStartDateTime = LocalDateTime.now().minusDays(2) @@ -127,7 +127,7 @@ class GoalProofRepositoryTest : IntegrationTestSupport { val userEntity = UserEntity(nickname = Nickname("User1")) userRepository.save(userEntity) - val goalEntity = createGoalProofEntity(userEntity, BILLING, PROCEEDING) + val goalEntity = createGoalEntity(userEntity, BILLING, PROCEEDING) goalRepository.save(goalEntity) val targetDateTime = LocalDateTime.now() @@ -178,8 +178,8 @@ class GoalProofRepositoryTest : IntegrationTestSupport { val userEntity = UserEntity(nickname = Nickname("User1")) userRepository.save(userEntity) - val goalEntity1 = createGoalProofEntity(userEntity, BILLING, PROCEEDING) - val goalEntity2 = createGoalProofEntity(userEntity, FREE, SUCCESS) + val goalEntity1 = createGoalEntity(userEntity, BILLING, PROCEEDING) + val goalEntity2 = createGoalEntity(userEntity, FREE, SUCCESS) goalRepository.saveAll(listOf(goalEntity1, goalEntity2)) val goalProofEntity1 = createGoalProofEntity(userEntity, goalEntity1) @@ -195,7 +195,7 @@ class GoalProofRepositoryTest : IntegrationTestSupport { assertThat(foundGoalProofCount).isEqualTo(2) } - private fun createGoalProofEntity( + private fun createGoalEntity( userEntity: UserEntity, goalType: GoalType, goalResult: GoalResult diff --git a/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/winner/WinnerRepositoryTest.kt b/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/winner/WinnerRepositoryTest.kt new file mode 100644 index 0000000..d4d9a4e --- /dev/null +++ b/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/winner/WinnerRepositoryTest.kt @@ -0,0 +1,224 @@ +package com.whatever.raisedragon.domain.winner + +import com.whatever.raisedragon.IntegrationTestSupport +import com.whatever.raisedragon.domain.gifticon.GifticonEntity +import com.whatever.raisedragon.domain.gifticon.GifticonRepository +import com.whatever.raisedragon.domain.gifticon.URL +import com.whatever.raisedragon.domain.goal.* +import com.whatever.raisedragon.domain.goal.GoalResult.* +import com.whatever.raisedragon.domain.goal.GoalType.* +import com.whatever.raisedragon.domain.user.Nickname +import com.whatever.raisedragon.domain.user.UserEntity +import com.whatever.raisedragon.domain.user.UserRepository +import org.assertj.core.api.Assertions.* +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import java.time.LocalDateTime + +class WinnerRepositoryTest : IntegrationTestSupport { + + @Autowired + private lateinit var winnerRepository: WinnerRepository + + @Autowired + private lateinit var userRepository: UserRepository + + @Autowired + private lateinit var goalRepository: GoalRepository + + @Autowired + private lateinit var gifticonRepository: GifticonRepository + + @DisplayName("goalEntity를 받아 GoalEntity를 포함하는 Winner를 조회한다.") + @Test + fun findByGoalEntity1() { + // given + val userEntity1 = UserEntity(nickname = Nickname("User1")) + val userEntity2 = UserEntity(nickname = Nickname("User2")) + userRepository.saveAll(listOf(userEntity1, userEntity2)) + + val goalEntity1 = createGoalEntity(userEntity1, FREE, FAIL) + val goalEntity2 = createGoalEntity(userEntity2, BILLING, SUCCESS) + goalRepository.saveAll(listOf(goalEntity1, goalEntity2)) + + val gifticonEntity1 = GifticonEntity(userEntity = userEntity1, url = URL("URL1")) + val gifticonEntity2 = GifticonEntity(userEntity = userEntity1, url = URL("URL2")) + gifticonRepository.saveAll(listOf(gifticonEntity1, gifticonEntity2)) + + val winnerEntity1 = WinnerEntity(goalEntity1, userEntity1, gifticonEntity1) + val winnerEntity2 = WinnerEntity(goalEntity2, userEntity2, gifticonEntity2) + winnerRepository.saveAll(listOf(winnerEntity1, winnerEntity2)) + + // when + val foundWinner = winnerRepository.findByGoalEntity(goalEntity1) + + // then + assertThat(foundWinner) + .isNotNull + .isInstanceOf(WinnerEntity::class.java) + + assertThat(foundWinner!!.goalEntity) + .isInstanceOf(GoalEntity::class.java) + .extracting("goalType", "goalResult") + .contains(FREE, FAIL) + + assertThat(foundWinner.userEntity) + .isInstanceOf(UserEntity::class.java) + .extracting("nickname") + .isEqualTo(Nickname("User1")) + + assertThat(foundWinner.gifticonEntity) + .isInstanceOf(GifticonEntity::class.java) + .extracting("url") + .isEqualTo(URL("URL1")) + } + + @DisplayName("goalEntity를 받아 GoalEntity를 포함하는 Winner를 조회하는 중 해당하는 Winner가 없는 경우 null를 반환한다.") + @Test + fun findByGoalEntity2() { + // given + val userEntity1 = UserEntity(nickname = Nickname("User1")) + val userEntity2 = UserEntity(nickname = Nickname("User2")) + userRepository.saveAll(listOf(userEntity1, userEntity2)) + + val goalEntity1 = createGoalEntity(userEntity1, FREE, FAIL) + val goalEntity2 = createGoalEntity(userEntity2, BILLING, SUCCESS) + val goalEntity3 = createGoalEntity(userEntity2, FREE, SUCCESS) + goalRepository.saveAll(listOf(goalEntity1, goalEntity2, goalEntity3)) + + val gifticonEntity1 = GifticonEntity(userEntity = userEntity1, url = URL("URL1")) + val gifticonEntity2 = GifticonEntity(userEntity = userEntity1, url = URL("URL2")) + gifticonRepository.saveAll(listOf(gifticonEntity1, gifticonEntity2)) + + val winnerEntity1 = WinnerEntity(goalEntity1, userEntity1, gifticonEntity1) + val winnerEntity2 = WinnerEntity(goalEntity2, userEntity2, gifticonEntity2) + winnerRepository.saveAll(listOf(winnerEntity1, winnerEntity2)) + + // when + val foundWinner = winnerRepository.findByGoalEntity(goalEntity3) + + // then + assertThat(foundWinner) + .isNull() + } + + @DisplayName("goalEntity와 userEntity를 입력받아 Winner를 조회한다.") + @Test + fun findByGoalEntityAndUserEntity1() { + // given + val userEntity1 = UserEntity(nickname = Nickname("User1")) + val userEntity2 = UserEntity(nickname = Nickname("User2")) + userRepository.saveAll(listOf(userEntity1, userEntity2)) + + val goalEntity1 = createGoalEntity(userEntity1, FREE, FAIL) + val goalEntity2 = createGoalEntity(userEntity2, BILLING, SUCCESS) + goalRepository.saveAll(listOf(goalEntity1, goalEntity2)) + + val gifticonEntity1 = GifticonEntity(userEntity = userEntity1, url = URL("URL1")) + val gifticonEntity2 = GifticonEntity(userEntity = userEntity1, url = URL("URL2")) + gifticonRepository.saveAll(listOf(gifticonEntity1, gifticonEntity2)) + + val winnerEntity1 = WinnerEntity(goalEntity1, userEntity1, gifticonEntity1) + val winnerEntity2 = WinnerEntity(goalEntity2, userEntity2, gifticonEntity2) + winnerRepository.saveAll(listOf(winnerEntity1, winnerEntity2)) + + // when + val foundWinner = winnerRepository.findByGoalEntityAndUserEntity(goalEntity2, userEntity2) + + // then + assertThat(foundWinner) + .isNotNull + .isInstanceOf(WinnerEntity::class.java) + + assertThat(foundWinner!!.goalEntity) + .isInstanceOf(GoalEntity::class.java) + .extracting("goalType", "goalResult") + .contains(BILLING, SUCCESS) + + assertThat(foundWinner.userEntity) + .isInstanceOf(UserEntity::class.java) + .extracting("nickname") + .isEqualTo(Nickname("User2")) + + assertThat(foundWinner.gifticonEntity) + .isInstanceOf(GifticonEntity::class.java) + .extracting("url") + .isEqualTo(URL("URL2")) + } + + @DisplayName("goalEntity와 userEntity를 입력받아 Winner를 조회하는 중 해당하는 Winner를 찾을 수 없으면 null를 반환한다.") + @Test + fun findByGoalEntityAndUserEntity2() { + // given + val userEntity1 = UserEntity(nickname = Nickname("User1")) + val userEntity2 = UserEntity(nickname = Nickname("User2")) + userRepository.saveAll(listOf(userEntity1, userEntity2)) + + val goalEntity1 = createGoalEntity(userEntity1, FREE, FAIL) + val goalEntity2 = createGoalEntity(userEntity2, BILLING, SUCCESS) + val goalEntity3 = createGoalEntity(userEntity2, FREE, SUCCESS) + goalRepository.saveAll(listOf(goalEntity1, goalEntity2, goalEntity3)) + + val gifticonEntity1 = GifticonEntity(userEntity = userEntity1, url = URL("URL1")) + val gifticonEntity2 = GifticonEntity(userEntity = userEntity1, url = URL("URL2")) + gifticonRepository.saveAll(listOf(gifticonEntity1, gifticonEntity2)) + + val winnerEntity1 = WinnerEntity(goalEntity1, userEntity1, gifticonEntity1) + val winnerEntity2 = WinnerEntity(goalEntity2, userEntity2, gifticonEntity2) + winnerRepository.saveAll(listOf(winnerEntity1, winnerEntity2)) + + // when + val foundWinner = winnerRepository.findByGoalEntityAndUserEntity(goalEntity3, userEntity2) + + // then + assertThat(foundWinner) + .isNull() + } + + @DisplayName("goalEntity와 userEntity를 입력받아 Winner를 조회하는 중 해당하는 Winner를 찾을 수 없으면 null를 반환한다.") + @Test + fun findByGoalEntityAndUserEntity3() { + // given + val userEntity1 = UserEntity(nickname = Nickname("User1")) + val userEntity2 = UserEntity(nickname = Nickname("User2")) + val userEntity3 = UserEntity(nickname = Nickname("User3")) + userRepository.saveAll(listOf(userEntity1, userEntity2, userEntity3)) + + val goalEntity1 = createGoalEntity(userEntity1, FREE, FAIL) + val goalEntity2 = createGoalEntity(userEntity2, BILLING, SUCCESS) + goalRepository.saveAll(listOf(goalEntity1, goalEntity2)) + + val gifticonEntity1 = GifticonEntity(userEntity = userEntity1, url = URL("URL1")) + val gifticonEntity2 = GifticonEntity(userEntity = userEntity1, url = URL("URL2")) + gifticonRepository.saveAll(listOf(gifticonEntity1, gifticonEntity2)) + + val winnerEntity1 = WinnerEntity(goalEntity1, userEntity1, gifticonEntity1) + val winnerEntity2 = WinnerEntity(goalEntity2, userEntity2, gifticonEntity2) + winnerRepository.saveAll(listOf(winnerEntity1, winnerEntity2)) + + // when + val foundWinner = winnerRepository.findByGoalEntityAndUserEntity(goalEntity2, userEntity3) + + // then + assertThat(foundWinner) + .isNull() + } + + private fun createGoalEntity( + userEntity: UserEntity, + goalType: GoalType, + goalResult: GoalResult + ): GoalEntity { + val startDateTime = LocalDateTime.now() + val endDateTime = startDateTime.plusDays(7) + return GoalEntity( + userEntity = userEntity, + goalType = goalType, + content = Content("sampleContent"), + goalResult = goalResult, + startDate = startDateTime, + endDate = endDateTime + ) + } +} \ No newline at end of file diff --git a/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/winner/WinnerServiceTest.kt b/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/winner/WinnerServiceTest.kt new file mode 100644 index 0000000..02a5ce8 --- /dev/null +++ b/raisedragon-core/src/test/kotlin/com/whatever/raisedragon/domain/winner/WinnerServiceTest.kt @@ -0,0 +1,311 @@ +package com.whatever.raisedragon.domain.winner + +import com.whatever.raisedragon.IntegrationTestSupport +import com.whatever.raisedragon.common.exception.BaseException +import com.whatever.raisedragon.common.exception.ExceptionCode +import com.whatever.raisedragon.domain.gifticon.GifticonEntity +import com.whatever.raisedragon.domain.gifticon.GifticonRepository +import com.whatever.raisedragon.domain.gifticon.URL +import com.whatever.raisedragon.domain.goal.* +import com.whatever.raisedragon.domain.goal.GoalResult.* +import com.whatever.raisedragon.domain.goal.GoalType.* +import com.whatever.raisedragon.domain.user.Nickname +import com.whatever.raisedragon.domain.user.UserEntity +import com.whatever.raisedragon.domain.user.UserRepository +import jakarta.transaction.Transactional +import org.assertj.core.api.Assertions.* +import org.assertj.core.api.ObjectAssert +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import java.time.LocalDateTime + +@Transactional +class WinnerServiceTest : IntegrationTestSupport { + + @Autowired + private lateinit var winnerService: WinnerService + + @Autowired + private lateinit var winnerRepository: WinnerRepository + + @Autowired + private lateinit var goalRepository: GoalRepository + + @Autowired + private lateinit var userRepository: UserRepository + + @Autowired + private lateinit var gifticonRepository: GifticonRepository + + @DisplayName("goalId, userId, gifticonId를 입력받아 Winner를 생성한다.") + @Test + fun create1() { + // given + val userEntity = UserEntity(nickname = Nickname("User1")) + userRepository.save(userEntity) + + val goalEntity = createGoalEntity(userEntity, FREE, FAIL) + goalRepository.save(goalEntity) + + val gifticonEntity = GifticonEntity(userEntity = userEntity, url = URL("URL")) + gifticonRepository.save(gifticonEntity) + + // when + val foundWinner = winnerService.create( + goalId = goalEntity.id, + userId = userEntity.id, + gifticonId = gifticonEntity.id + ) + + // then + assertThat(foundWinner) + .isInstanceOfWinner() + .extracting("goalId", "userId", "gifticonId") + .contains(goalEntity.id, userEntity.id, gifticonEntity.id) + } + + @DisplayName("goalId, userId, gifticonId를 입력받아 Winner를 생성할 때 goalId에 해당하는 Goal이 없다면 예외가 발생한다.") + @Test + fun create2() { + // given + val userEntity = UserEntity(nickname = Nickname("User1")) + userRepository.save(userEntity) + + val goalEntity = createGoalEntity(userEntity, FREE, FAIL) + goalRepository.save(goalEntity) + + val gifticonEntity = GifticonEntity(userEntity = userEntity, url = URL("URL")) + gifticonRepository.save(gifticonEntity) + + // when + assertThatThrownBy { winnerService.create(-1L, userEntity.id, gifticonEntity.id) } + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + } + + @DisplayName("goalId, userId, gifticonId를 입력받아 Winner를 생성할 때 userId에 해당하는 User가 없다면 예외가 발생한다.") + @Test + fun create3() { + // given + val userEntity = UserEntity(nickname = Nickname("User1")) + userRepository.save(userEntity) + + val goalEntity = createGoalEntity(userEntity, FREE, FAIL) + goalRepository.save(goalEntity) + + val gifticonEntity = GifticonEntity(userEntity = userEntity, url = URL("URL")) + gifticonRepository.save(gifticonEntity) + + // when + assertThatThrownBy { winnerService.create(goalEntity.id, -1L, gifticonEntity.id) } + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + } + + @DisplayName("goalId, userId, gifticonId를 입력받아 Winner를 생성할 때 gifticonId를 해당하는 Gifticon이 없다면 예외가 발생한다.") + @Test + fun create4() { + // given + val userEntity = UserEntity(nickname = Nickname("User1")) + userRepository.save(userEntity) + + val goalEntity = createGoalEntity(userEntity, FREE, FAIL) + goalRepository.save(goalEntity) + + val gifticonEntity = GifticonEntity(userEntity = userEntity, url = URL("URL")) + gifticonRepository.save(gifticonEntity) + + // when + assertThatThrownBy { winnerService.create(goalEntity.id, userEntity.id, -1L) } + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + } + + @DisplayName("goalId와 userId에 해당하는 Winner를 조회한다.") + @Test + fun findByGoalIdAndUserId1() { + // given + val userEntity = UserEntity(nickname = Nickname("User1")) + userRepository.save(userEntity) + + val goalEntity = createGoalEntity(userEntity, FREE, FAIL) + goalRepository.save(goalEntity) + + val gifticonEntity = GifticonEntity(userEntity = userEntity, url = URL("URL")) + gifticonRepository.save(gifticonEntity) + + val winnerEntity = WinnerEntity(goalEntity, userEntity, gifticonEntity) + winnerRepository.save(winnerEntity) + + // when + val foundWinner = winnerService.findByGoalIdAndUserId(goalEntity.id, userEntity.id) + + // then + assertThat(foundWinner) + .isNotNull + .isInstanceOfWinner() + .extracting("goalId", "userId", "gifticonId") + .contains(goalEntity.id, userEntity.id, gifticonEntity.id) + } + + @DisplayName("goalId와 userId에 해당하는 Winner를 조회하는 중 goalId에 해당하는 Goal이 없는 경우 예외가 발생한다.") + @Test + fun findByGoalIdAndUserId2() { + // given + val userEntity = UserEntity(nickname = Nickname("User1")) + userRepository.save(userEntity) + + val goalEntity = createGoalEntity(userEntity, FREE, FAIL) + goalRepository.save(goalEntity) + + val gifticonEntity = GifticonEntity(userEntity = userEntity, url = URL("URL")) + gifticonRepository.save(gifticonEntity) + + val winnerEntity = WinnerEntity(goalEntity, userEntity, gifticonEntity) + winnerRepository.save(winnerEntity) + + // when // then + assertThatThrownBy { winnerService.findByGoalIdAndUserId(-1L, userEntity.id) } + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + } + + @DisplayName("goalId와 userId에 해당하는 Winner를 조회하는 중 userId에 해당하는 User가 없는 경우 예외가 발생한다.") + @Test + fun findByGoalIdAndUserId3() { + // given + val userEntity = UserEntity(nickname = Nickname("User1")) + userRepository.save(userEntity) + + val goalEntity = createGoalEntity(userEntity, FREE, FAIL) + goalRepository.save(goalEntity) + + val gifticonEntity = GifticonEntity(userEntity = userEntity, url = URL("URL")) + gifticonRepository.save(gifticonEntity) + + val winnerEntity = WinnerEntity(goalEntity, userEntity, gifticonEntity) + winnerRepository.save(winnerEntity) + + // when // then + assertThatThrownBy { winnerService.findByGoalIdAndUserId(goalEntity.id, -1L) } + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + } + + @DisplayName("goalId와 userId에 해당하는 Winner를 조회하는 중 조건에 해당하는 Winner가 없는 경우 null를 반환한다.") + @Test + fun findByGoalIdAndUserId4() { + // given + val userEntity = UserEntity(nickname = Nickname("User1")) + userRepository.save(userEntity) + + val goalEntity1 = createGoalEntity(userEntity, FREE, FAIL) + val goalEntity2 = createGoalEntity(userEntity, BILLING, FAIL) + goalRepository.saveAll(listOf(goalEntity1, goalEntity2)) + + val gifticonEntity = GifticonEntity(userEntity = userEntity, url = URL("URL")) + gifticonRepository.save(gifticonEntity) + + val winnerEntity = WinnerEntity(goalEntity1, userEntity, gifticonEntity) + winnerRepository.save(winnerEntity) + + // when + val foundWinner = winnerService.findByGoalIdAndUserId(goalEntity2.id, userEntity.id) + + // then + assertThat(foundWinner).isNull() + } + + @DisplayName("goalId에 해당하는 Winner의 nickname을 조회한다.") + @Test + fun findWinnerNicknameByGoalId1() { + // given + val userEntity = UserEntity(nickname = Nickname("User1")) + userRepository.save(userEntity) + + val goalEntity1 = createGoalEntity(userEntity, FREE, SUCCESS) + val goalEntity2 = createGoalEntity(userEntity, BILLING, FAIL) + goalRepository.saveAll(listOf(goalEntity1, goalEntity2)) + + val gifticonEntity = GifticonEntity(userEntity = userEntity, url = URL("URL")) + gifticonRepository.save(gifticonEntity) + + val winnerEntity = WinnerEntity(goalEntity1, userEntity, gifticonEntity) + winnerRepository.save(winnerEntity) + + // when + val foundWinnerNickname = winnerService.findWinnerNicknameByGoalId(goalEntity1.id) + + // then + assertThat(foundWinnerNickname) + .isNotNull + .isEqualTo(Nickname("User1")) + } + + @DisplayName("goalId에 해당하는 Winner의 nickname을 조회하는 중 goalId에 해당하는 Goal이 없는 경우 예외가 발생한다.") + @Test + fun findWinnerNicknameByGoalId2() { + // given + val userEntity = UserEntity(nickname = Nickname("User1")) + userRepository.save(userEntity) + + val goalEntity1 = createGoalEntity(userEntity, FREE, SUCCESS) + val goalEntity2 = createGoalEntity(userEntity, BILLING, FAIL) + goalRepository.saveAll(listOf(goalEntity1, goalEntity2)) + + val gifticonEntity = GifticonEntity(userEntity = userEntity, url = URL("URL")) + gifticonRepository.save(gifticonEntity) + + val winnerEntity = WinnerEntity(goalEntity1, userEntity, gifticonEntity) + winnerRepository.save(winnerEntity) + + // when // then + assertThatThrownBy { winnerService.findWinnerNicknameByGoalId(-1L) } + .isInstanceOf(BaseException::class.java) + .hasMessage(ExceptionCode.E404_NOT_FOUND.message) + } + + @DisplayName("goalId에 해당하는 Winner의 nickname을 조회하는 중 goalId에 해당하는 Winner가 없는 경우 null를 반환한다.") + @Test + fun findWinnerNicknameByGoalId3() { + // given + val userEntity = UserEntity(nickname = Nickname("User1")) + userRepository.save(userEntity) + + val goalEntity1 = createGoalEntity(userEntity, FREE, SUCCESS) + val goalEntity2 = createGoalEntity(userEntity, BILLING, FAIL) + goalRepository.saveAll(listOf(goalEntity1, goalEntity2)) + + val gifticonEntity = GifticonEntity(userEntity = userEntity, url = URL("URL")) + gifticonRepository.save(gifticonEntity) + + val winnerEntity = WinnerEntity(goalEntity1, userEntity, gifticonEntity) + winnerRepository.save(winnerEntity) + + // when + val foundNickname = winnerService.findWinnerNicknameByGoalId(goalEntity2.id) + + //then + assertThat(foundNickname).isNull() + } + + private fun ObjectAssert<*>.isInstanceOfWinner() = isInstanceOf(Winner::class.java) + + private fun createGoalEntity( + userEntity: UserEntity, + goalType: GoalType, + goalResult: GoalResult + ): GoalEntity { + val startDateTime = LocalDateTime.now() + val endDateTime = startDateTime.plusDays(7) + return GoalEntity( + userEntity = userEntity, + goalType = goalType, + content = Content("sampleContent"), + goalResult = goalResult, + startDate = startDateTime, + endDate = endDateTime + ) + } +} \ No newline at end of file