From f249f935988fc8cba68d79ee2eda61f0b3db3048 Mon Sep 17 00:00:00 2001 From: anyukyung <1018dbrud@gmail.com> Date: Tue, 20 Feb 2024 16:34:52 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iOS/Layover/Layover.xcodeproj/project.pbxproj | 4 ++ .../Workers/Mocks/MockUserWorker.swift | 33 ++++++++++- .../Mocks/MockDatas/PostsPage.json | 32 +++++++++++ .../Mocks/Workers/MockHomeWorker.swift | 27 ++++++++- .../Mocks/Workers/MockPlaybackWorker.swift | 10 ++-- .../Mocks/Workers/MockUserWorker.swift | 14 +++-- .../Scenes/Home/HomeInteractorTests.swift | 57 ++++++++++++++----- .../Scenes/Home/HomePresenterTests.swift | 33 ++++++++--- .../Scenes/Home/HomeWorkerTests.swift | 32 +++++------ .../Profile/ProfileInteractorTests.swift | 3 - .../Profile/ProfilePresenterTests.swift | 16 +++--- iOS/Layover/LayoverTests/Seeds.swift | 17 ++++++ 12 files changed, 212 insertions(+), 66 deletions(-) create mode 100644 iOS/Layover/LayoverTests/Mocks/MockDatas/PostsPage.json diff --git a/iOS/Layover/Layover.xcodeproj/project.pbxproj b/iOS/Layover/Layover.xcodeproj/project.pbxproj index 3e192c5..880fb40 100644 --- a/iOS/Layover/Layover.xcodeproj/project.pbxproj +++ b/iOS/Layover/Layover.xcodeproj/project.pbxproj @@ -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 */; }; @@ -431,6 +432,7 @@ 839F1DF72B62AEDA0071C622 /* LOTextLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LOTextLabel.swift; sourceTree = ""; }; 83C35E1A2B108C3500D8DD5C /* PlaybackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackView.swift; sourceTree = ""; }; 83C35E1D2B10923C00D8DD5C /* PlaybackCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackCell.swift; sourceTree = ""; }; + FC06392D2B83D3F00019E4FB /* PostsPage.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = PostsPage.json; sourceTree = ""; }; FC0E801E2B1A0BBB00EF56D6 /* UploadPostPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadPostPresenter.swift; sourceTree = ""; }; FC0E801F2B1A0BBB00EF56D6 /* UploadPostWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadPostWorker.swift; sourceTree = ""; }; FC0E80202B1A0BBB00EF56D6 /* UploadPostRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadPostRouter.swift; sourceTree = ""; }; @@ -684,6 +686,7 @@ 194C21CE2B1DF63D00C62645 /* MockDatas */ = { isa = PBXGroup; children = ( + FC06392D2B83D3F00019E4FB /* PostsPage.json */, FC4E0C122B28609C00152596 /* PostBoard.json */, 192513972B278645001533FA /* CheckSignUp.json */, 1925138D2B278645001533FA /* CheckUserName.json */, @@ -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 */, diff --git a/iOS/Layover/Layover/Workers/Mocks/MockUserWorker.swift b/iOS/Layover/Layover/Workers/Mocks/MockUserWorker.swift index 6f09ec4..f805e8d 100644 --- a/iOS/Layover/Layover/Workers/Mocks/MockUserWorker.swift +++ b/iOS/Layover/Layover/Workers/Mocks/MockUserWorker.swift @@ -10,6 +10,7 @@ import Foundation import OSLog final class MockUserWorker: UserWorkerProtocol { + // MARK: - Properties @@ -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 @@ -163,7 +166,8 @@ final class MockUserWorker: UserWorkerProtocol { } let endPoint = EndPoint>(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 { @@ -171,6 +175,29 @@ final class MockUserWorker: UserWorkerProtocol { 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>(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 { diff --git a/iOS/Layover/LayoverTests/Mocks/MockDatas/PostsPage.json b/iOS/Layover/LayoverTests/Mocks/MockDatas/PostsPage.json new file mode 100644 index 0000000..5a0e28f --- /dev/null +++ b/iOS/Layover/LayoverTests/Mocks/MockDatas/PostsPage.json @@ -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" + ] + } + ] + } +} diff --git a/iOS/Layover/LayoverTests/Mocks/Workers/MockHomeWorker.swift b/iOS/Layover/LayoverTests/Mocks/Workers/MockHomeWorker.swift index dc22412..2bc796d 100644 --- a/iOS/Layover/LayoverTests/Mocks/Workers/MockHomeWorker.swift +++ b/iOS/Layover/LayoverTests/Mocks/Workers/MockHomeWorker.swift @@ -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") @@ -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>(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? { diff --git a/iOS/Layover/LayoverTests/Mocks/Workers/MockPlaybackWorker.swift b/iOS/Layover/LayoverTests/Mocks/Workers/MockPlaybackWorker.swift index dc62d72..3dc33b8 100644 --- a/iOS/Layover/LayoverTests/Mocks/Workers/MockPlaybackWorker.swift +++ b/iOS/Layover/LayoverTests/Mocks/Workers/MockPlaybackWorker.swift @@ -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) @@ -105,11 +105,11 @@ final class MockPlaybackWorker: PlaybackWorkerProtocol { headerFields: nil) return (response, mockData, nil) } - let endPoint: EndPoint = EndPoint>(path: "/board/home", + let endPoint: EndPoint = EndPoint>(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 @@ -128,11 +128,11 @@ final class MockPlaybackWorker: PlaybackWorkerProtocol { headerFields: nil) return (response, mockData, nil) } - let endPoint = EndPoint>(path: "/member/posts", + let endPoint = EndPoint>(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 diff --git a/iOS/Layover/LayoverTests/Mocks/Workers/MockUserWorker.swift b/iOS/Layover/LayoverTests/Mocks/Workers/MockUserWorker.swift index 5faa754..72a322e 100644 --- a/iOS/Layover/LayoverTests/Mocks/Workers/MockUserWorker.swift +++ b/iOS/Layover/LayoverTests/Mocks/Workers/MockUserWorker.swift @@ -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 @@ -161,11 +160,12 @@ class MockUserWorker: UserWorkerProtocol { headerFields: nil) return (response, mockData, nil) } - let endPoint = EndPoint>(path: "/member/posts", + let endPoint = EndPoint>(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 @@ -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" } + + } diff --git a/iOS/Layover/LayoverTests/Scenes/Home/HomeInteractorTests.swift b/iOS/Layover/LayoverTests/Scenes/Home/HomeInteractorTests.swift index 94c6dbf..88473d9 100644 --- a/iOS/Layover/LayoverTests/Scenes/Home/HomeInteractorTests.swift +++ b/iOS/Layover/LayoverTests/Scenes/Home/HomeInteractorTests.swift @@ -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() { } @@ -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값을_변경한다() { diff --git a/iOS/Layover/LayoverTests/Scenes/Home/HomePresenterTests.swift b/iOS/Layover/LayoverTests/Scenes/Home/HomePresenterTests.swift index 35bfd4f..c90ddd3 100644 --- a/iOS/Layover/LayoverTests/Scenes/Home/HomePresenterTests.swift +++ b/iOS/Layover/LayoverTests/Scenes/Home/HomePresenterTests.swift @@ -68,6 +68,10 @@ final class HomePresenterTests: XCTestCase { } + func displayMorePosts(with viewModel: Layover.HomeModels.FetchPosts.ViewModel) { + + } + } // MARK: - Tests @@ -76,25 +80,35 @@ final class HomePresenterTests: XCTestCase { // arrange let spy = HomeDisplayLogicSpy() sut.viewController = spy - let response = Models.FetchPosts.Response(posts: [Seeds.Posts.post1]) + let response = Models.FetchPosts.Response(cursor: Seeds.PostsPage.cursor1, + posts: [Seeds.PostsPage.post1]) // act sut.presentPosts(with: response) // assert - XCTAssertTrue(spy.displayPostsCalled, "presentPosts는 displayPosts를 실행하지 못했다.") - XCTAssertEqual(spy.displayPostsReceivedViewModel.displayedPosts.count, 1, "presentPosts는 올바른 갯수의 데이터를 전달하지 못했다.") - XCTAssertEqual(spy.displayPostsReceivedViewModel.displayedPosts[0].tags, Seeds.Posts.post1.tag, "presentPosts는 올바른 데이터를 전달하지 못했다.") - XCTAssertEqual(spy.displayPostsReceivedViewModel.displayedPosts[0].title, Seeds.Posts.post1.board.title, "presentPosts는 올바른 데이터를 전달하지 못했다.") - XCTAssertEqual(spy.displayPostsReceivedViewModel.displayedPosts[0].thumbnailImageURL, Seeds.Posts.post1.board.thumbnailImageURL, "presentPosts는 올바른 데이터를 전달하지 못했다.") - XCTAssertEqual(spy.displayPostsReceivedViewModel.displayedPosts[0].videoURL, Seeds.Posts.post1.board.videoURL, "presentPosts는 올바른 데이터를 전달하지 못했다.") + XCTAssertTrue(spy.displayPostsCalled, + "presentPosts는 displayPosts를 실행하지 못했다.") + XCTAssertEqual(spy.displayPostsReceivedViewModel.displayedPosts.count, + 1, + "presentPosts는 올바른 갯수의 데이터를 전달하지 못했다.") + XCTAssertEqual(spy.displayPostsReceivedViewModel.displayedPosts[0].tags, + Seeds.PostsPage.post1.tag, + "presentPosts는 올바른 데이터를 전달하지 못했다.") + XCTAssertEqual(spy.displayPostsReceivedViewModel.displayedPosts[0].title, Seeds.PostsPage.post1.board.title, + "presentPosts는 올바른 데이터를 전달하지 못했다.") + XCTAssertEqual(spy.displayPostsReceivedViewModel.displayedPosts[0].thumbnailImageURL, Seeds.PostsPage.post1.board.thumbnailImageURL, + "presentPosts는 올바른 데이터를 전달하지 못했다.") + XCTAssertEqual(spy.displayPostsReceivedViewModel.displayedPosts[0].videoURL, Seeds.PostsPage.post1.board.videoURL, + "presentPosts는 올바른 데이터를 전달하지 못했다.") } func test_presentPosts는_데이터의_썸네일_이미지_URL이_nil인_경우_뷰에게_해당_데이터를_전달하지_않는다() { // arrange let spy = HomeDisplayLogicSpy() sut.viewController = spy - let response = Models.FetchPosts.Response(posts: [Seeds.Posts.thumbnailImageNilPost]) + let response = Models.FetchPosts.Response(cursor: 400, + posts: [Seeds.Posts.thumbnailImageNilPost]) // act sut.presentPosts(with: response) @@ -108,7 +122,8 @@ final class HomePresenterTests: XCTestCase { // arrange let spy = HomeDisplayLogicSpy() sut.viewController = spy - let response = Models.FetchPosts.Response(posts: [Seeds.Posts.videoURLNilPost]) + let response = Models.FetchPosts.Response(cursor: 400, + posts: [Seeds.Posts.videoURLNilPost]) // act sut.presentPosts(with: response) diff --git a/iOS/Layover/LayoverTests/Scenes/Home/HomeWorkerTests.swift b/iOS/Layover/LayoverTests/Scenes/Home/HomeWorkerTests.swift index d0dd101..1a316c0 100644 --- a/iOS/Layover/LayoverTests/Scenes/Home/HomeWorkerTests.swift +++ b/iOS/Layover/LayoverTests/Scenes/Home/HomeWorkerTests.swift @@ -39,7 +39,7 @@ final class HomeWorkerTests: XCTestCase { func test_fetchPost는_성공적으로_데이터를_받아오면_Post배열을_리턴한다() async throws { // arrange - guard let mockFileLocation = Bundle(for: type(of: self)).url(forResource: "PostList", withExtension: "json"), + guard let mockFileLocation = Bundle(for: type(of: self)).url(forResource: "PostsPage", withExtension: "json"), let mockData = try? Data(contentsOf: mockFileLocation) else { XCTFail("Mock json 파일 로드 실패.") return @@ -55,24 +55,24 @@ final class HomeWorkerTests: XCTestCase { var result: [Post]? // act - result = await sut.fetchPosts() + result = await sut.fetchPosts()?.posts // 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배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].tag, Seeds.PostsPage.post1.tag, "fetchPost가 성공적으로 데이터를 받아와서 올바른 tag를 리턴하지 못했다.") + XCTAssertEqual(result![0].board.thumbnailImageURL, Seeds.PostsPage.post1.board.thumbnailImageURL, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].board.identifier, Seeds.PostsPage.post1.board.identifier, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].board.title, Seeds.PostsPage.post1.board.title, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].board.description, Seeds.PostsPage.post1.board.description, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].board.videoURL, Seeds.PostsPage.post1.board.videoURL, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].board.latitude, Seeds.PostsPage.post1.board.latitude, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].board.longitude, Seeds.PostsPage.post1.board.longitude, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].board.status, Seeds.PostsPage.post1.board.status, "fetchPost가 성공적으로 데이터를 받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].member.identifier, Seeds.PostsPage.post1.member.identifier, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].member.username, Seeds.PostsPage.post1.member.username, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].member.introduce, Seeds.PostsPage.post1.member.introduce, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") + XCTAssertEqual(result![0].member.profileImageURL, Seeds.PostsPage.post1.member.profileImageURL, "fetchPost가 성공적으로 데이터를_받아와서 Post배열을 리턴하지 못했다.") } func test_fetchPost는_데이터를_받아오지_못하면_nil을_리턴한다() async { @@ -87,7 +87,7 @@ final class HomeWorkerTests: XCTestCase { var result: [Post]? // act - result = await sut.fetchPosts() + result = await sut.fetchPosts()?.posts // assert XCTAssertNil(result) diff --git a/iOS/Layover/LayoverTests/Scenes/Profile/ProfileInteractorTests.swift b/iOS/Layover/LayoverTests/Scenes/Profile/ProfileInteractorTests.swift index aee566c..3720129 100644 --- a/iOS/Layover/LayoverTests/Scenes/Profile/ProfileInteractorTests.swift +++ b/iOS/Layover/LayoverTests/Scenes/Profile/ProfileInteractorTests.swift @@ -78,11 +78,9 @@ final class ProfileInteractorTests: XCTestCase { XCTAssertTrue(presentationLogicSpy.presentProfileCalled, "fetchProfile을 호출해서 presentProfile을 호출하지 못했다") XCTAssertEqual(presentationLogicSpy.presentProfileResponse.displayedPosts.count, 1, "presentProfileResponse에는 fetchProfile의 결과 갯수가 올바르게 담기지 못했다.") XCTAssertEqual(presentationLogicSpy.presentProfileResponse.displayedPosts[0].id, Seeds.Posts.post1.board.identifier, "presentProfileResponse에는 fetchProfile의 결과가 올바르게 담기지 못했다.") - XCTAssertEqual(presentationLogicSpy.presentProfileResponse.displayedPosts[0].thumbnailImageData, Seeds.sampleImageData, "presentProfileResponse에는 fetchProfile의 결과가 올바르게 담기지 못했다.") XCTAssertEqual(presentationLogicSpy.presentProfileResponse.displayedPosts[0].status, Seeds.Posts.post1.board.status, "presentProfileResponse에는 fetchProfile의 결과가 올바르게 담기지 못했다.") XCTAssertEqual(presentationLogicSpy.presentProfileResponse.userProfile.username, Seeds.Members.getMember1.username, "presentProfileResponse에는 fetchProfile의 결과가 올바르게 담기지 못했다.") XCTAssertEqual(presentationLogicSpy.presentProfileResponse.userProfile.introduce, Seeds.Members.getMember1.introduce, "presentProfileResponse에는 fetchProfile의 결과가 올바르게 담기지 못했다.") - XCTAssertEqual(presentationLogicSpy.presentProfileResponse.userProfile.profileImageData, Seeds.sampleImageData, "presentProfileResponse에는 fetchProfile의 결과가 올바르게 담기지 못했다.") } func test_fetchMorePosts을_호출하면_presenter의_presentMorePosts을_호출하고_presentMorePostsResponse를_전달한다() async { @@ -97,7 +95,6 @@ final class ProfileInteractorTests: XCTestCase { XCTAssertTrue(presentationLogicSpy.presentMorePostsCalled, "fetchMorePosts을 호출해서 presentMorePosts을 호출하지 못했다") XCTAssertEqual(presentationLogicSpy.presentMorePostsResponse.displayedPosts.count, 1, "fetchMorePosts의 결과 갯수가 올바르게 담기지 못했다") XCTAssertEqual(presentationLogicSpy.presentMorePostsResponse.displayedPosts[0].id, Seeds.Posts.post1.board.identifier, "presentMorePostsResponse에는 fetchMorePosts의 결과가 올바르게 담기지 못했다") - XCTAssertEqual(presentationLogicSpy.presentMorePostsResponse.displayedPosts[0].thumbnailImageData, Seeds.sampleImageData, "presentMorePostsResponse에는 fetchMorePosts의 결과가 올바르게 담기지 못했다") XCTAssertEqual(presentationLogicSpy.presentMorePostsResponse.displayedPosts[0].status, Seeds.Posts.post1.board.status, "presentMorePostsResponse에는 fetchMorePosts의 결과가 올바르게 담기지 못했다") } diff --git a/iOS/Layover/LayoverTests/Scenes/Profile/ProfilePresenterTests.swift b/iOS/Layover/LayoverTests/Scenes/Profile/ProfilePresenterTests.swift index a7224e7..2e110bb 100644 --- a/iOS/Layover/LayoverTests/Scenes/Profile/ProfilePresenterTests.swift +++ b/iOS/Layover/LayoverTests/Scenes/Profile/ProfilePresenterTests.swift @@ -69,10 +69,10 @@ final class ProfilePresenterTests: XCTestCase { sut.viewController = spy let response = Models.FetchProfile.Response(userProfile: ProfileModels.Profile(username: Seeds.Members.getMember1.username, introduce: Seeds.Members.getMember1.introduce, - profileImageData: Seeds.sampleImageData), + profileImageURL: Seeds.Members.getMember1.profileImageURL), displayedPosts: [.init(id: Seeds.Posts.post1.board.identifier, - thumbnailImageData: Seeds.sampleImageData, - status: Seeds.Posts.post1.board.status)]) + thumbnailImageData: Seeds.Members.getMember1.profileImageURL, + status: Seeds.Posts.post1.board.status)]) // act sut.presentProfile(with: response) @@ -80,11 +80,11 @@ final class ProfilePresenterTests: XCTestCase { XCTAssertTrue(spy.displayProfileDidCalled, "presentProfile은 displayProfile을 호출하지 못했다") XCTAssertEqual(spy.displayProfileViewModel.userProfile.username, Seeds.Members.getMember1.username, "presentProfile은 올바른 데이터를 뷰에 전달하지 못했다") XCTAssertEqual(spy.displayProfileViewModel.userProfile.introduce, Seeds.Members.getMember1.introduce, "presentProfile은 올바른 데이터를 뷰에 전달하지 못했다") - XCTAssertEqual(spy.displayProfileViewModel.userProfile.profileImageData, Seeds.sampleImageData, "presentProfile은 올바른 데이터를 뷰에 전달하지 못했다") + XCTAssertEqual(spy.displayProfileViewModel.userProfile.profileImageURL, Seeds.Members.getMember1.profileImageURL, "presentProfile은 올바른 데이터를 뷰에 전달하지 못했다") XCTAssertEqual(spy.displayProfileViewModel.displayedPosts.count, 1, "presentProfile은 올바른 데이터 갯수를 뷰에 전달하지 못했다") XCTAssertEqual(spy.displayProfileViewModel.displayedPosts[0].id, Seeds.Posts.post1.board.identifier, "presentProfile은 올바른 데이터를 뷰에 전달하지 못했다") XCTAssertEqual(spy.displayProfileViewModel.displayedPosts[0].status, Seeds.Posts.post1.board.status, "presentProfile은 올바른 데이터를 뷰에 전달하지 못했다") - XCTAssertEqual(spy.displayProfileViewModel.displayedPosts[0].thumbnailImageData, Seeds.sampleImageData, "presentProfile은 올바른 데이터를 뷰에 전달하지 못했다") + XCTAssertEqual(spy.displayProfileViewModel.displayedPosts[0].thumbnailImageData, Seeds.Members.getMember1.profileImageURL, "presentProfile은 올바른 데이터를 뷰에 전달하지 못했다") } func test_presentMorePosts을_호출하면_displayMorePosts를_호출하고_올바른_데이터를_전달한다() { @@ -94,8 +94,8 @@ final class ProfilePresenterTests: XCTestCase { // act let response = Models.FetchMorePosts.Response(displayedPosts: [.init(id: Seeds.Posts.post1.board.identifier, - thumbnailImageData: Seeds.sampleImageData, - status: Seeds.Posts.post1.board.status)]) + thumbnailImageData: Seeds.Members.getMember1.profileImageURL, + status: Seeds.Posts.post1.board.status)]) sut.presentMorePosts(with: response) // assert @@ -103,7 +103,7 @@ final class ProfilePresenterTests: XCTestCase { XCTAssertEqual(spy.displayMorePostsViewModel.displayedPosts.count, 1, "presentMorePosts은 올바른 데이터 갯수를 뷰에 전달하지 못했다") XCTAssertEqual(spy.displayMorePostsViewModel.displayedPosts[0].id, Seeds.Posts.post1.board.identifier, "presentMorePosts은 올바른 데이터를 뷰에 전달하지 못했다") XCTAssertEqual(spy.displayMorePostsViewModel.displayedPosts[0].status, Seeds.Posts.post1.board.status, "presentMorePosts은 올바른 데이터를 뷰에 전달하지 못했다") - XCTAssertEqual(spy.displayMorePostsViewModel.displayedPosts[0].thumbnailImageData, Seeds.sampleImageData, "presentMorePosts은 올바른 데이터를 뷰에 전달하지 못했다") + XCTAssertEqual(spy.displayMorePostsViewModel.displayedPosts[0].thumbnailImageData, Seeds.Members.getMember1.profileImageURL, "presentMorePosts은 올바른 데이터를 뷰에 전달하지 못했다") } func test_presentPostDetail을_호출하면_routeToPostDetail을_호출한다() { diff --git a/iOS/Layover/LayoverTests/Seeds.swift b/iOS/Layover/LayoverTests/Seeds.swift index b955342..0a092be 100644 --- a/iOS/Layover/LayoverTests/Seeds.swift +++ b/iOS/Layover/LayoverTests/Seeds.swift @@ -12,6 +12,23 @@ import Foundation class Seeds { static let sampleImageData = try? Data(contentsOf: Bundle(for: Seeds.self).url(forResource: "sample", withExtension: "jpeg")!) + struct PostsPage { + static let cursor1 = 32 + static let post1 = Post(member: Member(identifier: 221, + username: "hwani", + introduce: "Hi, my name is hwani", + profileImageURL: URL(string: "https://layover-profile-image.kr.obj...")), + board: Board(identifier: 1, + title: "붓산 광안리", + description: "날씨가 정말 좋았따이", + thumbnailImageURL: URL(string: "https://layover-video-thumbnail.kr.obj..."), + videoURL: URL(string: "https://qc66zhsq1708.edge.naverncp.com/hls/fMG98Ec1UirV-awtm4qKJyhanmRFlPLZbTs_/layover-station/sv_AVC_HD, SD_1Pass_30fps.mp4/index.m3u8"), + latitude: 37.0532156213, + longitude: 37.0532156213, + status: .complete), + tag: ["tag1", "tag2"]) + } + struct Posts { // PostList.json에 정의된 데이터 static let post1 = Post(member: Member(identifier: 1,