Skip to content

Commit

Permalink
✅ PlaybackInteractor Test 2차
Browse files Browse the repository at this point in the history
  • Loading branch information
chopmozzi committed Jan 9, 2024
1 parent 166e756 commit 244a6ca
Show file tree
Hide file tree
Showing 5 changed files with 448 additions and 97 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 @@ -147,6 +147,7 @@
835A61A92B0B5A31002F22A5 /* LoginConfigurator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835A61A82B0B5A31002F22A5 /* LoginConfigurator.swift */; };
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 */; };
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 @@ -406,6 +407,7 @@
835A61AA2B0B85FD002F22A5 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
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>"; };
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 @@ -652,6 +654,7 @@
1925136C2B26F84E001533FA /* MockTagPlayListWorker.swift */,
192513842B27852C001533FA /* MockUserWorker.swift */,
19AE481B2B28C53800DD4612 /* MockSettingWorker.swift */,
8363A3322B4D6E9B00772DDF /* MockPlaybackWorker.swift */,
);
path = Workers;
sourceTree = "<group>";
Expand Down Expand Up @@ -1602,6 +1605,7 @@
192513682B26F7CE001533FA /* TagPlayListViewControllerTests.swift in Sources */,
1925136A2B26F7CE001533FA /* TagPlayListWorkerTests.swift in Sources */,
19AE48182B28C2B700DD4612 /* SettingInteractorTests.swift in Sources */,
8363A3332B4D6E9B00772DDF /* MockPlaybackWorker.swift in Sources */,
192513A72B278BB3001533FA /* Seeds.swift in Sources */,
194C21C52B1DEE6B00C62645 /* HomeWorkerTests.swift in Sources */,
19AE481C2B28C53800DD4612 /* MockSettingWorker.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {
isNeedReplace: true)
playbackVideoInfos.append(playbackVideoInfos[request.indexPathRow - 1])
if let posts {
self.posts?.insert(posts[request.indexPathRow - 1], at: 0)
self.posts?.append(posts[request.indexPathRow - 1])
}
} else {
response = Models.DeletePlaybackVideo.Response(
Expand Down
177 changes: 177 additions & 0 deletions iOS/Layover/LayoverTests/Mocks/Workers/MockPlaybackWorker.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
//
// MockPlaybackWorker.swift
// Layover
//
// Created by 황지웅 on 12/7/23.
// Copyright © 2023 CodeBomber. All rights reserved.
//

@testable import Layover
import Foundation
import OSLog

final class MockPlaybackWorker: PlaybackWorkerProtocol {

// MARK: - Properties

typealias Models = PlaybackModels

private let provider: ProviderType
private let authManager: AuthManagerProtocol

// MARK: - Methods

init(provider: ProviderType = Provider(session: .initMockSession()), authManager: AuthManagerProtocol = StubAuthManager()) {
self.provider = provider
self.authManager = authManager
}

func makeInfiniteScroll(posts: [Post]) -> [Post] {
var tempVideos: [Post] = []
for post in posts {
if post.board.videoURL == nil {
continue
}
tempVideos.append(post)
}
guard let tempLastVideo: Post = tempVideos.last,
let tempFirstVideo: Post = tempVideos.first
else { return posts }
tempVideos.insert(tempLastVideo, at: 0)
tempVideos.append(tempFirstVideo)
return tempVideos
}

func deletePlaybackVideo(boardID: Int) async -> Bool {
guard let mockFileLocation = Bundle(for: type(of: self)).url(forResource: "DeleteVideo", withExtension: "json"),
let mockData = try? Data(contentsOf: mockFileLocation)
else {
os_log(.error, log: .data, "Failed to generate mock with error: %@", "Generate File Error")
return false
}

MockURLProtocol.requestHandler = { request in
let response = HTTPURLResponse(
url: request.url!,
statusCode: 200,
httpVersion: nil,
headerFields: nil)
return (response, mockData, nil)
}

do {
let endPoint = EndPoint<EmptyData>(
path: "/board",
method: .DELETE,
queryParameters: ["boardId": boardID])
_ = try await provider.request(with: endPoint)
return true
} catch {
os_log(.error, log: .data, "Failed to delete with error%@", error.localizedDescription)
return false
}
}

func transLocation(latitude: Double, longitude: Double) async -> String? {
"서울특별시"
}

func fetchImageData(with url: URL?) async -> Data? {
guard let url else { return nil }
do {
guard let imageURL = Bundle(for: type(of: self)).url(forResource: "sample", withExtension: "jpeg") else {
return nil
}
let mockData = try? Data(contentsOf: imageURL)
MockURLProtocol.requestHandler = { request in
let response = HTTPURLResponse(url: request.url!,
statusCode: 200,
httpVersion: nil,
headerFields: nil)
return (response, mockData, nil)
}

let data = try await provider.request(url: url)
return data
} catch {
os_log(.error, log: .data, "%@", error.localizedDescription)
return nil
}
}

func fetchHomePosts() async -> [Post]? {
guard let fileLocation = Bundle(for: type(of: self)).url(forResource: "PostList", withExtension: "json") else { return nil }
do {
let mockData = try Data(contentsOf: fileLocation)
MockURLProtocol.requestHandler = { request in
let response = HTTPURLResponse(url: request.url!,
statusCode: 200,
httpVersion: nil,
headerFields: nil)
return (response, mockData, nil)
}
let endPoint: EndPoint = EndPoint<Response<[PostDTO]>>(path: "/board/home",
method: .GET)
let response = try await provider.request(with: endPoint)
guard let data = response.data else { return nil }
return data.map { $0.toDomain() }
} catch {
os_log(.error, log: .data, "%@", error.localizedDescription)
return nil
}
}

func fetchProfilePosts(profileID: Int?, page: Int) async -> [Post]? {
let resourceFileName = switch page { case 1: "PostList" case 2: "PostListMore" default: "PostListEnd" }
guard let fileLocation = Bundle(for: type(of: self)).url(forResource: resourceFileName, withExtension: "json") else { return nil }
do {
let mockData = try Data(contentsOf: fileLocation)
MockURLProtocol.requestHandler = { request in
let response = HTTPURLResponse(url: request.url!,
statusCode: 200,
httpVersion: nil,
headerFields: nil)
return (response, mockData, nil)
}
let endPoint = EndPoint<Response<[PostDTO]>>(path: "/member/posts",
method: .GET,
queryParameters: ["page": page])
let response = try await provider.request(with: endPoint)
return response.data?.map { $0.toDomain() }
} catch {
os_log(.error, log: .data, "%@", error.localizedDescription)
return nil
}
}

func fetchTagPosts(selectedTag: String, page: Int) async -> [Post]? {
let resourceFileName = switch page { case 1: "PostList" case 2: "PostListMore" default: "PostListEnd" }
guard let fileLocation = Bundle(for: type(of: self)).url(forResource: resourceFileName, withExtension: "json") else { return nil }

do {
let mockData = try? Data(contentsOf: fileLocation)
MockURLProtocol.requestHandler = { request in
let response = HTTPURLResponse(url: request.url!,
statusCode: 200,
httpVersion: nil,
headerFields: nil)
return (response, mockData, nil)
}

let endPoint = EndPoint<Response<[PostDTO]>>(path: "/board/tag",
method: .GET,
queryParameters: ["tag": selectedTag])

let response = try await provider.request(with: endPoint)
return response.data?.map { $0.toDomain() }
} catch {
os_log(.error, log: .data, "%@", error.localizedDescription)
return nil
}
}

func isMyVideo(currentCellMemberID: Int) -> Bool {
return currentCellMemberID == authManager.memberID
}

}
Loading

0 comments on commit 244a6ca

Please sign in to comment.