From 7cf0958f27e5c1613ad5614661cb617bd01146ed Mon Sep 17 00:00:00 2001 From: chopmozzi <44396392+chopmozzi@users.noreply.github.com> Date: Thu, 11 Jan 2024 18:17:06 +0900 Subject: [PATCH] =?UTF-8?q?:test=5Ftube:=20Playback=20Worker=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iOS/Layover/Layover.xcodeproj/project.pbxproj | 4 + .../Mocks/Workers/PlaybackWorkerTests.swift | 132 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 iOS/Layover/LayoverTests/Mocks/Workers/PlaybackWorkerTests.swift diff --git a/iOS/Layover/Layover.xcodeproj/project.pbxproj b/iOS/Layover/Layover.xcodeproj/project.pbxproj index 2c80ebc..54c6178 100644 --- a/iOS/Layover/Layover.xcodeproj/project.pbxproj +++ b/iOS/Layover/Layover.xcodeproj/project.pbxproj @@ -148,6 +148,7 @@ 8363A32D2B4C1CBB00772DDF /* PlaybackPresenterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8363A32C2B4C1CBA00772DDF /* PlaybackPresenterTests.swift */; }; 8363A32F2B4C329100772DDF /* PlaybackInteractorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8363A32E2B4C329100772DDF /* PlaybackInteractorTests.swift */; }; 8363A3332B4D6E9B00772DDF /* MockPlaybackWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8363A3322B4D6E9B00772DDF /* MockPlaybackWorker.swift */; }; + 8363A3352B4FE14C00772DDF /* PlaybackWorkerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8363A3342B4FE14C00772DDF /* PlaybackWorkerTests.swift */; }; 836C33872B15A29600ECAFB0 /* Toast.swift in Sources */ = {isa = PBXBuildFile; fileRef = 836C33862B15A29600ECAFB0 /* Toast.swift */; }; 836C338B2B15D22C00ECAFB0 /* PlaybackConfigurator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 836C338A2B15D22C00ECAFB0 /* PlaybackConfigurator.swift */; }; 836C33912B17629400ECAFB0 /* MapRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 836C33902B17629400ECAFB0 /* MapRouter.swift */; }; @@ -408,6 +409,7 @@ 8363A32C2B4C1CBA00772DDF /* PlaybackPresenterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PlaybackPresenterTests.swift; path = LayoverTests/Mocks/Workers/PlaybackPresenterTests.swift; sourceTree = SOURCE_ROOT; }; 8363A32E2B4C329100772DDF /* PlaybackInteractorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PlaybackInteractorTests.swift; path = LayoverTests/Mocks/Workers/PlaybackInteractorTests.swift; sourceTree = SOURCE_ROOT; }; 8363A3322B4D6E9B00772DDF /* MockPlaybackWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockPlaybackWorker.swift; sourceTree = ""; }; + 8363A3342B4FE14C00772DDF /* PlaybackWorkerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PlaybackWorkerTests.swift; path = LayoverTests/Mocks/Workers/PlaybackWorkerTests.swift; sourceTree = SOURCE_ROOT; }; 836C33862B15A29600ECAFB0 /* Toast.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toast.swift; sourceTree = ""; }; 836C338A2B15D22C00ECAFB0 /* PlaybackConfigurator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackConfigurator.swift; sourceTree = ""; }; 836C33902B17629400ECAFB0 /* MapRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapRouter.swift; sourceTree = ""; }; @@ -882,6 +884,7 @@ children = ( 8363A32C2B4C1CBA00772DDF /* PlaybackPresenterTests.swift */, 8363A32E2B4C329100772DDF /* PlaybackInteractorTests.swift */, + 8363A3342B4FE14C00772DDF /* PlaybackWorkerTests.swift */, ); path = Playback; sourceTree = ""; @@ -1603,6 +1606,7 @@ FC4E0C0C2B282AE500152596 /* UploadPostViewControllerTests.swift in Sources */, 1925136B2B26F7CE001533FA /* TagPlayListPresenterTests.swift in Sources */, 192513682B26F7CE001533FA /* TagPlayListViewControllerTests.swift in Sources */, + 8363A3352B4FE14C00772DDF /* PlaybackWorkerTests.swift in Sources */, 1925136A2B26F7CE001533FA /* TagPlayListWorkerTests.swift in Sources */, 19AE48182B28C2B700DD4612 /* SettingInteractorTests.swift in Sources */, 8363A3332B4D6E9B00772DDF /* MockPlaybackWorker.swift in Sources */, diff --git a/iOS/Layover/LayoverTests/Mocks/Workers/PlaybackWorkerTests.swift b/iOS/Layover/LayoverTests/Mocks/Workers/PlaybackWorkerTests.swift new file mode 100644 index 0000000..f8d90a4 --- /dev/null +++ b/iOS/Layover/LayoverTests/Mocks/Workers/PlaybackWorkerTests.swift @@ -0,0 +1,132 @@ +// +// PlaybackWorkerTests.swift +// LayoverTests +// +// Created by 황지웅 on 1/11/24. +// Copyright © 2024 CodeBomber. All rights reserved. +// + +@testable import Layover +import XCTest + +final class PlaybackWorkerTests: XCTestCase { + // MARK: Subject under test + + typealias Models = PlaybackModels + var sut: PlaybackWorker! + + // MARK: - Test lifecycle + + override func setUp() { + super.setUp() + setupPlaybackWorker() + } + + override func tearDown() { + super.tearDown() + } + + // MARK: - Test setup + + func setupPlaybackWorker() { + sut = PlaybackWorker(provider: Provider(session: .initMockSession()), authManager: StubAuthManager()) + } + + func test_makeInfiniteScroll은_올바른_결과를_반환한다() { + // Arrange + let testPosts: [Post] = [Seeds.Posts.post1, Seeds.Posts.post2] + + // act + let result: [Post] = sut.makeInfiniteScroll(posts: testPosts) + + XCTAssertEqual(result.count, 4) + XCTAssertEqual(result[0].board.identifier, Seeds.Posts.post2.board.identifier) + XCTAssertEqual(result[1].board.identifier, Seeds.Posts.post1.board.identifier) + XCTAssertEqual(result[2].board.identifier, Seeds.Posts.post2.board.identifier) + XCTAssertEqual(result[3].board.identifier, Seeds.Posts.post1.board.identifier) + } + + func test_deletePlaybackVideo는_올바른_동작을_반환한다() async { + // Arrange + guard let mockFileLocation = Bundle(for: type(of: self)).url(forResource: "DeleteVideo", withExtension: "json"), + let mockData = try? Data(contentsOf: mockFileLocation) else { + XCTFail("Mock json 파일 로드 실패.") + return + } + + MockURLProtocol.requestHandler = { request in + let response = HTTPURLResponse(url: request.url!, + statusCode: 200, + httpVersion: nil, + headerFields: nil) + return (response, mockData, nil) + } + + let response = await sut.deletePlaybackVideo(boardID: 1) + + XCTAssertNotNil(response, "deleteVideo가 response를 정상적으로 반환하지 못함") + } + + func test_fetchHomePosts는_올바른_목록을_반환한다() async { + // Arrange + guard let mockFileLocation = Bundle(for: type(of: self)).url(forResource: "PostList", withExtension: "json"), + let mockData = try? Data(contentsOf: mockFileLocation) else { + XCTFail("Mock json 파일 로드 실패.") + return + } + + MockURLProtocol.requestHandler = { request in + let response = HTTPURLResponse(url: request.url!, + statusCode: 200, + httpVersion: nil, + headerFields: nil) + return (response, mockData, nil) + } + + var result: [Post]? + + // act + result = await sut.fetchHomePosts() + + // assert + XCTAssertNotNil(result) + XCTAssertEqual(result?.count, 1, "fetchPost가 성공적으로 데이터를 받아와서 올바른 데이터 갯수를 리턴하지 못했다.") + XCTAssertEqual(result![0].tag, Seeds.Posts.post1.tag, "fetchPost가 성공적으로 데이터를 받아와서 올바른 tag를 리턴하지 못했다.") + XCTAssertEqual(result![0].board.thumbnailImageURL, Seeds.Posts.post1.board.thumbnailImageURL, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].board.identifier, Seeds.Posts.post1.board.identifier, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].board.title, Seeds.Posts.post1.board.title, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].board.description, Seeds.Posts.post1.board.description, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].board.videoURL, Seeds.Posts.post1.board.videoURL, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].board.latitude, Seeds.Posts.post1.board.latitude, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].board.longitude, Seeds.Posts.post1.board.longitude, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].board.status, Seeds.Posts.post1.board.status, "fetchPost가 성공적으로 데이터를 받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].member.identifier, Seeds.Posts.post1.member.identifier, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].member.username, Seeds.Posts.post1.member.username, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].member.introduce, Seeds.Posts.post1.member.introduce, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].member.profileImageURL, Seeds.Posts.post1.member.profileImageURL, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + } + + func test_fetchProfilePosts_는_올바른_결과를_반환한다() async { + // Arrange + guard let mockFileLocation = Bundle(for: type(of: self)).url(forResource: "PostListMore", withExtension: "json"), + let mockData = try? Data(contentsOf: mockFileLocation) + else { + XCTFail("Mock json 파일 로드 실패.") + return + } + + MockURLProtocol.requestHandler = { request in + let response = HTTPURLResponse(url: request.url!, + statusCode: 200, + httpVersion: nil, + headerFields: nil) + return (response, mockData, nil) + } + + // act + let result = await sut.fetchProfilePosts(profileID: 2, page: 1) + + // assert + XCTAssertNotNil(result) + } +}