generated from pricelees/issue-pr-template
332 lines
11 KiB
Kotlin
332 lines
11 KiB
Kotlin
package roomescape.supports
|
|
|
|
import com.github.f4b6a3.tsid.TsidFactory
|
|
import roomescape.admin.infrastructure.persistence.AdminEntity
|
|
import roomescape.admin.infrastructure.persistence.AdminPermissionLevel
|
|
import roomescape.admin.infrastructure.persistence.AdminType
|
|
import roomescape.common.config.next
|
|
import roomescape.payment.infrastructure.client.*
|
|
import roomescape.payment.infrastructure.common.*
|
|
import roomescape.payment.web.PaymentCancelRequest
|
|
import roomescape.payment.web.PaymentConfirmRequest
|
|
import roomescape.reservation.web.PendingReservationCreateRequest
|
|
import roomescape.schedule.infrastructure.persistence.ScheduleEntity
|
|
import roomescape.schedule.infrastructure.persistence.ScheduleEntityFactory
|
|
import roomescape.schedule.web.ScheduleCreateRequest
|
|
import roomescape.store.infrastructure.persistence.StoreEntity
|
|
import roomescape.store.infrastructure.persistence.StoreStatus
|
|
import roomescape.store.web.StoreRegisterRequest
|
|
import roomescape.theme.infrastructure.persistence.Difficulty
|
|
import roomescape.theme.infrastructure.persistence.ThemeEntity
|
|
import roomescape.theme.web.ThemeCreateRequest
|
|
import roomescape.user.infrastructure.persistence.UserEntity
|
|
import roomescape.user.infrastructure.persistence.UserStatus
|
|
import roomescape.user.web.MIN_PASSWORD_LENGTH
|
|
import roomescape.user.web.UserCreateRequest
|
|
import java.time.LocalDate
|
|
import java.time.LocalTime
|
|
import java.time.OffsetDateTime
|
|
|
|
const val INVALID_PK: Long = 9999L
|
|
val tsidFactory = TsidFactory(0)
|
|
|
|
object StoreFixture {
|
|
val registerRequest = StoreRegisterRequest(
|
|
name = "행복${randomPhoneNumber()}호점",
|
|
address = "서울특별시 강북구 행복${randomPhoneNumber()}길",
|
|
contact = randomPhoneNumber(),
|
|
businessRegNum = randomBusinessRegNum(),
|
|
regionCode = "1111000000"
|
|
)
|
|
|
|
fun create(
|
|
id: Long = tsidFactory.next(),
|
|
name: String = "행복${randomPhoneNumber()}호점",
|
|
address: String = "서울특별시 강북구 행복${randomPhoneNumber()}길",
|
|
contact: String = randomPhoneNumber(),
|
|
businessRegNum: String = randomBusinessRegNum(),
|
|
regionCode: String = "1111000000",
|
|
status: StoreStatus = StoreStatus.ACTIVE
|
|
) = StoreEntity(
|
|
id = id,
|
|
name = name,
|
|
address = address,
|
|
contact = contact,
|
|
businessRegNum = businessRegNum,
|
|
regionCode = regionCode,
|
|
status = status
|
|
)
|
|
}
|
|
|
|
object AdminFixture {
|
|
val default: AdminEntity = create(
|
|
account = "default"
|
|
)
|
|
|
|
val storeDefault: AdminEntity = createStoreAdmin(
|
|
account = "store-default",
|
|
)
|
|
|
|
val hqDefault: AdminEntity = createHqAdmin(
|
|
account = "hq-default",
|
|
)
|
|
|
|
fun createStoreAdmin(
|
|
id: Long = tsidFactory.next(),
|
|
account: String = randomString(),
|
|
password: String = "adminPassword",
|
|
name: String = "admin12345",
|
|
phone: String = randomPhoneNumber(),
|
|
storeId: Long = tsidFactory.next(),
|
|
permissionLevel: AdminPermissionLevel = AdminPermissionLevel.FULL_ACCESS
|
|
): AdminEntity {
|
|
return create(
|
|
id = id,
|
|
account = account,
|
|
password = password,
|
|
name = name,
|
|
phone = phone,
|
|
type = AdminType.STORE,
|
|
storeId = storeId,
|
|
permissionLevel = permissionLevel
|
|
)
|
|
}
|
|
|
|
fun createHqAdmin(
|
|
id: Long = tsidFactory.next(),
|
|
account: String = randomString(),
|
|
password: String = "adminPassword",
|
|
name: String = "admin12345",
|
|
phone: String = randomPhoneNumber(),
|
|
permissionLevel: AdminPermissionLevel = AdminPermissionLevel.FULL_ACCESS
|
|
): AdminEntity {
|
|
return create(
|
|
id = id,
|
|
account = account,
|
|
password = password,
|
|
name = name,
|
|
phone = phone,
|
|
type = AdminType.HQ,
|
|
storeId = null,
|
|
permissionLevel = permissionLevel
|
|
)
|
|
}
|
|
|
|
fun create(
|
|
id: Long = tsidFactory.next(),
|
|
account: String = randomString(),
|
|
password: String = "adminPassword",
|
|
name: String = "admin",
|
|
phone: String = randomPhoneNumber(),
|
|
type: AdminType = AdminType.STORE,
|
|
storeId: Long? = tsidFactory.next(),
|
|
permissionLevel: AdminPermissionLevel = AdminPermissionLevel.FULL_ACCESS
|
|
): AdminEntity {
|
|
val storeId = if (type == AdminType.HQ) null else storeId
|
|
|
|
return AdminEntity(
|
|
id = id,
|
|
account = account,
|
|
password = password,
|
|
name = name,
|
|
phone = phone,
|
|
type = type,
|
|
storeId = storeId,
|
|
permissionLevel = permissionLevel,
|
|
)
|
|
}
|
|
}
|
|
|
|
object UserFixture {
|
|
val default: UserEntity = createUser(
|
|
name = "default",
|
|
email = "default-user@test.com"
|
|
)
|
|
|
|
fun createUser(
|
|
id: Long = tsidFactory.next(),
|
|
name: String = randomString(),
|
|
email: String = randomEmail(),
|
|
password: String = "a".repeat(MIN_PASSWORD_LENGTH),
|
|
phone: String = randomPhoneNumber(),
|
|
regionCode: String = "1111000000",
|
|
status: UserStatus = UserStatus.ACTIVE
|
|
): UserEntity = UserEntity(
|
|
id = id,
|
|
name = name,
|
|
email = email,
|
|
password = password,
|
|
phone = phone,
|
|
regionCode = regionCode,
|
|
status = status
|
|
)
|
|
|
|
val createRequest: UserCreateRequest = UserCreateRequest(
|
|
name = randomString(),
|
|
email = randomEmail(),
|
|
password = "a".repeat(MIN_PASSWORD_LENGTH),
|
|
phone = randomPhoneNumber(),
|
|
regionCode = "1111000000"
|
|
)
|
|
}
|
|
|
|
object ThemeFixture {
|
|
val createRequest: ThemeCreateRequest = ThemeCreateRequest(
|
|
name = randomString(),
|
|
description = "constituto",
|
|
thumbnailUrl = "https://duckduckgo.com/?q=mediocrem",
|
|
difficulty = Difficulty.VERY_EASY,
|
|
price = 10000,
|
|
minParticipants = 3,
|
|
maxParticipants = 5,
|
|
availableMinutes = 80,
|
|
expectedMinutesFrom = 60,
|
|
expectedMinutesTo = 70,
|
|
isActive = true
|
|
)
|
|
|
|
fun create(
|
|
id: Long = tsidFactory.next(),
|
|
name: String = randomString(),
|
|
description: String = randomString(),
|
|
thumbnailUrl: String = "http://www.bing.com/search?q=fugit",
|
|
difficulty: Difficulty = Difficulty.VERY_EASY,
|
|
price: Int = 10_000,
|
|
minParticipants: Short = 3,
|
|
maxParticipants: Short = 5,
|
|
availableMinutes: Short = 60,
|
|
expectedMinutesFrom: Short = 40,
|
|
expectedMinutesTo: Short = 50,
|
|
isActive: Boolean = true
|
|
) = ThemeEntity(
|
|
id = id,
|
|
name = name,
|
|
description = description,
|
|
thumbnailUrl = thumbnailUrl,
|
|
difficulty = difficulty,
|
|
price = price,
|
|
minParticipants = minParticipants,
|
|
maxParticipants = maxParticipants,
|
|
availableMinutes = availableMinutes,
|
|
expectedMinutesFrom = expectedMinutesFrom,
|
|
expectedMinutesTo = expectedMinutesTo,
|
|
isActive = isActive
|
|
)
|
|
}
|
|
|
|
object ScheduleFixture {
|
|
val createRequest: ScheduleCreateRequest = ScheduleCreateRequest(
|
|
date = LocalDate.now().plusDays(1),
|
|
time = LocalTime.now(),
|
|
themeId = tsidFactory.next()
|
|
)
|
|
|
|
fun create(
|
|
id: Long = tsidFactory.next(),
|
|
date: LocalDate = LocalDate.now().plusDays(1),
|
|
time: LocalTime = LocalTime.now(),
|
|
storeId: Long = tsidFactory.next(),
|
|
themeId: Long = tsidFactory.next()
|
|
): ScheduleEntity = ScheduleEntityFactory.create(
|
|
id = id,
|
|
date = date,
|
|
time = time,
|
|
storeId = storeId,
|
|
themeId = themeId
|
|
)
|
|
}
|
|
|
|
object PaymentFixture {
|
|
val confirmRequest: PaymentConfirmRequest = PaymentConfirmRequest(
|
|
paymentKey = "paymentKey",
|
|
orderId = "orderId",
|
|
amount = 10000,
|
|
paymentType = PaymentType.NORMAL
|
|
)
|
|
|
|
val cancelRequest: PaymentCancelRequest = PaymentCancelRequest(
|
|
reservationId = tsidFactory.next(),
|
|
cancelReason = "cancelReason",
|
|
)
|
|
|
|
fun cardDetail(
|
|
amount: Int,
|
|
issuerCode: CardIssuerCode = CardIssuerCode.SHINHAN,
|
|
cardType: CardType = CardType.CREDIT,
|
|
ownerType: CardOwnerType = CardOwnerType.PERSONAL,
|
|
installmentPlanMonths: Int = 0,
|
|
): CardDetail = CardDetail(
|
|
issuerCode = issuerCode,
|
|
number = "429335*********",
|
|
amount = amount,
|
|
cardType = cardType,
|
|
ownerType = ownerType,
|
|
isInterestFree = false,
|
|
approveNo = "1828382",
|
|
installmentPlanMonths = installmentPlanMonths
|
|
)
|
|
|
|
fun easypayDetail(
|
|
amount: Int,
|
|
provider: EasyPayCompanyCode = EasyPayCompanyCode.TOSSPAY,
|
|
discountAmount: Int = 0
|
|
): EasyPayDetail = EasyPayDetail(provider, amount, discountAmount)
|
|
|
|
fun transferDetail(
|
|
bankCode: BankCode = BankCode.SHINHAN,
|
|
settlementStatus: String = "COMPLETED"
|
|
): TransferDetail = TransferDetail(
|
|
bankCode = bankCode,
|
|
settlementStatus = settlementStatus
|
|
)
|
|
|
|
fun confirmResponse(
|
|
paymentKey: String,
|
|
amount: Int,
|
|
method: PaymentMethod,
|
|
cardDetail: CardDetail?,
|
|
easyPayDetail: EasyPayDetail?,
|
|
transferDetail: TransferDetail?
|
|
) = PaymentClientConfirmResponse(
|
|
paymentKey = paymentKey,
|
|
status = PaymentStatus.DONE,
|
|
totalAmount = amount,
|
|
vat = (amount * 0.1).toInt(),
|
|
suppliedAmount = (amount * 0.9).toInt(),
|
|
method = method,
|
|
card = cardDetail,
|
|
easyPay = easyPayDetail,
|
|
transfer = transferDetail,
|
|
requestedAt = OffsetDateTime.now(),
|
|
approvedAt = OffsetDateTime.now().plusSeconds(5)
|
|
)
|
|
|
|
fun cancelResponse(
|
|
amount: Int,
|
|
cardDiscountAmount: Int = 0,
|
|
transferDiscountAmount: Int = 0,
|
|
easypayDiscountAmount: Int = 0,
|
|
cancelReason: String = "cancelReason"
|
|
) = PaymentClientCancelResponse(
|
|
status = PaymentStatus.CANCELED,
|
|
cancels = CancelDetail(
|
|
cancelAmount = amount,
|
|
cardDiscountAmount = cardDiscountAmount,
|
|
transferDiscountAmount = transferDiscountAmount,
|
|
easyPayDiscountAmount = easypayDiscountAmount,
|
|
canceledAt = OffsetDateTime.now().plusSeconds(5),
|
|
cancelReason = cancelReason
|
|
),
|
|
)
|
|
}
|
|
|
|
object ReservationFixture {
|
|
val pendingCreateRequest: PendingReservationCreateRequest = PendingReservationCreateRequest(
|
|
scheduleId = tsidFactory.next(),
|
|
reserverName = "Wilbur Stuart",
|
|
reserverContact = "wilbur@example.com",
|
|
participantCount = 5,
|
|
requirement = "Hello, Nice to meet you!"
|
|
)
|
|
}
|