Skip to content

Commit

Permalink
♻️ 테스트 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
anyukyung committed Feb 20, 2024
1 parent 8b0303d commit f249f93
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 66 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 @@ -161,6 +161,7 @@
839F1DF82B62AEDA0071C622 /* LOTextLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 839F1DF72B62AEDA0071C622 /* LOTextLabel.swift */; };
83C35E1B2B108C3500D8DD5C /* PlaybackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83C35E1A2B108C3500D8DD5C /* PlaybackView.swift */; };
83C35E1E2B10923C00D8DD5C /* PlaybackCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83C35E1D2B10923C00D8DD5C /* PlaybackCell.swift */; };
FC06392E2B83D3F00019E4FB /* PostsPage.json in Resources */ = {isa = PBXBuildFile; fileRef = FC06392D2B83D3F00019E4FB /* PostsPage.json */; };
FC0E80242B1A0BBB00EF56D6 /* UploadPostPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC0E801E2B1A0BBB00EF56D6 /* UploadPostPresenter.swift */; };
FC0E80252B1A0BBB00EF56D6 /* UploadPostWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC0E801F2B1A0BBB00EF56D6 /* UploadPostWorker.swift */; };
FC0E80262B1A0BBB00EF56D6 /* UploadPostRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC0E80202B1A0BBB00EF56D6 /* UploadPostRouter.swift */; };
Expand Down Expand Up @@ -431,6 +432,7 @@
839F1DF72B62AEDA0071C622 /* LOTextLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LOTextLabel.swift; sourceTree = "<group>"; };
83C35E1A2B108C3500D8DD5C /* PlaybackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackView.swift; sourceTree = "<group>"; };
83C35E1D2B10923C00D8DD5C /* PlaybackCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackCell.swift; sourceTree = "<group>"; };
FC06392D2B83D3F00019E4FB /* PostsPage.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = PostsPage.json; sourceTree = "<group>"; };
FC0E801E2B1A0BBB00EF56D6 /* UploadPostPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadPostPresenter.swift; sourceTree = "<group>"; };
FC0E801F2B1A0BBB00EF56D6 /* UploadPostWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadPostWorker.swift; sourceTree = "<group>"; };
FC0E80202B1A0BBB00EF56D6 /* UploadPostRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadPostRouter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -684,6 +686,7 @@
194C21CE2B1DF63D00C62645 /* MockDatas */ = {
isa = PBXGroup;
children = (
FC06392D2B83D3F00019E4FB /* PostsPage.json */,
FC4E0C122B28609C00152596 /* PostBoard.json */,
192513972B278645001533FA /* CheckSignUp.json */,
1925138D2B278645001533FA /* CheckUserName.json */,
Expand Down Expand Up @@ -1423,6 +1426,7 @@
1925139C2B278645001533FA /* DeleteVideo.json in Resources */,
1925139F2B278646001533FA /* PostListMore.json in Resources */,
1925139A2B278645001533FA /* PostList.json in Resources */,
FC06392E2B83D3F00019E4FB /* PostsPage.json in Resources */,
192513992B278645001533FA /* PostListEnd.json in Resources */,
192513A12B278646001533FA /* DeleteUser.json in Resources */,
192513A22B278646001533FA /* ReportPlaybackVideo.json in Resources */,
Expand Down
33 changes: 30 additions & 3 deletions iOS/Layover/Layover/Workers/Mocks/MockUserWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import OSLog

final class MockUserWorker: UserWorkerProtocol {


// MARK: - Properties

Expand Down Expand Up @@ -150,8 +151,10 @@ final class MockUserWorker: UserWorkerProtocol {
}

func fetchPosts(at cursor: Int?, of id: Int?) async -> PostsPage? {
let resourceFileName = switch cursor { case 1: "PostList" case 2: "PostListMore" default: "PostListEnd" }
guard let fileLocation = Bundle.main.url(forResource: resourceFileName, withExtension: "json") else { return nil }
// let resourceFileName = switch page { case 1: "PostList" case 2: "PostListMore" default: "PostListEnd" }
// let resourceFileName = cursor != nil ? "PostsPage" : "PostList"

guard let fileLocation = Bundle(for: type(of: self)).url(forResource: "PostsPage", withExtension: "json") else { return nil }
do {
let mockData = try Data(contentsOf: fileLocation)
MockURLProtocol.requestHandler = { request in
Expand All @@ -163,14 +166,38 @@ final class MockUserWorker: UserWorkerProtocol {
}
let endPoint = EndPoint<Response<PostsPageDTO>>(path: "/member/posts",
method: .GET,
queryParameters: ["cursor": cursor])
queryParameters: PostRequestDTO(cursor: cursor,
memberId: "\(id)"))
let response = try await provider.request(with: endPoint)
return response.data?.toDomain()
} catch {
os_log(.error, log: .data, "%@", error.localizedDescription)
return nil
}
}
//
// func fetchPosts(at cursor: Int?, of id: Int?) async -> PostsPage? {
// let resourceFileName = switch cursor { case 1: "PostList" case 2: "PostListMore" default: "PostListEnd" }
// guard let fileLocation = Bundle.main.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<PostsPageDTO>>(path: "/member/posts",
// method: .GET,
// queryParameters: ["cursor": cursor])
// let response = try await provider.request(with: endPoint)
// return response.data?.toDomain()
// } catch {
// os_log(.error, log: .data, "%@", error.localizedDescription)
// return nil
// }
// }

func fetchImageData(with url: URL) async -> Data? {
do {
Expand Down
32 changes: 32 additions & 0 deletions iOS/Layover/LayoverTests/Mocks/MockDatas/PostsPage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"customCode": "SUCCESS",
"message": "성공",
"statusCode": 200,
"data": {
"lastId": 32,
"boardsResDto": [
{
"member": {
"id": 221,
"username": "hwani",
"introduce": "Hi, my name is hwani",
"profile_image_url": "https://layover-profile-image.kr.obj..."
},
"board": {
"id": 1,
"encoded_video_url": "https://qc66zhsq1708.edge.naverncp.com/hls/fMG98Ec1UirV-awtm4qKJyhanmRFlPLZbTs_/layover-station/sv_AVC_HD, SD_1Pass_30fps.mp4/index.m3u8",
"video_thumbnail_url": "https://layover-video-thumbnail.kr.obj...",
"latitude": 37.0532156213,
"longitude": 37.0532156213,
"title": "붓산 광안리",
"content": "날씨가 정말 좋았따이",
"status": "COMPLETE"
},
"tag": [
"tag1",
"tag2"
]
}
]
}
}
27 changes: 25 additions & 2 deletions iOS/Layover/LayoverTests/Mocks/Workers/MockHomeWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class MockHomeWorker: HomeWorkerProtocol {
// MARK: - Methods

func fetchPosts() async -> PostsPage? {
guard let fileLocation = Bundle(for: type(of: self)).url(forResource: "PostList",
guard let fileLocation = Bundle(for: type(of: self)).url(forResource: "PostsPage",
withExtension: "json"),
let imageDataLocation = Bundle(for: type(of: self)).url(forResource: "sample",
withExtension: "jpeg")
Expand All @@ -47,7 +47,30 @@ final class MockHomeWorker: HomeWorkerProtocol {
}

func fetchMorePosts(at cursor: Int?) async -> PostsPage? {
return nil
guard let fileLocation = Bundle(for: type(of: self)).url(forResource: "PostsPage",
withExtension: "json"),
let imageDataLocation = Bundle(for: type(of: self)).url(forResource: "sample",
withExtension: "jpeg")
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<PostsPageDTO>>(path: "/board/home",
method: .GET)
let response = try await provider.request(with: endPoint)
guard let data = response.data else { return nil }
return data.toDomain()
} catch {
os_log(.error, log: .data, "%@", error.localizedDescription)
return nil
}
}

func fetchImageData(of url: URL) async -> Data? {
Expand Down
10 changes: 5 additions & 5 deletions iOS/Layover/LayoverTests/Mocks/Workers/MockPlaybackWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ final class MockPlaybackWorker: PlaybackWorkerProtocol {
}
}

func fetchHomePosts() async -> [Post]? {
func fetchHomePosts(at cursor: Int?) async -> PostsPage? {
guard let fileLocation = Bundle(for: type(of: self)).url(forResource: "PostList", withExtension: "json") else { return nil }
do {
let mockData = try Data(contentsOf: fileLocation)
Expand All @@ -105,11 +105,11 @@ final class MockPlaybackWorker: PlaybackWorkerProtocol {
headerFields: nil)
return (response, mockData, nil)
}
let endPoint: EndPoint = EndPoint<Response<[PostDTO]>>(path: "/board/home",
let endPoint: EndPoint = EndPoint<Response<PostsPageDTO>>(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() }
return data.toDomain()
} catch {
os_log(.error, log: .data, "%@", error.localizedDescription)
return nil
Expand All @@ -128,11 +128,11 @@ final class MockPlaybackWorker: PlaybackWorkerProtocol {
headerFields: nil)
return (response, mockData, nil)
}
let endPoint = EndPoint<Response<[PostDTO]>>(path: "/member/posts",
let endPoint = EndPoint<Response<PostsPageDTO>>(path: "/member/posts",
method: .GET,
queryParameters: ["page": page])
let response = try await provider.request(with: endPoint)
return response.data?.map { $0.toDomain() }
return response.data?.posts.map { $0.toDomain() }
} catch {
os_log(.error, log: .data, "%@", error.localizedDescription)
return nil
Expand Down
14 changes: 8 additions & 6 deletions iOS/Layover/LayoverTests/Mocks/Workers/MockUserWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ class MockUserWorker: UserWorkerProtocol {
}
}

func fetchPosts(at page: Int, of id: 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 }
func fetchPosts(at cursor: Int?, of id: Int?) async -> PostsPage? {
guard let fileLocation = Bundle(for: type(of: self)).url(forResource: "PostsPage", withExtension: "json") else { return nil }
do {
let mockData = try Data(contentsOf: fileLocation)
MockURLProtocol.requestHandler = { request in
Expand All @@ -161,11 +160,12 @@ class MockUserWorker: UserWorkerProtocol {
headerFields: nil)
return (response, mockData, nil)
}
let endPoint = EndPoint<Response<[PostDTO]>>(path: "/member/posts",
let endPoint = EndPoint<Response<PostsPageDTO>>(path: "/member/posts",
method: .GET,
queryParameters: ["page": page])
queryParameters: PostRequestDTO(cursor: cursor,
memberId: "\(id)"))
let response = try await provider.request(with: endPoint)
return response.data?.map { $0.toDomain() }
return response.data?.toDomain()
} catch {
os_log(.error, log: .data, "%@", error.localizedDescription)
return nil
Expand Down Expand Up @@ -205,4 +205,6 @@ class MockUserWorker: UserWorkerProtocol {
func fetchImagePresignedURL(with fileType: String) async -> String? {
return "https://s3.ap-northeast-2.amazonaws.com/sofastcar/member/1/profile.jpeg"
}


}
57 changes: 43 additions & 14 deletions iOS/Layover/LayoverTests/Scenes/Home/HomeInteractorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ final class HomeInteractorTests: XCTestCase {
// MARK: - Test doubles

final class HomePresentationLogicSpy: HomePresentationLogic {
func presentMorePosts(with response: Layover.HomeModels.FetchPosts.Response) {

}

func presentUploadScene() {

}
Expand Down Expand Up @@ -77,20 +81,45 @@ final class HomeInteractorTests: XCTestCase {
// Assert
XCTAssertTrue(spy.presentPostsCalled, "fetchPost()가 presenter의 presentPosts()를 호출하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts.count, 1, "fetchPost()가 presenter에게 올바른 데이터 갯수를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].tag, Seeds.Posts.post1.tag, "fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].thumbnailImageData, Seeds.sampleImageData, "fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.identifier, Seeds.Posts.post1.board.identifier, "fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.title, Seeds.Posts.post1.board.title, "fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.description, Seeds.Posts.post1.board.description, "fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.latitude, Seeds.Posts.post1.board.latitude, "fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.longitude, Seeds.Posts.post1.board.longitude, "fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.thumbnailImageURL, Seeds.Posts.post1.board.thumbnailImageURL, "fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.videoURL, Seeds.Posts.post1.board.videoURL, "fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.status, Seeds.Posts.post1.board.status, "fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].member.username, Seeds.Posts.post1.member.username, "fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].member.introduce, Seeds.Posts.post1.member.introduce, "fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].member.profileImageURL, Seeds.Posts.post1.member.profileImageURL, "fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].member.identifier, Seeds.Posts.post1.member.identifier, "fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].tag,
Seeds.PostsPage.post1.tag,
"fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.identifier,
Seeds.PostsPage.post1.board.identifier,
"fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.title,
Seeds.PostsPage.post1.board.title,
"fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.description,
Seeds.PostsPage.post1.board.description,
"fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.latitude,
Seeds.PostsPage.post1.board.latitude,
"fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.longitude,
Seeds.PostsPage.post1.board.longitude,
"fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.thumbnailImageURL,
Seeds.PostsPage.post1.board.thumbnailImageURL,
"fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.videoURL,
Seeds.PostsPage.post1.board.videoURL,
"fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].board.status,
Seeds.PostsPage.post1.board.status,
"fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].member.username,
Seeds.PostsPage.post1.member.username,
"fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].member.introduce,
Seeds.PostsPage.post1.member.introduce,
"fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].member.profileImageURL,
Seeds.PostsPage.post1.member.profileImageURL,
"fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
XCTAssertEqual(spy.presentPostsReceivedResponse.posts[0].member.identifier,
Seeds.PostsPage.post1.member.identifier,
"fetchPost()가 presenter에게 올바른 데이터를 저장하지 못했다.")
}

func test_playPosts는_자신의_selectedIndex값을_변경한다() {
Expand Down
Loading

0 comments on commit f249f93

Please sign in to comment.