generated from pricelees/issue-pr-template
<!-- 제목 양식 --> <!-- [이슈번호] 작업 요약 (예시: [#10] Gitea 템플릿 생성) --> ## 📝 관련 이슈 및 PR **PR과 관련된 이슈 번호** - #13 ## ✨ 작업 내용 <!-- 어떤 작업을 했는지 알려주세요! --> theme 패키지 내 코드 및 테스트 코틀린 전환 ## 🧪 테스트 <!-- 어떤 테스트를 생각했고 진행했는지 알려주세요! --> 다른 테스트는 코틀린으로 전환 시 크게 문제가 없었으나, GET /themes/most-reserved-last-week API의 경우 쿼리에 크게 의존하여 mocking을 사용하는 기존 테스트로 처리하기 애매한 부분이 있었음. 따라서, API 테스트는 mocking이 아닌 RestAssured를 이용한 실제 테스트로 진행하였고 \@RequestParam, 날짜 등 실제 비즈니스와 관련된 부분을 위주로 처리하고 쿼리 자체는 Repository 테스트에서 상세하게 검증하였음. ## 📚 참고 자료 및 기타 <!-- 참고한 자료, 또는 논의할 사항이 있다면 알려주세요! --> 패키지를 reservation 안에 넣는 것은 고민이 조금 더 필요할 것 같음. 현재는 단일 매장에 대한 서비스지만 매장별로 분리하는 것을 고민중인 만큼 코틀린 마이그레이션이 끝난 이후 생각해볼 예정 Reviewed-on: #15 Co-authored-by: pricelees <priceelees@gmail.com> Co-committed-by: pricelees <priceelees@gmail.com>
155 lines
5.1 KiB
Kotlin
155 lines
5.1 KiB
Kotlin
package roomescape.util
|
|
|
|
import roomescape.auth.infrastructure.jwt.JwtHandler
|
|
import roomescape.auth.web.LoginRequest
|
|
import roomescape.member.infrastructure.persistence.Member
|
|
import roomescape.member.infrastructure.persistence.Role
|
|
import roomescape.payment.infrastructure.persistence.CanceledPaymentEntity
|
|
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
|
import roomescape.payment.web.PaymentApprove
|
|
import roomescape.payment.web.PaymentCancel
|
|
import roomescape.reservation.domain.Reservation
|
|
import roomescape.reservation.domain.ReservationStatus
|
|
import roomescape.reservation.domain.ReservationTime
|
|
import roomescape.theme.infrastructure.persistence.ThemeEntity
|
|
import java.time.LocalDate
|
|
import java.time.LocalTime
|
|
import java.time.OffsetDateTime
|
|
import kotlin.random.Random
|
|
|
|
object MemberFixture {
|
|
const val NOT_LOGGED_IN_USERID: Long = 0
|
|
|
|
fun create(
|
|
id: Long? = null,
|
|
name: String = "sangdol",
|
|
account: String = "default",
|
|
password: String = "password",
|
|
role: Role = Role.ADMIN
|
|
): Member = Member(id, name, "$account@email.com", password, role)
|
|
|
|
fun admin(): Member = create(
|
|
id = 2L,
|
|
account = "admin",
|
|
role = Role.ADMIN
|
|
)
|
|
fun adminLoginRequest(): LoginRequest = LoginRequest(
|
|
email = admin().email,
|
|
password = admin().password
|
|
)
|
|
|
|
fun user(): Member = create(
|
|
id = 1L,
|
|
account = "user",
|
|
role = Role.MEMBER
|
|
)
|
|
fun userLoginRequest(): LoginRequest = LoginRequest(
|
|
email = user().email,
|
|
password = user().password
|
|
)
|
|
}
|
|
|
|
object ReservationTimeFixture {
|
|
fun create(
|
|
id: Long? = null,
|
|
startAt: LocalTime = LocalTime.now().plusHours(1),
|
|
): ReservationTime = ReservationTime(id, startAt)
|
|
}
|
|
|
|
object ThemeFixture {
|
|
fun create(
|
|
id: Long? = null,
|
|
name: String = "Default Theme",
|
|
description: String = "Default Description",
|
|
thumbnail: String = "https://example.com/default-thumbnail.jpg"
|
|
): ThemeEntity = ThemeEntity(id, name, description, thumbnail)
|
|
}
|
|
|
|
object ReservationFixture {
|
|
fun create(
|
|
id: Long? = null,
|
|
date: LocalDate = LocalDate.now().plusWeeks(1),
|
|
themeEntity: ThemeEntity = ThemeFixture.create(),
|
|
reservationTime: ReservationTime = ReservationTimeFixture.create(),
|
|
member: Member = MemberFixture.create(),
|
|
status: ReservationStatus = ReservationStatus.CONFIRMED_PAYMENT_REQUIRED
|
|
): Reservation = Reservation(id, date, reservationTime, themeEntity, member, status)
|
|
}
|
|
|
|
object JwtFixture {
|
|
const val SECRET_KEY: String = "daijawligagaf@LIJ$@U)9nagnalkkgalijaddljfi"
|
|
const val EXPIRATION_TIME: Long = 1000 * 60 * 60
|
|
|
|
fun create(
|
|
secretKey: String = SECRET_KEY,
|
|
expirationTime: Long = EXPIRATION_TIME
|
|
): JwtHandler = JwtHandler(secretKey, expirationTime)
|
|
}
|
|
|
|
object PaymentFixture {
|
|
const val PAYMENT_KEY: String = "paymentKey"
|
|
const val ORDER_ID: String = "orderId"
|
|
const val AMOUNT: Long = 10000L
|
|
|
|
fun create(
|
|
id: Long? = null,
|
|
orderId: String = ORDER_ID,
|
|
paymentKey: String = PAYMENT_KEY,
|
|
totalAmount: Long = AMOUNT,
|
|
reservationId: Long = Random.nextLong(),
|
|
approvedAt: OffsetDateTime = OffsetDateTime.now()
|
|
): PaymentEntity = PaymentEntity(
|
|
id = id,
|
|
orderId = orderId,
|
|
paymentKey = paymentKey,
|
|
totalAmount = totalAmount,
|
|
reservation = ReservationFixture.create(id = reservationId),
|
|
approvedAt = approvedAt
|
|
)
|
|
|
|
fun createCanceled(
|
|
id: Long? = null,
|
|
paymentKey: String = PAYMENT_KEY,
|
|
cancelReason: String = "Test Cancel",
|
|
cancelAmount: Long = AMOUNT,
|
|
approvedAt: OffsetDateTime = OffsetDateTime.now(),
|
|
canceledAt: OffsetDateTime = approvedAt.plusHours(1)
|
|
): CanceledPaymentEntity = CanceledPaymentEntity(
|
|
id = id,
|
|
paymentKey = paymentKey,
|
|
cancelReason = cancelReason,
|
|
cancelAmount = cancelAmount,
|
|
approvedAt = approvedAt,
|
|
canceledAt = canceledAt
|
|
|
|
)
|
|
|
|
fun createApproveRequest(): PaymentApprove.Request = PaymentApprove.Request(
|
|
paymentKey = PAYMENT_KEY,
|
|
orderId = ORDER_ID,
|
|
amount = AMOUNT,
|
|
paymentType = "CARD"
|
|
)
|
|
|
|
fun createApproveResponse(): PaymentApprove.Response = PaymentApprove.Response(
|
|
paymentKey = PAYMENT_KEY,
|
|
orderId = ORDER_ID,
|
|
approvedAt = OffsetDateTime.now(),
|
|
totalAmount = AMOUNT
|
|
)
|
|
|
|
fun createCancelRequest(): PaymentCancel.Request = PaymentCancel.Request(
|
|
paymentKey = PAYMENT_KEY,
|
|
amount = AMOUNT,
|
|
cancelReason = "Test Cancel"
|
|
)
|
|
|
|
fun createCancelResponse(): PaymentCancel.Response = PaymentCancel.Response(
|
|
cancelStatus = "SUCCESS",
|
|
cancelReason = "Test Cancel",
|
|
cancelAmount = AMOUNT,
|
|
canceledAt = OffsetDateTime.now().plusMinutes(1)
|
|
)
|
|
}
|
|
|