Skip to content

Commit

Permalink
♻️ Task 감싸기
Browse files Browse the repository at this point in the history
  • Loading branch information
chopmozzi committed Jan 11, 2024
1 parent 2e3bfab commit 44b5e71
Showing 1 changed file with 127 additions and 110 deletions.
237 changes: 127 additions & 110 deletions iOS/Layover/LayoverTests/Mocks/Workers/PlaybackInteractorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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일_때() {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
}
}
}

0 comments on commit 44b5e71

Please sign in to comment.