From 605cb079cfffaf7bb2289976102bab00eca31706 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Thu, 10 Oct 2024 14:53:32 +0900 Subject: [PATCH] =?UTF-8?q?[Refactor/#427]=20BrowseWorkbooksUseCase=20?= =?UTF-8?q?=EB=A6=AC=ED=8E=99=ED=86=A0=EB=A7=81=20(#428)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Workbooks 모델 생성 * refactor: 기존 WorkbookOrderDelegator 이동 및 order 메서드 시그니쳐 변경 * refactor: WorkbookOrderDelegator 구현체 이동 및 변경 반영 * feat: OrderedWorkBooks 모델 생성 * refactor: BrowseWorkbooksUseCase에 변경 반영 * refactor: 변경 사항 테스트에 반영 * refactor: WorkBook 클래스 범용 데이터 클래스로 변경 * feat: order 모델에서 사용할 OrderTargetWorkBooks 구현 * feat: order 모델 부모 객체 생성 * refactor: order 모델 변경 사항 반영 * refactor: 변경 사항 반영 * refactor: orderedWorkbooks 공통으로 처리할 수 있도록 수정 * fix: 변경 사항 테스트에 적용 --- .../usecase/BrowseWorkbooksUseCase.kt | 116 +++++++++++------- .../workbook/usecase/model/WorkBooks.kt | 5 + .../AuthMainViewWorkbookOrderDelegator.kt | 12 +- .../usecase/model/order/OrderAbleWorkBooks.kt | 5 + .../model/order/OrderTargetWorkBooks.kt | 7 ++ .../usecase/model/order/OrderedWorkBooks.kt | 9 ++ .../usecase/model/order/UnOrderedWorkBooks.kt | 11 ++ .../model/order/WorkbookOrderDelegator.kt | 11 ++ .../order/BasicWorkbookOrderDelegator.kt | 11 -- .../service/order/WorkbookOrderDelegator.kt | 11 -- .../order/WorkbookOrderDelegatorExecutor.kt | 12 -- .../usecase/BrowseWorkbooksUseCaseTest.kt | 104 +--------------- .../AuthMainViewWorkbookOrderDelegatorTest.kt | 24 ++-- 13 files changed, 139 insertions(+), 199 deletions(-) create mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/WorkBooks.kt rename api/src/main/kotlin/com/few/api/domain/workbook/usecase/{service => model}/order/AuthMainViewWorkbookOrderDelegator.kt (87%) create mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderAbleWorkBooks.kt create mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderTargetWorkBooks.kt create mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderedWorkBooks.kt create mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/UnOrderedWorkBooks.kt create mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/WorkbookOrderDelegator.kt delete mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/BasicWorkbookOrderDelegator.kt delete mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegator.kt delete mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegatorExecutor.kt rename api/src/test/kotlin/com/few/api/domain/workbook/usecase/{service => model}/order/AuthMainViewWorkbookOrderDelegatorTest.kt (88%) diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt index 5aa097dc8..15a5aa002 100644 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt @@ -4,16 +4,16 @@ import com.few.api.domain.workbook.service.WorkbookMemberService import com.few.api.domain.workbook.service.WorkbookSubscribeService import com.few.api.domain.workbook.service.dto.BrowseMemberSubscribeWorkbooksInDto import com.few.api.domain.workbook.service.dto.BrowseWorkbookWriterRecordsInDto +import com.few.api.domain.workbook.service.dto.WriterMappedWorkbookOutDto import com.few.api.domain.workbook.usecase.dto.BrowseWorkBookDetail import com.few.api.domain.workbook.usecase.dto.BrowseWorkbooksUseCaseIn import com.few.api.domain.workbook.usecase.dto.BrowseWorkbooksUseCaseOut import com.few.api.domain.workbook.usecase.dto.WriterDetail import com.few.api.domain.workbook.usecase.model.* -import com.few.api.domain.workbook.usecase.service.order.AuthMainViewWorkbookOrderDelegator -import com.few.api.domain.workbook.usecase.service.order.BasicWorkbookOrderDelegator -import com.few.api.domain.workbook.usecase.service.order.WorkbookOrderDelegatorExecutor +import com.few.api.domain.workbook.usecase.model.order.* import com.few.api.repo.dao.workbook.WorkbookDao import com.few.api.repo.dao.workbook.query.BrowseWorkBookQueryWithSubscriptionCountQuery +import com.few.api.repo.dao.workbook.record.SelectWorkBookRecordWithSubscriptionCount import com.few.api.web.support.ViewCategory import com.few.data.common.code.CategoryType import org.springframework.stereotype.Component @@ -42,7 +42,6 @@ class BrowseWorkbooksUseCase( private val workbookDao: WorkbookDao, private val workbookMemberService: WorkbookMemberService, private val workbookSubscribeService: WorkbookSubscribeService, - private val workbookOrderDelegatorExecutor: WorkbookOrderDelegatorExecutor, ) { @Transactional @@ -56,54 +55,30 @@ class BrowseWorkbooksUseCase( BrowseWorkbookWriterRecordsInDto(workbookIds) ) - val workbookDetails = workbookRecords.map { record -> - WorkBook( - id = record.id, - mainImageUrl = record.mainImageUrl, - title = record.title, - description = record.description, - category = CategoryType.convertToDisplayName(record.category), - createdAt = record.createdAt, - writerDetails = writerRecords[record.id]?.map { - WorkBookWriter( - id = it.writerId, - name = it.name, - url = it.url - ) - } ?: emptyList(), - subscriptionCount = record.subscriptionCount - ) + val orderStrategy = getOrderStrategy(useCaseIn) + val orderDelegator = when (orderStrategy) { + WorkBookOrderStrategy.MAIN_VIEW_AUTH -> { + genAuthMainViewWorkbookOrderDelegator(useCaseIn) + } + /** BASIC, MAIN_VIEW_UNAUTH -> 해당 경우는 DB 조회 결과를 그대로 반환 */ + else -> null } - val orderStrategy = when { - useCaseIn.viewCategory == ViewCategory.MAIN_CARD && useCaseIn.memberId != null -> WorkBookOrderStrategy.MAIN_VIEW_AUTH - useCaseIn.viewCategory == ViewCategory.MAIN_CARD && useCaseIn.memberId == null -> WorkBookOrderStrategy.MAIN_VIEW_UNAUTH - else -> WorkBookOrderStrategy.BASIC - } + val workbooks = toWorkbooks(workbookRecords, writerRecords) - val orderedWorkbooks = when (orderStrategy) { - WorkBookOrderStrategy.MAIN_VIEW_AUTH -> { - BrowseMemberSubscribeWorkbooksInDto(useCaseIn.memberId!!).let { dto -> - workbookSubscribeService.browseMemberSubscribeWorkbooks(dto) - }.map { - MemberSubscribedWorkbook( - workbookId = it.workbookId, - isActiveSub = it.isActiveSub, - currentDay = it.currentDay - ) - }.let { subscribedWorkbooks -> - AuthMainViewWorkbookOrderDelegator(workbookDetails, subscribedWorkbooks) + val orderedWorkbook = OrderTargetWorkBooks(workbooks).let { target -> + orderDelegator + ?.let { delegator -> + UnOrderedWorkBooks( + target, + delegator + ).order() } - } - WorkBookOrderStrategy.MAIN_VIEW_UNAUTH -> { - BasicWorkbookOrderDelegator(workbookDetails) - } - else -> BasicWorkbookOrderDelegator(workbookDetails) - }.let { delegator -> - workbookOrderDelegatorExecutor.execute(delegator) - } + ?: run { OrderedWorkBooks(target) } + }.orderedWorkbooks - orderedWorkbooks.map { workBook -> + val orderedWorkbookData = orderedWorkbook.workbookData + orderedWorkbookData.map { workBook -> BrowseWorkBookDetail( id = workBook.id, mainImageUrl = workBook.mainImageUrl, @@ -126,4 +101,51 @@ class BrowseWorkbooksUseCase( ) } } + + private fun getOrderStrategy(useCaseIn: BrowseWorkbooksUseCaseIn) = + when { + useCaseIn.viewCategory == ViewCategory.MAIN_CARD && useCaseIn.memberId != null -> WorkBookOrderStrategy.MAIN_VIEW_AUTH + useCaseIn.viewCategory == ViewCategory.MAIN_CARD && useCaseIn.memberId == null -> WorkBookOrderStrategy.MAIN_VIEW_UNAUTH + else -> WorkBookOrderStrategy.BASIC + } + + private fun genAuthMainViewWorkbookOrderDelegator(useCaseIn: BrowseWorkbooksUseCaseIn): WorkbookOrderDelegator { + return BrowseMemberSubscribeWorkbooksInDto(useCaseIn.memberId!!).let { dto -> + workbookSubscribeService.browseMemberSubscribeWorkbooks(dto) + }.map { + MemberSubscribedWorkbook( + workbookId = it.workbookId, + isActiveSub = it.isActiveSub, + currentDay = it.currentDay + ) + }.let { subscribedWorkbooks -> + AuthMainViewWorkbookOrderDelegator(subscribedWorkbooks) + } + } + + private fun toWorkbooks( + workbookRecords: List, + writerRecords: Map>, + ): WorkBooks { + return workbookRecords.map { record -> + WorkBook( + id = record.id, + mainImageUrl = record.mainImageUrl, + title = record.title, + description = record.description, + category = CategoryType.convertToDisplayName(record.category), + createdAt = record.createdAt, + writerDetails = writerRecords[record.id]?.map { + WorkBookWriter( + id = it.writerId, + name = it.name, + url = it.url + ) + } ?: emptyList(), + subscriptionCount = record.subscriptionCount + ) + }.let { + WorkBooks(it) + } + } } \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/WorkBooks.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/WorkBooks.kt new file mode 100644 index 000000000..8a3bd807b --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/WorkBooks.kt @@ -0,0 +1,5 @@ +package com.few.api.domain.workbook.usecase.model + +data class WorkBooks( + val workbookData: List, +) \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/AuthMainViewWorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegator.kt similarity index 87% rename from api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/AuthMainViewWorkbookOrderDelegator.kt rename to api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegator.kt index fe44f1f59..9f3bb9513 100644 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/AuthMainViewWorkbookOrderDelegator.kt +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegator.kt @@ -1,13 +1,10 @@ -package com.few.api.domain.workbook.usecase.service.order +package com.few.api.domain.workbook.usecase.model.order import com.few.api.domain.workbook.usecase.model.MemberSubscribedWorkbook import com.few.api.domain.workbook.usecase.model.WorkBook +import com.few.api.domain.workbook.usecase.model.WorkBooks class AuthMainViewWorkbookOrderDelegator( - /** - * @see com.few.api.repo.dao.workbook.WorkbookDao.browseWorkBookWithSubscriptionCount - */ - private val workbooks: List, private val memberSubscribedWorkbooks: List, ) : WorkbookOrderDelegator { @@ -18,7 +15,8 @@ class AuthMainViewWorkbookOrderDelegator( * 2. 구독 기록이 없는 워크북을 보여줍니다. * 3. 비활성화된 구독 워크북을 보여줍니다. */ - override fun order(): List { + override fun order(targetWorkBooks: OrderTargetWorkBooks): OrderTargetWorkBooks { + val workbooks = targetWorkBooks.workbooks.workbookData val allWorkbookIds = workbooks.associate { it.id to false }.toMutableMap() val activeSubWorkbookIds = memberSubscribedWorkbooks.filter { it.isActiveSub }.sortedByDescending { @@ -64,6 +62,6 @@ class AuthMainViewWorkbookOrderDelegator( */ orderedWorkbooks.addAll(lastAddWorkbooks) - return orderedWorkbooks + return OrderTargetWorkBooks(WorkBooks(orderedWorkbooks)) } } \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderAbleWorkBooks.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderAbleWorkBooks.kt new file mode 100644 index 000000000..190a2585c --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderAbleWorkBooks.kt @@ -0,0 +1,5 @@ +package com.few.api.domain.workbook.usecase.model.order + +open class OrderAbleWorkBooks( + protected open val targetWorkBooks: OrderTargetWorkBooks, +) \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderTargetWorkBooks.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderTargetWorkBooks.kt new file mode 100644 index 000000000..7e82be429 --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderTargetWorkBooks.kt @@ -0,0 +1,7 @@ +package com.few.api.domain.workbook.usecase.model.order + +import com.few.api.domain.workbook.usecase.model.WorkBooks + +data class OrderTargetWorkBooks( + val workbooks: WorkBooks, +) \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderedWorkBooks.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderedWorkBooks.kt new file mode 100644 index 000000000..66dafe100 --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderedWorkBooks.kt @@ -0,0 +1,9 @@ +package com.few.api.domain.workbook.usecase.model.order + +import com.few.api.domain.workbook.usecase.model.WorkBooks + +class OrderedWorkBooks( + orderTargetWorkBooks: OrderTargetWorkBooks, +) : OrderAbleWorkBooks(orderTargetWorkBooks) { + val orderedWorkbooks: WorkBooks = orderTargetWorkBooks.workbooks +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/UnOrderedWorkBooks.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/UnOrderedWorkBooks.kt new file mode 100644 index 000000000..ae72f2ec3 --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/UnOrderedWorkBooks.kt @@ -0,0 +1,11 @@ +package com.few.api.domain.workbook.usecase.model.order + +class UnOrderedWorkBooks( + orderTargetWorkBooks: OrderTargetWorkBooks, + private val delegator: WorkbookOrderDelegator, +) : OrderAbleWorkBooks(orderTargetWorkBooks) { + fun order(): OrderedWorkBooks { + val orderedWorkbooks = delegator.order(targetWorkBooks) + return OrderedWorkBooks(orderedWorkbooks) + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/WorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/WorkbookOrderDelegator.kt new file mode 100644 index 000000000..df281f9cc --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/WorkbookOrderDelegator.kt @@ -0,0 +1,11 @@ +package com.few.api.domain.workbook.usecase.model.order + +interface WorkbookOrderDelegator { + + /** + * 워크북을 정렬합니다. + * @param targetWorkBooks 정렬할 워크북 목록 + * @return 정렬된 워크북 목록 + */ + fun order(targetWorkBooks: OrderTargetWorkBooks): OrderTargetWorkBooks +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/BasicWorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/BasicWorkbookOrderDelegator.kt deleted file mode 100644 index daae07090..000000000 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/BasicWorkbookOrderDelegator.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.few.api.domain.workbook.usecase.service.order - -import com.few.api.domain.workbook.usecase.model.WorkBook - -class BasicWorkbookOrderDelegator( - private val workbooks: List, -) : WorkbookOrderDelegator { - override fun order(): List { - return workbooks - } -} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegator.kt deleted file mode 100644 index 1da8614c7..000000000 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegator.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.few.api.domain.workbook.usecase.service.order - -import com.few.api.domain.workbook.usecase.model.WorkBook - -interface WorkbookOrderDelegator { - - /** - * 워크북을 정렬합니다. - * */ - fun order(): List -} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegatorExecutor.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegatorExecutor.kt deleted file mode 100644 index cf37cd2e2..000000000 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegatorExecutor.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.few.api.domain.workbook.usecase.service.order - -import com.few.api.domain.workbook.usecase.model.WorkBook -import org.springframework.stereotype.Service - -@Service -class WorkbookOrderDelegatorExecutor { - - fun execute(delegator: WorkbookOrderDelegator): List { - return delegator.order() - } -} \ No newline at end of file diff --git a/api/src/test/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCaseTest.kt b/api/src/test/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCaseTest.kt index bef68a2e2..54c704948 100644 --- a/api/src/test/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCaseTest.kt +++ b/api/src/test/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCaseTest.kt @@ -5,11 +5,6 @@ import com.few.api.domain.workbook.service.WorkbookSubscribeService import com.few.api.domain.workbook.service.dto.BrowseMemberSubscribeWorkbooksOutDto import com.few.api.domain.workbook.service.dto.WriterMappedWorkbookOutDto import com.few.api.domain.workbook.usecase.dto.BrowseWorkbooksUseCaseIn -import com.few.api.domain.workbook.usecase.model.WorkBook -import com.few.api.domain.workbook.usecase.model.WorkBookWriter -import com.few.api.domain.workbook.usecase.service.order.AuthMainViewWorkbookOrderDelegator -import com.few.api.domain.workbook.usecase.service.order.BasicWorkbookOrderDelegator -import com.few.api.domain.workbook.usecase.service.order.WorkbookOrderDelegatorExecutor import com.few.api.repo.dao.workbook.WorkbookDao import com.few.api.repo.dao.workbook.record.SelectWorkBookRecordWithSubscriptionCount import com.few.api.web.support.ViewCategory @@ -29,16 +24,14 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ lateinit var workbookDao: WorkbookDao lateinit var workbookMemberService: WorkbookMemberService lateinit var workbookSubscribeService: WorkbookSubscribeService - lateinit var workbookOrderDelegatorExecutor: WorkbookOrderDelegatorExecutor lateinit var useCase: BrowseWorkbooksUseCase beforeContainer { workbookDao = mockk() workbookMemberService = mockk() workbookSubscribeService = mockk() - workbookOrderDelegatorExecutor = mockk() useCase = - BrowseWorkbooksUseCase(workbookDao, workbookMemberService, workbookSubscribeService, workbookOrderDelegatorExecutor) + BrowseWorkbooksUseCase(workbookDao, workbookMemberService, workbookSubscribeService) } given("메인 뷰에서 로그인 된 상태로 카테고리를 지정하여 다수 워크북 조회 요청이 온 상황에서") { @@ -63,16 +56,16 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ 1L to listOf( WriterMappedWorkbookOutDto( writerId = 1L, - name = "hunca", - url = URL("https://jh-labs.tistory.com/"), + name = "writer1", + url = URL("http://localhost:8080/image/writer/1"), workbookId = 1L ) ), 2L to listOf( WriterMappedWorkbookOutDto( writerId = 2L, - name = "hunca", - url = URL("https://jh-labs.tistory.com/"), + name = "writer2", + url = URL("http://localhost:8080/image/writer/2"), workbookId = 2L ) ) @@ -93,27 +86,6 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ ) ) - every { - workbookOrderDelegatorExecutor.execute(any(AuthMainViewWorkbookOrderDelegator::class)) - } returns IntStream.range(1, 1 + workbookCount).mapToObj { - WorkBook( - id = it.toLong(), - title = "workbook title$it", - mainImageUrl = URL("http://localhost:8080/image/main/$it"), - category = WorkBookCategory.ECONOMY.displayName, - description = "workbook$it description", - createdAt = LocalDateTime.now(), - writerDetails = listOf( - WorkBookWriter( - id = it.toLong(), - name = "writer$it", - url = URL("https://jh-labs.tistory.com/") - ) - ), - subscriptionCount = it.toLong() - ) - }.toList() - then("경제 카테고리의 워크북이 조회된다") { val useCaseOut = useCase.execute(useCaseIn) useCaseOut.workbooks.size shouldBe workbookCount @@ -127,20 +99,13 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ browseWorkBookDetail.writerDetails.size shouldBe 1 browseWorkBookDetail.writerDetails[0].id shouldBe (index + 1).toLong() browseWorkBookDetail.writerDetails[0].name shouldBe "writer${index + 1}" - browseWorkBookDetail.writerDetails[0].url shouldBe URL("https://jh-labs.tistory.com/") + browseWorkBookDetail.writerDetails[0].url shouldBe URL("http://localhost:8080/image/writer/${index + 1}") browseWorkBookDetail.subscriptionCount shouldBe (index + 1).toLong() } verify(exactly = 1) { workbookDao.browseWorkBookWithSubscriptionCount(any()) } verify(exactly = 1) { workbookMemberService.browseWorkbookWriterRecords(any()) } verify(exactly = 1) { workbookSubscribeService.browseMemberSubscribeWorkbooks(any()) } - verify(exactly = 1) { - workbookOrderDelegatorExecutor.execute( - any( - AuthMainViewWorkbookOrderDelegator::class - ) - ) - } } } } @@ -176,28 +141,6 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ } every { workbookMemberService.browseWorkbookWriterRecords(any()) } returns workbookWriterRecords - every { - workbookOrderDelegatorExecutor.execute(any(BasicWorkbookOrderDelegator::class)) - } returns - IntStream.range(1, 1 + workbookCount).mapToObj { - WorkBook( - id = it.toLong(), - title = "workbook title$it", - mainImageUrl = URL("http://localhost:8080/image/main/$it"), - category = WorkBookCategory.ECONOMY.displayName, - description = "workbook$it description", - createdAt = LocalDateTime.now(), - writerDetails = listOf( - WorkBookWriter( - id = it.toLong(), - name = "writer$it", - url = URL("http://localhost:8080/image/writer/$it") - ) - ), - subscriptionCount = it.toLong() - ) - }.toList() - then("경제 카테고리의 워크북이 조회된다") { val useCaseOut = useCase.execute(useCaseIn) useCaseOut.workbooks.size shouldBe workbookCount @@ -218,13 +161,6 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ verify(exactly = 1) { workbookDao.browseWorkBookWithSubscriptionCount(any()) } verify(exactly = 1) { workbookMemberService.browseWorkbookWriterRecords(any()) } verify(exactly = 0) { workbookSubscribeService.browseMemberSubscribeWorkbooks(any()) } - verify(exactly = 1) { - workbookOrderDelegatorExecutor.execute( - any( - BasicWorkbookOrderDelegator::class - ) - ) - } } } } @@ -268,27 +204,6 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ ) ) - every { - workbookOrderDelegatorExecutor.execute(any(BasicWorkbookOrderDelegator::class)) - } returns IntStream.range(1, 1 + workbookCount).mapToObj { - WorkBook( - id = it.toLong(), - title = "workbook title$it", - mainImageUrl = URL("http://localhost:8080/image/main/$it"), - category = WorkBookCategory.ECONOMY.displayName, - description = "workbook$it description", - createdAt = LocalDateTime.now(), - writerDetails = listOf( - WorkBookWriter( - id = it.toLong(), - name = "writer$it", - url = URL("http://localhost:8080/image/writer/$it") - ) - ), - subscriptionCount = it.toLong() - ) - }.toList() - then("경제 카테고리의 워크북이 조회된다") { val useCaseOut = useCase.execute(useCaseIn) useCaseOut.workbooks.size shouldBe workbookCount @@ -308,13 +223,6 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ verify(exactly = 1) { workbookDao.browseWorkBookWithSubscriptionCount(any()) } verify(exactly = 1) { workbookMemberService.browseWorkbookWriterRecords(any()) } verify(exactly = 0) { workbookSubscribeService.browseMemberSubscribeWorkbooks(any()) } - verify(exactly = 1) { - workbookOrderDelegatorExecutor.execute( - any( - BasicWorkbookOrderDelegator::class - ) - ) - } } } } diff --git a/api/src/test/kotlin/com/few/api/domain/workbook/usecase/service/order/AuthMainViewWorkbookOrderDelegatorTest.kt b/api/src/test/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegatorTest.kt similarity index 88% rename from api/src/test/kotlin/com/few/api/domain/workbook/usecase/service/order/AuthMainViewWorkbookOrderDelegatorTest.kt rename to api/src/test/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegatorTest.kt index e1402a943..39218116f 100644 --- a/api/src/test/kotlin/com/few/api/domain/workbook/usecase/service/order/AuthMainViewWorkbookOrderDelegatorTest.kt +++ b/api/src/test/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegatorTest.kt @@ -1,7 +1,8 @@ -package com.few.api.domain.workbook.usecase.service.order +package com.few.api.domain.workbook.usecase.model.order import com.few.api.domain.workbook.usecase.model.MemberSubscribedWorkbook import com.few.api.domain.workbook.usecase.model.WorkBook +import com.few.api.domain.workbook.usecase.model.WorkBooks import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test import java.net.URL @@ -55,17 +56,16 @@ class AuthMainViewWorkbookOrderDelegatorTest { // when val delegator = AuthMainViewWorkbookOrderDelegator( - workbooksOrderBySubscriptionCount, memberSubscribedWorkbooksReverseOrderByCurrentDay ) // then - val orderedWorkbooks = delegator.order() - assertEquals(totalWorkbookCount, orderedWorkbooks.size) + val orderedWorkbooks = delegator.order(OrderTargetWorkBooks(WorkBooks(workbooksOrderBySubscriptionCount))) + assertEquals(totalWorkbookCount, orderedWorkbooks.workbooks.workbookData.size) val expectedOrderedWorkbookIds = activeWorkbookIds + notSubscribeWorkbookIds + inActiveList for (i in expectedOrderedWorkbookIds.indices) { - assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks[i].id) + assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks.workbooks.workbookData[i].id) } } @@ -115,17 +115,16 @@ class AuthMainViewWorkbookOrderDelegatorTest { // when val delegator = AuthMainViewWorkbookOrderDelegator( - workbooksOrderBySubscriptionCount, memberSubscribedWorkbooksReverseOrderByCurrentDay ) // then - val orderedWorkbooks = delegator.order() - assertEquals(totalWorkbookCount, orderedWorkbooks.size) + val orderedWorkbooks = delegator.order(OrderTargetWorkBooks(WorkBooks(workbooksOrderBySubscriptionCount))) + assertEquals(totalWorkbookCount, orderedWorkbooks.workbooks.workbookData.size) val expectedOrderedWorkbookIds = activeWorkbookIds + notSubscribeWorkbookIds for (i in expectedOrderedWorkbookIds.indices) { - assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks[i].id) + assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks.workbooks.workbookData[i].id) } } @@ -175,17 +174,16 @@ class AuthMainViewWorkbookOrderDelegatorTest { // when val delegator = AuthMainViewWorkbookOrderDelegator( - workbooksOrderBySubscriptionCount, memberSubscribedWorkbooksReverseOrderByCurrentDay ) // then - val orderedWorkbooks = delegator.order() - assertEquals(totalWorkbookCount, orderedWorkbooks.size) + val orderedWorkbooks = delegator.order(OrderTargetWorkBooks(WorkBooks(workbooksOrderBySubscriptionCount))) + assertEquals(totalWorkbookCount, orderedWorkbooks.workbooks.workbookData.size) val expectedOrderedWorkbookIds = notSubscribeWorkbookIds + inActiveWorkbookIds for (i in expectedOrderedWorkbookIds.indices) { - assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks[i].id) + assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks.workbooks.workbookData[i].id) } } } \ No newline at end of file