From 44b5e7115ab941027b7a9bffb8d8428b71fb0e2c Mon Sep 17 00:00:00 2001 From: chopmozzi <44396392+chopmozzi@users.noreply.github.com> Date: Thu, 11 Jan 2024 20:25:12 +0900 Subject: [PATCH] =?UTF-8?q?:recycle:=20Task=20=EA=B0=90=EC=8B=B8=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Workers/PlaybackInteractorTests.swift | 237 ++++++++++-------- 1 file changed, 127 insertions(+), 110 deletions(-) diff --git a/iOS/Layover/LayoverTests/Mocks/Workers/PlaybackInteractorTests.swift b/iOS/Layover/LayoverTests/Mocks/Workers/PlaybackInteractorTests.swift index aebb427..d387b7d 100644 --- a/iOS/Layover/LayoverTests/Mocks/Workers/PlaybackInteractorTests.swift +++ b/iOS/Layover/LayoverTests/Mocks/Workers/PlaybackInteractorTests.swift @@ -180,45 +180,48 @@ final class PlaybackInteractorTests: XCTestCase { // MARK: - Tests - func test_parentView가_map일_때_displayVideoList를_호출하면_presentVideoList를_호출하고_올바른_데이터를_전달한다() async { + func test_parentView가_map일_때_displayVideoList를_호출하면_presentVideoList를_호출하고_올바른_데이터를_전달한다() { // Arrange let spy = PlaybackPresentationLogicSpy() sut.presenter = spy sut.parentView = .map sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.videoURLNilPost] - // Act - await sut.displayVideoList() + Task { + // Act + await sut.displayVideoList() + + // Assert + XCTAssertTrue(spy.presentVideoListDidCalled, "displayVideoList는 presentVideoList를 호출하지 않았습니다") + // map이므로 2 + 더미셀 2 = 4 + // videoURL이 nil이면 거름 + XCTAssertEqual(spy.presentVideoListResponse.videos.count, 4) + XCTAssertEqual(spy.presentVideoListResponse.videos[0].displayedPost, spy.presentVideoListResponse.videos[2].displayedPost) + XCTAssertEqual(spy.presentVideoListResponse.videos[1].displayedPost, spy.presentVideoListResponse.videos[1].displayedPost) + XCTAssertEqual(spy.presentVideoListResponse.videos.first!.displayedPost, Seeds.PlaybackVideos.videos.last!.displayedPost) + XCTAssertEqual(spy.presentVideoListResponse.videos.last!.displayedPost, Seeds.PlaybackVideos.videos.first!.displayedPost) + } + } - // Assert - XCTAssertTrue(spy.presentVideoListDidCalled, "displayVideoList는 presentVideoList를 호출하지 않았습니다") - // map이므로 2 + 더미셀 2 = 4 - // videoURL이 nil이면 거름 - print(spy.presentVideoListResponse.videos) - XCTAssertEqual(spy.presentVideoListResponse.videos.count, 4) - XCTAssertEqual(spy.presentVideoListResponse.videos[0].displayedPost, spy.presentVideoListResponse.videos[2].displayedPost) - XCTAssertEqual(spy.presentVideoListResponse.videos[1].displayedPost, spy.presentVideoListResponse.videos[1].displayedPost) - XCTAssertEqual(spy.presentVideoListResponse.videos.first!.displayedPost, Seeds.PlaybackVideos.videos.last!.displayedPost) - XCTAssertEqual(spy.presentVideoListResponse.videos.last!.displayedPost, Seeds.PlaybackVideos.videos.first!.displayedPost) - } - - func test_displayVideoList를_호출하면_presentVideoList를_호출하고_올바른_데이터를_전달한다_parentView가_map이_아닐때() async { + func test_displayVideoList를_호출하면_presentVideoList를_호출하고_올바른_데이터를_전달한다_parentView가_map이_아닐때() { // Arrange let spy = PlaybackPresentationLogicSpy() sut.presenter = spy sut.parentView = .home sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.videoURLNilPost] - // Act - await sut.displayVideoList() - - // Assert - XCTAssertTrue(spy.presentVideoListDidCalled, "displayVideoList는 presentVideoList를 호출하지 않았습니다") - // map이므로 2 + 더미셀 2 = 4 - // videoURL이 nil이면 거름 - XCTAssertEqual(spy.presentVideoListResponse.videos.count, 2) - XCTAssertEqual(spy.presentVideoListResponse.videos.first!.displayedPost, Seeds.PlaybackVideos.videos.first!.displayedPost) - XCTAssertEqual(spy.presentVideoListResponse.videos.last!.displayedPost, Seeds.PlaybackVideos.videos.last!.displayedPost) + Task { + // Act + await sut.displayVideoList() + + // Assert + XCTAssertTrue(spy.presentVideoListDidCalled, "displayVideoList는 presentVideoList를 호출하지 않았습니다") + // map이므로 2 + 더미셀 2 = 4 + // videoURL이 nil이면 거름 + XCTAssertEqual(spy.presentVideoListResponse.videos.count, 2) + XCTAssertEqual(spy.presentVideoListResponse.videos.first!.displayedPost, Seeds.PlaybackVideos.videos.first!.displayedPost) + XCTAssertEqual(spy.presentVideoListResponse.videos.last!.displayedPost, Seeds.PlaybackVideos.videos.last!.displayedPost) + } } func test_moveInitialPlaybackCell을_호출하면_presentMoveInitialPlaybackCell을_호출하고_올바른_데이터를_전달한다_parentView가_map일_때() { @@ -587,23 +590,25 @@ final class PlaybackInteractorTests: XCTestCase { XCTAssertEqual(sut.selectedTag, "테스트") } - func test_Home_fetchPosts를_호출하면_presentLoadFetchVideosResponse를_호출한다() async { + func test_Home_fetchPosts를_호출하면_presentLoadFetchVideosResponse를_호출한다() { // Arrange let spy = PlaybackPresentationLogicSpy() sut.parentView = .home sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2] sut.presenter = spy - // act - await sut.fetchPosts() + Task { + // act + await sut.fetchPosts() - // Assert - XCTAssertTrue(spy.presentLoadFetchVideosDidCalled, "fetchPosts가 presentLoadFetchVideos를 호출하지 않았습니다") - XCTAssertEqual(spy.presentLoadFetchVideosResponse.videos.count, 1) - XCTAssertEqual(sut.posts?.count, 3) + // Assert + XCTAssertTrue(spy.presentLoadFetchVideosDidCalled, "fetchPosts가 presentLoadFetchVideos를 호출하지 않았습니다") + XCTAssertEqual(spy.presentLoadFetchVideosResponse.videos.count, 1) + XCTAssertEqual(sut.posts?.count, 3) + } } - func test_tag_fetchPosts를_호출하면_presentLoadFetchVideos를_호출한다() async throws { + func test_tag_fetchPosts를_호출하면_presentLoadFetchVideos를_호출한다() { // Arrange let spy = PlaybackPresentationLogicSpy() sut.parentView = .tag @@ -623,17 +628,19 @@ final class PlaybackInteractorTests: XCTestCase { sut.selectedTag = "테스트" sut.presenter = spy - // act - await sut.fetchPosts() + Task { + // act + await sut.fetchPosts() - // Assert - XCTAssertTrue(spy.presentLoadFetchVideosDidCalled, "fetchPosts가 presentLoadFetchVideos를 호출하지 않았습니다") - XCTAssertEqual(spy.presentLoadFetchVideosResponse.videos.count, 1) - XCTAssertEqual(sut.posts?.count, 21) - XCTAssertEqual(sut.playbackVideoInfos.count, 21) + // Assert + XCTAssertTrue(spy.presentLoadFetchVideosDidCalled, "fetchPosts가 presentLoadFetchVideos를 호출하지 않았습니다") + XCTAssertEqual(spy.presentLoadFetchVideosResponse.videos.count, 1) + XCTAssertEqual(sut.posts?.count, 21) + XCTAssertEqual(sut.playbackVideoInfos.count, 21) + } } - func test_Profile_fetchPosts를_호출하면_presentLoadFetchVideos를_호출한다() async throws { + func test_Profile_fetchPosts를_호출하면_presentLoadFetchVideos를_호출한다() { // Arrange let spy = PlaybackPresentationLogicSpy() sut.parentView = .otherProfile @@ -654,16 +661,18 @@ final class PlaybackInteractorTests: XCTestCase { sut.presenter = spy sut.memberID = -1 - // act - await sut.fetchPosts() + Task { + // act + await sut.fetchPosts() - // Assert - XCTAssertTrue(spy.presentLoadFetchVideosDidCalled, "fetchPosts가 presentLoadFetchVideos를 호출하지 않았습니다") - XCTAssertEqual(spy.presentLoadFetchVideosResponse.videos.count, 1) - XCTAssertEqual(sut.posts?.count, 21) + // Assert + XCTAssertTrue(spy.presentLoadFetchVideosDidCalled, "fetchPosts가 presentLoadFetchVideos를 호출하지 않았습니다") + XCTAssertEqual(spy.presentLoadFetchVideosResponse.videos.count, 1) + XCTAssertEqual(sut.posts?.count, 21) + } } - func test_map이_아닐_때_deleteVideo를_호출하면_presentDeleteVideo를_호출한다() async throws { + func test_map이_아닐_때_deleteVideo를_호출하면_presentDeleteVideo를_호출한다() { // Arrange let spy = PlaybackPresentationLogicSpy() let testPost: Post = Seeds.Posts.post1 @@ -686,20 +695,22 @@ final class PlaybackInteractorTests: XCTestCase { sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2] sut.playbackVideoInfos = [Models.PlaybackInfo(memberID: 0, boardID: 1), Models.PlaybackInfo(memberID: 0, boardID: 2)] - // act - await sut.deleteVideo(with: Models.DeletePlaybackVideo.Request(playbackVideo: playbackVideo, indexPathRow: 0)) - - // Assert - XCTAssertTrue(spy.presentDeleteVideoDidCalled, "deleteVideo가 presentDeleteVideo를 호출하지 않았습니다") - XCTAssertTrue(spy.presentDeleteVideoResponse.result) - XCTAssertEqual(spy.presentDeleteVideoResponse.playbackVideo, playbackVideo) - XCTAssertEqual(sut.posts!.count, 1) - XCTAssertEqual(sut.playbackVideoInfos.count, 1) + Task { + // act + await sut.deleteVideo(with: Models.DeletePlaybackVideo.Request(playbackVideo: playbackVideo, indexPathRow: 0)) + + // Assert + XCTAssertTrue(spy.presentDeleteVideoDidCalled, "deleteVideo가 presentDeleteVideo를 호출하지 않았습니다") + XCTAssertTrue(spy.presentDeleteVideoResponse.result) + XCTAssertEqual(spy.presentDeleteVideoResponse.playbackVideo, playbackVideo) + XCTAssertEqual(sut.posts!.count, 1) + XCTAssertEqual(sut.playbackVideoInfos.count, 1) + } } // TODO: map paging추가되면 로직 그냥 날려버리기 - func test_map일_때_마지막_무한스크롤셀을_지울_경우_deleteVideo를_호출하면_presentDeleteVideo를_호출한다() async { + func test_map일_때_마지막_무한스크롤셀을_지울_경우_deleteVideo를_호출하면_presentDeleteVideo를_호출한다() { // Arrange let spy = PlaybackPresentationLogicSpy() let testPost: Post = Seeds.Posts.post1 @@ -722,24 +733,26 @@ final class PlaybackInteractorTests: XCTestCase { sut.posts = [Seeds.Posts.thumbnailImageNilPost, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.thumbnailImageNilPost ,Seeds.Posts.post1] sut.playbackVideoInfos = [Models.PlaybackInfo(memberID: 0, boardID: 3), Models.PlaybackInfo(memberID: 0, boardID: 1), Models.PlaybackInfo(memberID: 0, boardID: 2), Models.PlaybackInfo(memberID: 0, boardID: 3), Models.PlaybackInfo(memberID: 0, boardID: 1)] - // act - await sut.deleteVideo(with: Models.DeletePlaybackVideo.Request(playbackVideo: playbackVideo, indexPathRow: 3)) - - // assert - XCTAssertTrue(spy.presentDeleteVideoDidCalled, "deleteVideo가 presentDeleteVideo를 호출하지 않았습니다") - XCTAssertEqual(sut.playbackVideoInfos[0].boardID, 1) - XCTAssertEqual(sut.playbackVideoInfos[1].boardID, 2) - XCTAssertEqual(sut.playbackVideoInfos[2].boardID, 1) - XCTAssertEqual(sut.playbackVideoInfos[3].boardID, 2) - XCTAssertEqual(sut.posts?[0].board.identifier, Seeds.Posts.post1.board.identifier) - XCTAssertEqual(sut.posts?[1].board.identifier, Seeds.Posts.post2.board.identifier) - XCTAssertEqual(sut.posts?[2].board.identifier, Seeds.Posts.post1.board.identifier) - XCTAssertEqual(sut.posts?[3].board.identifier, Seeds.Posts.post2.board.identifier) - XCTAssertEqual(sut.playbackVideoInfos.count, 4) - XCTAssertEqual(sut.posts?.count, 4) - } - - func test_map일_때_첫번째_무한스크롤셀을_지울_경우_deleteVideo를_호출하면_presentDeleteVideo를_호출한다() async { + Task { + // act + await sut.deleteVideo(with: Models.DeletePlaybackVideo.Request(playbackVideo: playbackVideo, indexPathRow: 3)) + + // assert + XCTAssertTrue(spy.presentDeleteVideoDidCalled, "deleteVideo가 presentDeleteVideo를 호출하지 않았습니다") + XCTAssertEqual(sut.playbackVideoInfos[0].boardID, 1) + XCTAssertEqual(sut.playbackVideoInfos[1].boardID, 2) + XCTAssertEqual(sut.playbackVideoInfos[2].boardID, 1) + XCTAssertEqual(sut.playbackVideoInfos[3].boardID, 2) + XCTAssertEqual(sut.posts?[0].board.identifier, Seeds.Posts.post1.board.identifier) + XCTAssertEqual(sut.posts?[1].board.identifier, Seeds.Posts.post2.board.identifier) + XCTAssertEqual(sut.posts?[2].board.identifier, Seeds.Posts.post1.board.identifier) + XCTAssertEqual(sut.posts?[3].board.identifier, Seeds.Posts.post2.board.identifier) + XCTAssertEqual(sut.playbackVideoInfos.count, 4) + XCTAssertEqual(sut.posts?.count, 4) + } + } + + func test_map일_때_첫번째_무한스크롤셀을_지울_경우_deleteVideo를_호출하면_presentDeleteVideo를_호출한다() { // Arrange let spy = PlaybackPresentationLogicSpy() let testPost: Post = Seeds.Posts.post1 @@ -762,24 +775,26 @@ final class PlaybackInteractorTests: XCTestCase { sut.posts = [Seeds.Posts.thumbnailImageNilPost, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.thumbnailImageNilPost ,Seeds.Posts.post1] sut.playbackVideoInfos = [Models.PlaybackInfo(memberID: 0, boardID: 3), Models.PlaybackInfo(memberID: 0, boardID: 1), Models.PlaybackInfo(memberID: 0, boardID: 2), Models.PlaybackInfo(memberID: 0, boardID: 3), Models.PlaybackInfo(memberID: 0, boardID: 1)] - // act - await sut.deleteVideo(with: Models.DeletePlaybackVideo.Request(playbackVideo: playbackVideo, indexPathRow: 1)) - - // assert - XCTAssertTrue(spy.presentDeleteVideoDidCalled, "deleteVideo가 presentDeleteVideo를 호출하지 않았습니다") - XCTAssertEqual(sut.playbackVideoInfos[0].boardID, 3) - XCTAssertEqual(sut.playbackVideoInfos[1].boardID, 2) - XCTAssertEqual(sut.playbackVideoInfos[2].boardID, 3) - XCTAssertEqual(sut.playbackVideoInfos[3].boardID, 2) - XCTAssertEqual(sut.posts?[0].board.identifier, Seeds.Posts.thumbnailImageNilPost.board.identifier) - XCTAssertEqual(sut.posts?[1].board.identifier, Seeds.Posts.post2.board.identifier) - XCTAssertEqual(sut.posts?[2].board.identifier, Seeds.Posts.thumbnailImageNilPost.board.identifier) - XCTAssertEqual(sut.posts?[3].board.identifier, Seeds.Posts.post2.board.identifier) - XCTAssertEqual(sut.playbackVideoInfos.count, 4) - XCTAssertEqual(sut.posts?.count, 4) - } - - func test_map일_때_무한스크롤셀을_지우지않을_경우_deleteVideo를_호출하면_presentDeleteVideo를_호출한다() async { + Task { + // act + await sut.deleteVideo(with: Models.DeletePlaybackVideo.Request(playbackVideo: playbackVideo, indexPathRow: 1)) + + // assert + XCTAssertTrue(spy.presentDeleteVideoDidCalled, "deleteVideo가 presentDeleteVideo를 호출하지 않았습니다") + XCTAssertEqual(sut.playbackVideoInfos[0].boardID, 3) + XCTAssertEqual(sut.playbackVideoInfos[1].boardID, 2) + XCTAssertEqual(sut.playbackVideoInfos[2].boardID, 3) + XCTAssertEqual(sut.playbackVideoInfos[3].boardID, 2) + XCTAssertEqual(sut.posts?[0].board.identifier, Seeds.Posts.thumbnailImageNilPost.board.identifier) + XCTAssertEqual(sut.posts?[1].board.identifier, Seeds.Posts.post2.board.identifier) + XCTAssertEqual(sut.posts?[2].board.identifier, Seeds.Posts.thumbnailImageNilPost.board.identifier) + XCTAssertEqual(sut.posts?[3].board.identifier, Seeds.Posts.post2.board.identifier) + XCTAssertEqual(sut.playbackVideoInfos.count, 4) + XCTAssertEqual(sut.posts?.count, 4) + } + } + + func test_map일_때_무한스크롤셀을_지우지않을_경우_deleteVideo를_호출하면_presentDeleteVideo를_호출한다() { // Arrange let spy = PlaybackPresentationLogicSpy() let testPost: Post = Seeds.Posts.post1 @@ -802,20 +817,22 @@ final class PlaybackInteractorTests: XCTestCase { sut.posts = [Seeds.Posts.thumbnailImageNilPost, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.thumbnailImageNilPost ,Seeds.Posts.post1] sut.playbackVideoInfos = [Models.PlaybackInfo(memberID: 0, boardID: 3), Models.PlaybackInfo(memberID: 0, boardID: 1), Models.PlaybackInfo(memberID: 0, boardID: 2), Models.PlaybackInfo(memberID: 0, boardID: 3), Models.PlaybackInfo(memberID: 0, boardID: 1)] - // act - await sut.deleteVideo(with: Models.DeletePlaybackVideo.Request(playbackVideo: playbackVideo, indexPathRow: 2)) - - // assert - XCTAssertTrue(spy.presentDeleteVideoDidCalled, "deleteVideo가 presentDeleteVideo를 호출하지 않았습니다") - XCTAssertEqual(sut.playbackVideoInfos[0].boardID, 3) - XCTAssertEqual(sut.playbackVideoInfos[1].boardID, 1) - XCTAssertEqual(sut.playbackVideoInfos[2].boardID, 3) - XCTAssertEqual(sut.playbackVideoInfos[3].boardID, 1) - XCTAssertEqual(sut.posts?[0].board.identifier, Seeds.Posts.thumbnailImageNilPost.board.identifier) - XCTAssertEqual(sut.posts?[1].board.identifier, Seeds.Posts.post1.board.identifier) - XCTAssertEqual(sut.posts?[2].board.identifier, Seeds.Posts.thumbnailImageNilPost.board.identifier) - XCTAssertEqual(sut.posts?[3].board.identifier, Seeds.Posts.post1.board.identifier) - XCTAssertEqual(sut.playbackVideoInfos.count, 4) - XCTAssertEqual(sut.posts?.count, 4) + Task { + // act + await sut.deleteVideo(with: Models.DeletePlaybackVideo.Request(playbackVideo: playbackVideo, indexPathRow: 2)) + + // assert + XCTAssertTrue(spy.presentDeleteVideoDidCalled, "deleteVideo가 presentDeleteVideo를 호출하지 않았습니다") + XCTAssertEqual(sut.playbackVideoInfos[0].boardID, 3) + XCTAssertEqual(sut.playbackVideoInfos[1].boardID, 1) + XCTAssertEqual(sut.playbackVideoInfos[2].boardID, 3) + XCTAssertEqual(sut.playbackVideoInfos[3].boardID, 1) + XCTAssertEqual(sut.posts?[0].board.identifier, Seeds.Posts.thumbnailImageNilPost.board.identifier) + XCTAssertEqual(sut.posts?[1].board.identifier, Seeds.Posts.post1.board.identifier) + XCTAssertEqual(sut.posts?[2].board.identifier, Seeds.Posts.thumbnailImageNilPost.board.identifier) + XCTAssertEqual(sut.posts?[3].board.identifier, Seeds.Posts.post1.board.identifier) + XCTAssertEqual(sut.playbackVideoInfos.count, 4) + XCTAssertEqual(sut.posts?.count, 4) + } } }