From ed679d31b208736d107b6d4da5b3626c5b942297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=9A=A8=EC=A4=80?= Date: Thu, 28 Nov 2024 01:49:11 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20HomeViewModel=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20useCase=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MHPresentation/Source/Home/HomeViewModel.swift | 7 +------ .../MHPresentation/Source/Home/HomeViewModelFactory.swift | 5 +---- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/MemorialHouse/MHPresentation/MHPresentation/Source/Home/HomeViewModel.swift b/MemorialHouse/MHPresentation/MHPresentation/Source/Home/HomeViewModel.swift index 82a1c9b7..66831043 100644 --- a/MemorialHouse/MHPresentation/MHPresentation/Source/Home/HomeViewModel.swift +++ b/MemorialHouse/MHPresentation/MHPresentation/Source/Home/HomeViewModel.swift @@ -16,18 +16,13 @@ public final class HomeViewModel: ViewModelType { private let output = PassthroughSubject() private let fetchMemorialHouseUseCase: FetchMemorialHouseUseCase - private let fetchCategoryUseCase: FetchCategoriesUseCase private var cancellables = Set() private(set) var houseName = "" private(set) var bookCovers = [BookCover]() private(set) var currentBookCovers = [BookCover]() - public init( - fetchMemorialHouseUseCase: FetchMemorialHouseUseCase, - fetchCategoryUseCase: FetchCategoriesUseCase - ) { + public init(fetchMemorialHouseUseCase: FetchMemorialHouseUseCase) { self.fetchMemorialHouseUseCase = fetchMemorialHouseUseCase - self.fetchCategoryUseCase = fetchCategoryUseCase } @MainActor diff --git a/MemorialHouse/MHPresentation/MHPresentation/Source/Home/HomeViewModelFactory.swift b/MemorialHouse/MHPresentation/MHPresentation/Source/Home/HomeViewModelFactory.swift index 83cb5aa0..0f72d753 100644 --- a/MemorialHouse/MHPresentation/MHPresentation/Source/Home/HomeViewModelFactory.swift +++ b/MemorialHouse/MHPresentation/MHPresentation/Source/Home/HomeViewModelFactory.swift @@ -13,9 +13,6 @@ public struct HomeViewModelFactory { } public func make() -> HomeViewModel { - HomeViewModel( - fetchMemorialHouseUseCase: fetchMemorialHouseUseCase, - fetchCategoryUseCase: fetchCategoryUseCase - ) + HomeViewModel(fetchMemorialHouseUseCase: fetchMemorialHouseUseCase) } } From 72c6f0dcba3b2224a26667d03a45d84d0dad03b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=9A=A8=EC=A4=80?= Date: Thu, 28 Nov 2024 01:52:11 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20HomeViewModel=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HomeViewModelTest.swift | 40 +------------------ 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/MemorialHouse/MHPresentation/MHPresentationTests/HomeViewModelTest.swift b/MemorialHouse/MHPresentation/MHPresentationTests/HomeViewModelTest.swift index 8377c223..58b6f146 100644 --- a/MemorialHouse/MHPresentation/MHPresentationTests/HomeViewModelTest.swift +++ b/MemorialHouse/MHPresentation/MHPresentationTests/HomeViewModelTest.swift @@ -12,7 +12,6 @@ struct HomeViewModelTest { // Arrange 준비 단계: 테스트 대상 시스템(SUT)와 의존성을 원하는 상태로 만들기 let dummyMemorialHouse = MemorialHouse( name: "효준", - categories: ["가족", "친구"], bookCovers: [ BookCover(title: "책1", imageURL: "Temp", color: .beige, category: "가족"), BookCover(title: "책2", imageURL: "Temp", color: .beige, category: "친구") @@ -36,7 +35,6 @@ struct HomeViewModelTest { // Assert 검증 단계: 결과와 기대치를 비교해서 검증하기 #expect(sut.houseName == "효준") - #expect(sut.categories == ["전체", "즐겨찾기", "가족", "친구"]) #expect(sut.bookCovers.count == 2) } @@ -45,7 +43,6 @@ struct HomeViewModelTest { // Arrange 준비 단계: 테스트 대상 시스템(SUT)와 의존성을 원하는 상태로 만들기 let dummyMemorialHouse = MemorialHouse( name: "효준", - categories: ["가족", "친구"], bookCovers: [ BookCover(title: "책1", imageURL: "Temp", color: .beige, category: "가족"), BookCover(title: "책2", imageURL: "Temp", color: .beige, category: "친구") @@ -67,46 +64,11 @@ struct HomeViewModelTest { try await Task.sleep(nanoseconds: 500_000_000) // Act 실행 단계: SUT 메소드를 호출하면서 의존성을 전달해서 결과를 저장하기 - input.send(.selectedCategory(index: 3)) // 전체, 즐겨찾기, 가족, 친구 중에서 친구 선택 + input.send(.selectedCategory(category: "친구")) // 전체, 즐겨찾기, 가족, 친구 중에서 친구 선택 try await Task.sleep(nanoseconds: 500_000_000) // Assert 검증 단계: 결과와 기대치를 비교해서 검증하기 #expect(sut.currentBookCovers.count == 1) #expect(sut.currentBookCovers.first?.title == "책2") } - - @MainActor - @Test mutating func test유효하지_않은_인덱스를_선택하면_에러를_발생시킨다() async throws { - // Arrange 준비 단계: 테스트 대상 시스템(SUT)와 의존성을 원하는 상태로 만들기 - let dummyMemorialHouse = MemorialHouse( - name: "효준", - categories: ["가족", "친구"], - bookCovers: [ - BookCover(title: "책1", imageURL: "Temp", color: .beige, category: "가족"), - BookCover(title: "책2", imageURL: "Temp", color: .beige, category: "친구") - ] - ) - let stubFetchMemorialHouseUseCase = StubFetchMemorialHouseUseCase(dummyMemorialHouse: dummyMemorialHouse) - self.sut = HomeViewModel(fetchMemorialHouseUseCase: stubFetchMemorialHouseUseCase) - - let input = PassthroughSubject() - var receivedOutputs: [HomeViewModel.Output] = [] - - sut.transform(input: input.eraseToAnyPublisher()) - .sink { output in - receivedOutputs.append(output) - } - .store(in: &cancellables) - - input.send(.viewDidLoad) - try await Task.sleep(nanoseconds: 500_000_000) - - // Act 실행 단계: SUT 메소드를 호출하면서 의존성을 전달해서 결과를 저장하기 - receivedOutputs.removeAll() - input.send(.selectedCategory(index: 999)) - try await Task.sleep(nanoseconds: 500_000_000) - - // Assert 검증 단계: 결과와 기대치를 비교해서 검증하기 - #expect(receivedOutputs.isEmpty) - } } From 79b829f173c725fd1f5c3bbe7310b20b1644ef93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=9A=A8=EC=A4=80?= Date: Thu, 28 Nov 2024 01:54:44 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20Home=20UseCase=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Stubs/StubMemorialHouseRepository.swift | 4 ++-- .../MHDomainTests/UserHouseUseCaseTest.swift | 16 ++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/MemorialHouse/MHDomain/MHDomainTests/Stubs/StubMemorialHouseRepository.swift b/MemorialHouse/MHDomain/MHDomainTests/Stubs/StubMemorialHouseRepository.swift index c456146c..9b60c7fa 100644 --- a/MemorialHouse/MHDomain/MHDomainTests/Stubs/StubMemorialHouseRepository.swift +++ b/MemorialHouse/MHDomain/MHDomainTests/Stubs/StubMemorialHouseRepository.swift @@ -7,7 +7,7 @@ struct StubMemorialHouseRepository: MemorialHouseRepository { self.dummyData = dummyData } - func fetchMemorialHouse() async -> MemorialHouse { - return dummyData + func fetchMemorialHouse() async -> Result { + return .success(dummyData) } } diff --git a/MemorialHouse/MHDomain/MHDomainTests/UserHouseUseCaseTest.swift b/MemorialHouse/MHDomain/MHDomainTests/UserHouseUseCaseTest.swift index 62134a4c..73d2b884 100644 --- a/MemorialHouse/MHDomain/MHDomainTests/UserHouseUseCaseTest.swift +++ b/MemorialHouse/MHDomain/MHDomainTests/UserHouseUseCaseTest.swift @@ -4,11 +4,10 @@ import Testing struct MemorialHouseUseCaseTest { var sut: FetchMemorialHouseUseCase! - @Test mutating func test유저하우스_엔티티모델_가져오기() async { + @Test mutating func test유저하우스_엔티티모델_가져오기() async throws { // Arrange 준비 단계: 테스트 대상 시스템(SUT)와 의존성을 원하는 상태로 만들기 let dummyMemorialHouse = MemorialHouse( name: "더미데이터", - categories: ["가족", "친구"], bookCovers: [ BookCover(title: "책1", imageURL: "Temp", color: .beige, category: "가족"), BookCover(title: "책2", imageURL: "Temp", color: .beige, category: "친구") @@ -18,43 +17,40 @@ struct MemorialHouseUseCaseTest { self.sut = DefaultFetchMemorialHouseUseCase(repository: stubMemorialHouseRepository) // Act 실행 단계: SUT 메소드를 호출하면서 의존성을 전달해서 결과를 저장하기 - let result = await sut.execute() + let result = try await sut.execute() // Assert 검증 단계: 결과와 기대치를 비교해서 검증하기 #expect(result.name == dummyMemorialHouse.name) - #expect(result.categories == dummyMemorialHouse.categories) #expect(result.bookCovers == dummyMemorialHouse.bookCovers) } - @Test mutating func test세글자_이상인_경우_원본_문자열_그대로_반환() async { + @Test mutating func test세글자_이상인_경우_원본_문자열_그대로_반환() async throws { // Arrange 준비 단계: 테스트 대상 시스템(SUT)와 의존성을 원하는 상태로 만들기 let dummyMemorialHouse = MemorialHouse( name: "Hello", - categories: [], bookCovers: [] ) let stubMemorialHouseRepository = StubMemorialHouseRepository(dummyData: dummyMemorialHouse) self.sut = DefaultFetchMemorialHouseUseCase(repository: stubMemorialHouseRepository) // Act 실행 단계: SUT 메소드를 호출하면서 의존성을 전달해서 결과를 저장하기 - let result = await sut.execute() + let result = try await sut.execute() // Assert 검증 단계: 결과와 기대치를 비교해서 검증하기 #expect(result.name == "Hello") } - @Test mutating func test두글자_이하인_경우_글자_사이에_공백추가() async { + @Test mutating func test두글자_이하인_경우_글자_사이에_공백추가() async throws { // Arrange 준비 단계: 테스트 대상 시스템(SUT)와 의존성을 원하는 상태로 만들기 let dummyMemorialHouse = MemorialHouse( name: "Hi", - categories: [], bookCovers: [] ) let stubMemorialHouseRepository = StubMemorialHouseRepository(dummyData: dummyMemorialHouse) self.sut = DefaultFetchMemorialHouseUseCase(repository: stubMemorialHouseRepository) // Act 실행 단계: SUT 메소드를 호출하면서 의존성을 전달해서 결과를 저장하기 - let result = await sut.execute() + let result = try await sut.execute() // Assert 검증 단계: 결과와 기대치를 비교해서 검증하기 #expect(result.name == "H i")