generated from pricelees/issue-pr-template
155 lines
5.2 KiB
Kotlin
155 lines
5.2 KiB
Kotlin
package roomescape.util
|
|
|
|
import roomescape.auth.infrastructure.jwt.JwtHandler
|
|
import roomescape.auth.web.LoginRequest
|
|
import roomescape.member.infrastructure.persistence.MemberEntity
|
|
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.infrastructure.persistence.Reservation
|
|
import roomescape.reservation.infrastructure.persistence.ReservationStatus
|
|
import roomescape.reservation.infrastructure.persistence.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
|
|
): MemberEntity = MemberEntity(id, name, "$account@email.com", password, role)
|
|
|
|
fun admin(): MemberEntity = create(
|
|
id = 2L,
|
|
account = "admin",
|
|
role = Role.ADMIN
|
|
)
|
|
fun adminLoginRequest(): LoginRequest = LoginRequest(
|
|
email = admin().email,
|
|
password = admin().password
|
|
)
|
|
|
|
fun user(): MemberEntity = 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: MemberEntity = 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)
|
|
)
|
|
}
|
|
|