Skip to content

Commit

Permalink
Merge pull request #92 from whatever-mentoring/feature/goal-gifticon-…
Browse files Browse the repository at this point in the history
…application-service-test

Write test codes of GoalGifticonApplicationService
mkSpace authored Apr 18, 2024
2 parents 9d86302 + ed2f9fe commit 0a988fc
Showing 7 changed files with 406 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -63,7 +63,6 @@ class GoalGifticonApplicationService(
userId: Long
): GifticonResponse {
val goal = goalService.findById(goalId)
isBrokenTiming(goal)

val goalGifticon = if (userId != goal.userId) {
null
@@ -86,15 +85,11 @@ class GoalGifticonApplicationService(

@Transactional
fun updateGifticonURLByGoalId(request: GoalGifticonUpdateServiceRequest): GoalGifticonResponse {
val userEntity = userService.findById(request.userId).fromDto()
val goal = goalService.findById(request.goalId).fromDto(userEntity).toDto()
val goal = goalService.findById(request.goalId)
validateIsRequestUserHasUpdateAuthority(goal, request.userId)
val goalGifticon = goalGifticonService.findByGoalId(goal.id)
?: throw BaseException.of(ExceptionCode.E404_NOT_FOUND, "다짐에 등록된 기프티콘을 찾을 수 없습니다.")
val gifticon = gifticonService.findById(goalGifticon.gifticonId)

validateIsRequestUserHasUpdateAuthority(goal, request.userId)

gifticon.url = URL(request.gifticonURL)
val gifticon = gifticonService.update(goalGifticon.gifticonId, URL(request.gifticonURL))

return GoalGifticonResponse(
goalGifticonId = goalGifticon.id,
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.whatever.raisedragon.applicationservice.betting
package com.whatever.raisedragon.applicationservice

import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whatever.raisedragon.applicationservice.betting

import com.whatever.raisedragon.applicationservice.ApplicationServiceTestSupport
import com.whatever.raisedragon.applicationservice.betting.dto.BettingCreateServiceRequest
import com.whatever.raisedragon.applicationservice.betting.dto.BettingRetrieveResponse
import com.whatever.raisedragon.applicationservice.betting.dto.BettingUpdateServiceRequest
@@ -13,7 +14,6 @@ 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.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import java.time.LocalDateTime
data class Gifticon(
val id: Long,
val userId: Long,
var url: URL,
val url: URL,
val isValidated: Boolean,
var deletedAt: LocalDateTime?,
var createdAt: LocalDateTime?,
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ class GifticonEntity(

@Embedded
@Column(name = "url", nullable = false, length = 255)
val url: URL,
var url: URL,

@Column(name = "is_validated")
var isValidated: Boolean = true
Original file line number Diff line number Diff line change
@@ -33,6 +33,13 @@ class GifticonService(
return gifticonRepository.findById(gifticonId).orElseThrow(notFoundExceptionSupplier).toDto()
}

@Transactional
fun update(gifticonId: Long, gifticonUrl: URL): Gifticon {
val gifticon = gifticonRepository.findById(gifticonId).orElseThrow(notFoundExceptionSupplier)
gifticon.url = gifticonUrl
return gifticon.toDto()
}

@Transactional
fun hardDeleteByUserId(userId: Long) {
val gifticonEntities = gifticonRepository.findAllByUserEntity(

0 comments on commit 0a988fc

Please sign in to comment.