Skip to content

Commit

Permalink
🧪 Playback Worker추가 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
chopmozzi committed Jan 11, 2024
1 parent c918fd0 commit 7cf0958
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
4 changes: 4 additions & 0 deletions iOS/Layover/Layover.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
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 = "<group>"; };
836C338A2B15D22C00ECAFB0 /* PlaybackConfigurator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackConfigurator.swift; sourceTree = "<group>"; };
836C33902B17629400ECAFB0 /* MapRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapRouter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -882,6 +884,7 @@
children = (
8363A32C2B4C1CBA00772DDF /* PlaybackPresenterTests.swift */,
8363A32E2B4C329100772DDF /* PlaybackInteractorTests.swift */,
8363A3342B4FE14C00772DDF /* PlaybackWorkerTests.swift */,
);
path = Playback;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
132 changes: 132 additions & 0 deletions iOS/Layover/LayoverTests/Mocks/Workers/PlaybackWorkerTests.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 7cf0958

Please sign in to comment.