generated from pricelees/issue-pr-template
refactor: dummyinitializer 로직을 Api 호출 -> repository 사용으로 수정
This commit is contained in:
parent
2f8c2a6a55
commit
75f628c991
@ -1,11 +1,8 @@
|
|||||||
package roomescape.supports
|
package roomescape.supports
|
||||||
|
|
||||||
import io.restassured.module.kotlin.extensions.Extract
|
|
||||||
import io.restassured.module.kotlin.extensions.Given
|
|
||||||
import io.restassured.module.kotlin.extensions.When
|
|
||||||
import org.springframework.data.repository.findByIdOrNull
|
import org.springframework.data.repository.findByIdOrNull
|
||||||
import org.springframework.http.MediaType
|
|
||||||
import roomescape.common.config.next
|
import roomescape.common.config.next
|
||||||
|
import roomescape.common.util.MdcPrincipalId
|
||||||
import roomescape.payment.business.PaymentWriter
|
import roomescape.payment.business.PaymentWriter
|
||||||
import roomescape.payment.infrastructure.client.CardDetail
|
import roomescape.payment.infrastructure.client.CardDetail
|
||||||
import roomescape.payment.infrastructure.client.EasyPayDetail
|
import roomescape.payment.infrastructure.client.EasyPayDetail
|
||||||
@ -16,22 +13,25 @@ import roomescape.payment.infrastructure.persistence.PaymentEntity
|
|||||||
import roomescape.payment.infrastructure.persistence.PaymentRepository
|
import roomescape.payment.infrastructure.persistence.PaymentRepository
|
||||||
import roomescape.payment.web.PaymentConfirmRequest
|
import roomescape.payment.web.PaymentConfirmRequest
|
||||||
import roomescape.payment.web.PaymentWithDetailResponse
|
import roomescape.payment.web.PaymentWithDetailResponse
|
||||||
import roomescape.payment.web.toPaymentDetailResponse
|
|
||||||
import roomescape.payment.web.toDetailResponse
|
import roomescape.payment.web.toDetailResponse
|
||||||
|
import roomescape.payment.web.toPaymentDetailResponse
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationRepository
|
import roomescape.reservation.infrastructure.persistence.ReservationRepository
|
||||||
|
import roomescape.reservation.infrastructure.persistence.ReservationStatus
|
||||||
import roomescape.reservation.web.PendingReservationCreateRequest
|
import roomescape.reservation.web.PendingReservationCreateRequest
|
||||||
|
import roomescape.reservation.web.toEntity
|
||||||
import roomescape.schedule.infrastructure.persistence.ScheduleEntity
|
import roomescape.schedule.infrastructure.persistence.ScheduleEntity
|
||||||
import roomescape.schedule.infrastructure.persistence.ScheduleRepository
|
import roomescape.schedule.infrastructure.persistence.ScheduleRepository
|
||||||
import roomescape.schedule.infrastructure.persistence.ScheduleStatus
|
import roomescape.schedule.infrastructure.persistence.ScheduleStatus
|
||||||
import roomescape.schedule.web.ScheduleCreateRequest
|
import roomescape.schedule.web.ScheduleCreateRequest
|
||||||
import roomescape.schedule.web.ScheduleUpdateRequest
|
|
||||||
import roomescape.store.infrastructure.persistence.StoreEntity
|
import roomescape.store.infrastructure.persistence.StoreEntity
|
||||||
import roomescape.store.infrastructure.persistence.StoreRepository
|
import roomescape.store.infrastructure.persistence.StoreRepository
|
||||||
import roomescape.store.infrastructure.persistence.StoreStatus
|
import roomescape.store.infrastructure.persistence.StoreStatus
|
||||||
import roomescape.theme.infrastructure.persistence.ThemeEntity
|
import roomescape.theme.infrastructure.persistence.ThemeEntity
|
||||||
import roomescape.theme.infrastructure.persistence.ThemeRepository
|
import roomescape.theme.infrastructure.persistence.ThemeRepository
|
||||||
import roomescape.theme.web.ThemeCreateRequest
|
import roomescape.theme.web.ThemeCreateRequest
|
||||||
|
import roomescape.theme.web.toEntity
|
||||||
|
import roomescape.user.infrastructure.persistence.UserEntity
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
class DummyInitializer(
|
class DummyInitializer(
|
||||||
@ -42,132 +42,109 @@ class DummyInitializer(
|
|||||||
private val paymentRepository: PaymentRepository,
|
private val paymentRepository: PaymentRepository,
|
||||||
private val paymentWriter: PaymentWriter
|
private val paymentWriter: PaymentWriter
|
||||||
) {
|
) {
|
||||||
fun createTheme(adminToken: String, request: ThemeCreateRequest): ThemeEntity {
|
|
||||||
val createdThemeId: Long = Given {
|
fun createStore(
|
||||||
contentType(MediaType.APPLICATION_JSON_VALUE)
|
id: Long = tsidFactory.next(),
|
||||||
header("Authorization", "Bearer $adminToken")
|
name: String = "행복${randomPhoneNumber()}호점",
|
||||||
body(request)
|
address: String = "강북구 행복로 $name",
|
||||||
} When {
|
contact: String = randomPhoneNumber(),
|
||||||
post("/admin/themes")
|
businessRegNum: String = randomBusinessRegNum(),
|
||||||
} Extract {
|
regionCode: String = "1111000000",
|
||||||
path("data.id")
|
status: StoreStatus = StoreStatus.ACTIVE
|
||||||
|
): StoreEntity {
|
||||||
|
return StoreEntity(
|
||||||
|
id = id,
|
||||||
|
name = name,
|
||||||
|
address = address,
|
||||||
|
contact = contact,
|
||||||
|
businessRegNum = businessRegNum,
|
||||||
|
regionCode = regionCode,
|
||||||
|
status = status
|
||||||
|
).also {
|
||||||
|
storeRepository.save(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return themeRepository.findByIdOrNull(createdThemeId)
|
fun createTheme(
|
||||||
?: throw RuntimeException("unexpected error occurred")
|
request: ThemeCreateRequest = ThemeFixture.createRequest
|
||||||
|
): ThemeEntity {
|
||||||
|
return request.toEntity(tsidFactory.next()).also { themeRepository.save(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createSchedule(
|
fun createSchedule(
|
||||||
adminToken: String,
|
storeId: Long = tsidFactory.next(),
|
||||||
request: ScheduleCreateRequest,
|
request: ScheduleCreateRequest = ScheduleFixture.createRequest,
|
||||||
status: ScheduleStatus = ScheduleStatus.AVAILABLE
|
status: ScheduleStatus = ScheduleStatus.AVAILABLE
|
||||||
): ScheduleEntity {
|
): ScheduleEntity {
|
||||||
val themeId: Long = if (themeRepository.existsById(request.themeId)) {
|
val themeId: Long = if (themeRepository.existsById(request.themeId)) {
|
||||||
request.themeId
|
request.themeId
|
||||||
} else {
|
} else {
|
||||||
createTheme(
|
createTheme().id
|
||||||
adminToken = adminToken,
|
|
||||||
request = ThemeFixture.createRequest.copy(name = "theme-${System.currentTimeMillis()}")
|
|
||||||
).id
|
|
||||||
}
|
|
||||||
val createdScheduleId: Long = Given {
|
|
||||||
contentType(MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
header("Authorization", "Bearer $adminToken")
|
|
||||||
body(request.copy(themeId = themeId))
|
|
||||||
} When {
|
|
||||||
post("/schedules")
|
|
||||||
} Extract {
|
|
||||||
path("data.id")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Given {
|
val storeId: Long = if (storeRepository.existsById(storeId)) {
|
||||||
contentType(MediaType.APPLICATION_JSON_VALUE)
|
storeId
|
||||||
header("Authorization", "Bearer $adminToken")
|
} else {
|
||||||
body(ScheduleUpdateRequest(status = status))
|
createStore(id = storeId).id
|
||||||
} When {
|
|
||||||
patch("/schedules/$createdScheduleId")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return scheduleRepository.findByIdOrNull(createdScheduleId)
|
val schedule: ScheduleEntity = ScheduleFixture.create(
|
||||||
?: throw RuntimeException("unexpected error occurred")
|
date = request.date, time = request.time, storeId = storeId, themeId = themeId,
|
||||||
|
).apply {
|
||||||
|
this.status = status
|
||||||
|
}
|
||||||
|
|
||||||
|
return scheduleRepository.save(schedule)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createPendingReservation(
|
fun createPendingReservation(
|
||||||
adminToken: String,
|
user: UserEntity,
|
||||||
reserverToken: String,
|
|
||||||
themeRequest: ThemeCreateRequest = ThemeFixture.createRequest,
|
themeRequest: ThemeCreateRequest = ThemeFixture.createRequest,
|
||||||
scheduleRequest: ScheduleCreateRequest = ScheduleFixture.createRequest,
|
scheduleRequest: ScheduleCreateRequest = ScheduleFixture.createRequest,
|
||||||
reservationRequest: PendingReservationCreateRequest = ReservationFixture.pendingCreateRequest,
|
reservationRequest: PendingReservationCreateRequest = ReservationFixture.pendingCreateRequest,
|
||||||
): ReservationEntity {
|
): ReservationEntity {
|
||||||
val themeId: Long = if (themeRepository.existsById(scheduleRequest.themeId)) {
|
val themeId: Long = if (themeRepository.existsById(scheduleRequest.themeId)) {
|
||||||
scheduleRequest.themeId
|
scheduleRequest.themeId
|
||||||
} else if (themeRepository.existsById(reservationRequest.scheduleId)) {
|
|
||||||
reservationRequest.scheduleId
|
|
||||||
} else {
|
} else {
|
||||||
createTheme(
|
createTheme(themeRequest).id
|
||||||
adminToken = adminToken,
|
|
||||||
request = themeRequest
|
|
||||||
).id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val scheduleId: Long = if (scheduleRepository.existsById(reservationRequest.scheduleId)) {
|
val scheduleId: Long = if (scheduleRepository.existsById(reservationRequest.scheduleId)) {
|
||||||
reservationRequest.scheduleId
|
reservationRequest.scheduleId
|
||||||
} else {
|
} else {
|
||||||
createSchedule(
|
createSchedule(
|
||||||
adminToken = adminToken,
|
|
||||||
request = scheduleRequest.copy(themeId = themeId),
|
request = scheduleRequest.copy(themeId = themeId),
|
||||||
status = ScheduleStatus.HOLD
|
status = ScheduleStatus.HOLD
|
||||||
).id
|
).id
|
||||||
}
|
}
|
||||||
|
|
||||||
return createPendingReservation(
|
val reservation = ReservationFixture.pendingCreateRequest.copy(
|
||||||
reserverToken = reserverToken,
|
scheduleId = scheduleId,
|
||||||
request = reservationRequest.copy(scheduleId = scheduleId)
|
reserverName = reservationRequest.reserverName,
|
||||||
)
|
reserverContact = reservationRequest.reserverContact,
|
||||||
|
participantCount = reservationRequest.participantCount,
|
||||||
|
requirement = reservationRequest.requirement,
|
||||||
|
).toEntity(id = tsidFactory.next(), userId = user.id)
|
||||||
|
|
||||||
|
return reservationRepository.save(reservation)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createConfirmReservation(
|
fun createConfirmReservation(
|
||||||
adminToken: String,
|
user: UserEntity,
|
||||||
reserverToken: String,
|
|
||||||
themeRequest: ThemeCreateRequest = ThemeFixture.createRequest,
|
themeRequest: ThemeCreateRequest = ThemeFixture.createRequest,
|
||||||
scheduleRequest: ScheduleCreateRequest = ScheduleFixture.createRequest,
|
scheduleRequest: ScheduleCreateRequest = ScheduleFixture.createRequest,
|
||||||
reservationRequest: PendingReservationCreateRequest = ReservationFixture.pendingCreateRequest,
|
reservationRequest: PendingReservationCreateRequest = ReservationFixture.pendingCreateRequest,
|
||||||
): ReservationEntity {
|
): ReservationEntity {
|
||||||
val themeId: Long = if (themeRepository.existsById(scheduleRequest.themeId)) {
|
return createPendingReservation(user, themeRequest, scheduleRequest, reservationRequest).apply {
|
||||||
scheduleRequest.themeId
|
this.status = ReservationStatus.CONFIRMED
|
||||||
} else if (themeRepository.existsById(reservationRequest.scheduleId)) {
|
}.also {
|
||||||
reservationRequest.scheduleId
|
reservationRepository.save(it)
|
||||||
} else {
|
|
||||||
createTheme(
|
scheduleRepository.findByIdOrNull(it.scheduleId)?.let { schedule ->
|
||||||
adminToken = adminToken,
|
schedule.status = ScheduleStatus.RESERVED
|
||||||
request = themeRequest
|
scheduleRepository.save(schedule)
|
||||||
).id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val scheduleId: Long = if (scheduleRepository.existsById(reservationRequest.scheduleId)) {
|
|
||||||
reservationRequest.scheduleId
|
|
||||||
} else {
|
|
||||||
createSchedule(
|
|
||||||
adminToken = adminToken,
|
|
||||||
request = scheduleRequest.copy(themeId = themeId),
|
|
||||||
status = ScheduleStatus.HOLD
|
|
||||||
).id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val reservation = createPendingReservation(
|
|
||||||
reserverToken = reserverToken,
|
|
||||||
request = reservationRequest.copy(scheduleId = scheduleId)
|
|
||||||
)
|
|
||||||
|
|
||||||
Given {
|
|
||||||
contentType(MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
header("Authorization", "Bearer $reserverToken")
|
|
||||||
} When {
|
|
||||||
post("/reservations/${reservation.id}/confirm")
|
|
||||||
}
|
|
||||||
|
|
||||||
return reservationRepository.findByIdOrNull(reservation.id)
|
|
||||||
?: throw RuntimeException("unexpected error occurred")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createPayment(
|
fun createPayment(
|
||||||
@ -228,37 +205,4 @@ class DummyInitializer(
|
|||||||
clientCancelResponse
|
clientCancelResponse
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createPendingReservation(
|
|
||||||
reserverToken: String,
|
|
||||||
request: PendingReservationCreateRequest,
|
|
||||||
): ReservationEntity {
|
|
||||||
val createdReservationId: Long = Given {
|
|
||||||
contentType(MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
header("Authorization", "Bearer $reserverToken")
|
|
||||||
body(request.copy(scheduleId = request.scheduleId))
|
|
||||||
} When {
|
|
||||||
post("/reservations/pending")
|
|
||||||
} Extract {
|
|
||||||
path("data.id")
|
|
||||||
}
|
|
||||||
|
|
||||||
return reservationRepository.findByIdOrNull(createdReservationId)
|
|
||||||
?: throw RuntimeException("unexpected error occurred")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createStore(): StoreEntity {
|
|
||||||
|
|
||||||
return StoreEntity(
|
|
||||||
id = tsidFactory.next(),
|
|
||||||
name = "Hello 매장-${System.currentTimeMillis()}",
|
|
||||||
address = "강북구 행복로 123",
|
|
||||||
contact = randomPhoneNumber(),
|
|
||||||
businessRegNum = randomBusinessRegNum(),
|
|
||||||
regionCode = "1111000000",
|
|
||||||
status = StoreStatus.ACTIVE
|
|
||||||
).also {
|
|
||||||
storeRepository.save(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user