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 27c8110 commit a94f8f7
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 116 deletions.
172 changes: 84 additions & 88 deletions iOS/Layover/LayoverTests/Mocks/Workers/PlaybackInteractorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ final class PlaybackInteractorTests: XCTestCase {
}
}

func test_tag_fetchPosts를_호출하면_presentLoadFetchVideos를_호출한다() async throws {
func test_tag_fetchPosts를_호출하면_presentLoadFetchVideos를_호출한다() {
// Arrange
let spy = PlaybackPresentationLogicSpy()
sut.parentView = .tag
Expand All @@ -629,19 +629,17 @@ final class PlaybackInteractorTests: XCTestCase {
sut.presenter = spy

// act
await sut.fetchPosts()

try await Task.sleep(nanoseconds: 30_000_000_000)


// Assert
XCTAssertTrue(spy.presentLoadFetchVideosDidCalled, "fetchPosts가 presentLoadFetchVideos를 호출하지 않았습니다")
XCTAssertEqual(spy.presentLoadFetchVideosResponse.videos.count, 1)
XCTAssertEqual(sut.posts?.count, 21)
XCTAssertEqual(sut.playbackVideoInfos.count, 21)
Task {
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)
}
}

func test_Profile_fetchPosts를_호출하면_presentLoadFetchVideos를_호출한다() async throws {
func test_Profile_fetchPosts를_호출하면_presentLoadFetchVideos를_호출한다() {
// Arrange
let spy = PlaybackPresentationLogicSpy()
sut.parentView = .otherProfile
Expand All @@ -662,18 +660,17 @@ final class PlaybackInteractorTests: XCTestCase {
sut.presenter = spy
sut.memberID = -1

// act
await sut.fetchPosts()

try await Task.sleep(nanoseconds: 3_000_000_000)

// Assert
XCTAssertTrue(spy.presentLoadFetchVideosDidCalled, "fetchPosts가 presentLoadFetchVideos를 호출하지 않았습니다")
XCTAssertEqual(spy.presentLoadFetchVideosResponse.videos.count, 1)
XCTAssertEqual(sut.posts?.count, 21)
Task {
// act
await sut.fetchPosts()
// 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 @@ -696,22 +693,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))

try await Task.sleep(nanoseconds: 3_000_000_000)
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)
// 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 throws {
func test_map일_때_마지막_무한스크롤셀을_지울_경우_deleteVideo를_호출하면_presentDeleteVideo를_호출한다() {
// Arrange
let spy = PlaybackPresentationLogicSpy()
let testPost: Post = Seeds.Posts.post1
Expand All @@ -734,27 +731,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))

try await Task.sleep(nanoseconds: 3_000_000_000)


// 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)
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를_호출한다() async throws {
func test_map일_때_첫번째_무한스크롤셀을_지울_경우_deleteVideo를_호출하면_presentDeleteVideo를_호출한다() {
// Arrange
let spy = PlaybackPresentationLogicSpy()
let testPost: Post = Seeds.Posts.post1
Expand All @@ -777,26 +773,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))

try await Task.sleep(nanoseconds: 3_000_000_000)
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)
}
}

// 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 throws {
func test_map일_때_무한스크롤셀을_지우지않을_경우_deleteVideo를_호출하면_presentDeleteVideo를_호출한다() {
// Arrange
let spy = PlaybackPresentationLogicSpy()
let testPost: Post = Seeds.Posts.post1
Expand All @@ -819,22 +815,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))

try await Task.sleep(nanoseconds: 3_000_000_000)

// 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)
}
}
}
Loading

0 comments on commit a94f8f7

Please sign in to comment.