Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Home 테스트 코드 작성 #202

Merged
merged 7 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 68 additions & 4 deletions iOS/Layover/Layover.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
1945523B2B05258200299768 /* HomeConfigurator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1945523A2B05258200299768 /* HomeConfigurator.swift */; };
194C21BB2B1B718B00C62645 /* MockHomeWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 194C21BA2B1B718B00C62645 /* MockHomeWorker.swift */; };
194C21BD2B1B728600C62645 /* StubAuthManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 194C21BC2B1B728600C62645 /* StubAuthManager.swift */; };
194C21C32B1DEE6B00C62645 /* HomeViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 194C21BF2B1DEE6A00C62645 /* HomeViewControllerTests.swift */; };
194C21C42B1DEE6B00C62645 /* HomeInteractorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 194C21C02B1DEE6A00C62645 /* HomeInteractorTests.swift */; };
194C21C52B1DEE6B00C62645 /* HomeWorkerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 194C21C12B1DEE6A00C62645 /* HomeWorkerTests.swift */; };
194C21C62B1DEE6B00C62645 /* HomePresenterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 194C21C22B1DEE6A00C62645 /* HomePresenterTests.swift */; };
194C21CC2B1DF39200C62645 /* MockHomeWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 194C21CB2B1DF39200C62645 /* MockHomeWorker.swift */; };
194C21D02B1DF65200C62645 /* PostList.json in Resources */ = {isa = PBXBuildFile; fileRef = 194C21CF2B1DF65200C62645 /* PostList.json */; };
194C21D42B1EEE3700C62645 /* sample.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = 194C21D32B1EEE3700C62645 /* sample.jpeg */; };
1972CCCF2B12438900C3C762 /* LoginEndPointFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1972CCCE2B12438900C3C762 /* LoginEndPointFactory.swift */; };
1972CCD22B125ED700C3C762 /* UserDefaultStored.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1972CCD12B125ED700C3C762 /* UserDefaultStored.swift */; };
1972CCD42B138E6B00C3C762 /* SignUpRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1972CCD32B138E6B00C3C762 /* SignUpRouter.swift */; };
Expand Down Expand Up @@ -160,7 +167,6 @@
FC7E453C2AFEB623004F155A /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC7E453B2AFEB623004F155A /* SceneDelegate.swift */; };
FC7E45432AFEB62B004F155A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FC7E45422AFEB62B004F155A /* Assets.xcassets */; };
FC7E45462AFEB62B004F155A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FC7E45442AFEB62B004F155A /* LaunchScreen.storyboard */; };
FC7E45512AFEB62C004F155A /* LayoverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC7E45502AFEB62C004F155A /* LayoverTests.swift */; };
FC7E456A2AFEC06E004F155A /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = FC7E45692AFEC06E004F155A /* .swiftlint.yml */; };
FC930E752B0CD75C00AA48E3 /* ProfilePresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC930E6F2B0CD75C00AA48E3 /* ProfilePresenter.swift */; };
FC930E772B0CD75C00AA48E3 /* ProfileRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC930E712B0CD75C00AA48E3 /* ProfileRouter.swift */; };
Expand Down Expand Up @@ -214,6 +220,13 @@
1945523A2B05258200299768 /* HomeConfigurator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeConfigurator.swift; sourceTree = "<group>"; };
194C21BA2B1B718B00C62645 /* MockHomeWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockHomeWorker.swift; sourceTree = "<group>"; };
194C21BC2B1B728600C62645 /* StubAuthManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StubAuthManager.swift; sourceTree = "<group>"; };
194C21BF2B1DEE6A00C62645 /* HomeViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewControllerTests.swift; sourceTree = "<group>"; };
194C21C02B1DEE6A00C62645 /* HomeInteractorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeInteractorTests.swift; sourceTree = "<group>"; };
194C21C12B1DEE6A00C62645 /* HomeWorkerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeWorkerTests.swift; sourceTree = "<group>"; };
194C21C22B1DEE6A00C62645 /* HomePresenterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePresenterTests.swift; sourceTree = "<group>"; };
194C21CB2B1DF39200C62645 /* MockHomeWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockHomeWorker.swift; sourceTree = "<group>"; };
194C21CF2B1DF65200C62645 /* PostList.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = PostList.json; sourceTree = "<group>"; };
194C21D32B1EEE3700C62645 /* sample.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = sample.jpeg; sourceTree = "<group>"; };
1972CCCE2B12438900C3C762 /* LoginEndPointFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginEndPointFactory.swift; sourceTree = "<group>"; };
1972CCD12B125ED700C3C762 /* UserDefaultStored.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultStored.swift; sourceTree = "<group>"; };
1972CCD32B138E6B00C3C762 /* SignUpRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpRouter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -346,7 +359,6 @@
FC7E45452AFEB62B004F155A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
FC7E45472AFEB62B004F155A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
FC7E454C2AFEB62B004F155A /* LayoverTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LayoverTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
FC7E45502AFEB62C004F155A /* LayoverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoverTests.swift; sourceTree = "<group>"; };
FC7E45692AFEC06E004F155A /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = "<group>"; };
FC930E6F2B0CD75C00AA48E3 /* ProfilePresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilePresenter.swift; sourceTree = "<group>"; };
FC930E712B0CD75C00AA48E3 /* ProfileRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileRouter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -428,6 +440,51 @@
path = Cell;
sourceTree = "<group>";
};
194C21BE2B1DEE5500C62645 /* Home */ = {
isa = PBXGroup;
children = (
194C21BF2B1DEE6A00C62645 /* HomeViewControllerTests.swift */,
194C21C02B1DEE6A00C62645 /* HomeInteractorTests.swift */,
194C21C12B1DEE6A00C62645 /* HomeWorkerTests.swift */,
194C21C22B1DEE6A00C62645 /* HomePresenterTests.swift */,
);
path = Home;
sourceTree = "<group>";
};
194C21C72B1DF09B00C62645 /* Scenes */ = {
isa = PBXGroup;
children = (
194C21BE2B1DEE5500C62645 /* Home */,
);
path = Scenes;
sourceTree = "<group>";
};
194C21C92B1DF36E00C62645 /* Mocks */ = {
isa = PBXGroup;
children = (
194C21CE2B1DF63D00C62645 /* MockDatas */,
194C21CA2B1DF37900C62645 /* Workers */,
);
path = Mocks;
sourceTree = "<group>";
};
194C21CA2B1DF37900C62645 /* Workers */ = {
isa = PBXGroup;
children = (
194C21CB2B1DF39200C62645 /* MockHomeWorker.swift */,
);
path = Workers;
sourceTree = "<group>";
};
194C21CE2B1DF63D00C62645 /* MockDatas */ = {
isa = PBXGroup;
children = (
194C21D32B1EEE3700C62645 /* sample.jpeg */,
194C21CF2B1DF65200C62645 /* PostList.json */,
);
path = MockDatas;
sourceTree = "<group>";
};
1972CCCD2B12436300C3C762 /* Factories */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -764,7 +821,8 @@
FC7E454F2AFEB62C004F155A /* LayoverTests */ = {
isa = PBXGroup;
children = (
FC7E45502AFEB62C004F155A /* LayoverTests.swift */,
194C21C92B1DF36E00C62645 /* Mocks */,
194C21C72B1DF09B00C62645 /* Scenes */,
);
path = LayoverTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -1000,6 +1058,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
194C21D02B1DF65200C62645 /* PostList.json in Resources */,
194C21D42B1EEE3700C62645 /* sample.jpeg in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1189,7 +1249,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FC7E45512AFEB62C004F155A /* LayoverTests.swift in Sources */,
194C21C42B1DEE6B00C62645 /* HomeInteractorTests.swift in Sources */,
194C21C52B1DEE6B00C62645 /* HomeWorkerTests.swift in Sources */,
194C21C62B1DEE6B00C62645 /* HomePresenterTests.swift in Sources */,
194C21C32B1DEE6B00C62645 /* HomeViewControllerTests.swift in Sources */,
194C21CC2B1DF39200C62645 /* MockHomeWorker.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
12 changes: 6 additions & 6 deletions iOS/Layover/Layover/Network/DTOs/BoardDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import Foundation

struct BoardDTO: Decodable {
let id: Int
let url: String
let videoThumbnail: String
let encodedVideoURL: String
let videoThumbnailURL: String
let latitude, longitude, title, content: String

enum CodingKeys: String, CodingKey {
case id
case url = "url"
case videoThumbnail = "video_thumbnail"
case encodedVideoURL = "encoded_video_url"
case videoThumbnailURL = "video_thumbnail_url"
case latitude, longitude, title, content
}
}
Expand All @@ -28,8 +28,8 @@ extension BoardDTO {
identifier: id,
title: title,
description: content,
thumbnailImageURL: URL(string: videoThumbnail),
videoURL: URL(string: url),
thumbnailImageURL: URL(string: videoThumbnailURL),
videoURL: URL(string: encodedVideoURL),
latitude: Double(latitude),
longitude: Double(longitude)
)
Expand Down
16 changes: 8 additions & 8 deletions iOS/Layover/Layover/Network/Mock/MockData/PostList.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
},
"board" : {
"id" : 1,
"url" : "https://assets.afcdn.com/video49/20210722/v_645516.m3u8",
"video_thumbnail" : "https://think-note.com/wp-content/uploads/2023/07/eta_3.jpg",
"encoded_video_url" : "https://assets.afcdn.com/video49/20210722/v_645516.m3u8",
"video_thumbnail_url" : "https://think-note.com/wp-content/uploads/2023/07/eta_3.jpg",
"longitude" : "37.0532156213",
"latitude" : "127.060123123",
"title" : "최강 아이돌",
Expand All @@ -30,8 +30,8 @@
},
"board" : {
"id" : 2,
"url" : "https://qc66zhsq1708.edge.naverncp.com/hls/fMG98EEU8c1UirV-awtm4qKJyhaHRcnDymRFlPLZbTs_/layover-station/IMG_0136_AVC_,HD,SD,_1Pass_30fps.mp4.smil/master.m3u8",
"video_thumbnail" : "video_thumbnail_link",
"encoded_video_url" : "https://qc66zhsq1708.edge.naverncp.com/hls/fMG98EEU8c1UirV-awtm4qKJyhaHRcnDymRFlPLZbTs_/layover-station/IMG_0136_AVC_,HD,SD,_1Pass_30fps.mp4.smil/master.m3u8",
"video_thumbnail_url" : "video_thumbnail_link",
"longitude" : "37.0532156213",
"latitude" : "127.060123123",
"title" : "프로듀스 101",
Expand All @@ -48,8 +48,8 @@
},
"board" : {
"id" : 3,
"url" : "https://sample.vodobox.net/skate_phantom_flex_4k/skate_phantom_flex_4k.m3u8",
"video_thumbnail" : "https://cdnimg.melon.co.kr/resource/image/cds/musicstory/imgUrl20210831030133473.jpg/melon/quality/90/optimize",
"encoded_video_url" : "https://sample.vodobox.net/skate_phantom_flex_4k/skate_phantom_flex_4k.m3u8",
"video_thumbnail_url" : "https://cdnimg.melon.co.kr/resource/image/cds/musicstory/imgUrl20210831030133473.jpg/melon/quality/90/optimize",
"longitude" : "37.0532156213",
"latitude" : "127.060123123",
"title" : "프로미스 나인",
Expand All @@ -66,8 +66,8 @@
},
"board" : {
"id" : 4,
"url" : "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8",
"video_thumbnail" : "https://res.heraldm.com/content/image/2023/04/16/20230416000040_0.jpg",
"encoded_video_url" : "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8",
"video_thumbnail_url" : "https://res.heraldm.com/content/image/2023/04/16/20230416000040_0.jpg",
"longitude" : "37.0532156213",
"latitude" : "127.060123123",
"title" : "아이즈원",
Expand Down
20 changes: 14 additions & 6 deletions iOS/Layover/Layover/Scenes/Home/HomeInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import UIKit

protocol HomeBusinessLogic {
func fetchPosts(with request: HomeModels.FetchPosts.Request)
func fetchThumbnailImageData(with request: HomeModels.FetchThumbnailImageData.Request)
@discardableResult
func fetchPosts(with request: HomeModels.FetchPosts.Request) -> Task<Bool, Never>
@discardableResult
func fetchThumbnailImageData(with request: HomeModels.FetchThumbnailImageData.Request) -> Task<Bool, Never>
func playPosts(with request: HomeModels.PlayPosts.Request)
func selectVideo(with request: HomeModels.SelectVideo.Request)
func showTagPlayList(with request: HomeModels.ShowTagPlayList.Request)
Expand Down Expand Up @@ -45,27 +47,33 @@ final class HomeInteractor: HomeDataStore {
// MARK: - Use Case

extension HomeInteractor: HomeBusinessLogic {
func fetchPosts(with request: Models.FetchPosts.Request) {
@discardableResult
func fetchPosts(with request: Models.FetchPosts.Request) -> Task<Bool, Never> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Task {
guard let posts = await homeWorker?.fetchPosts() else { return }
guard let posts = await homeWorker?.fetchPosts() else { return false }
let response = Models.FetchPosts.Response(posts: posts)

await MainActor.run {
self.posts = posts
presenter?.presentPosts(with: response)
}

return true
}
}

func fetchThumbnailImageData(with request: HomeModels.FetchThumbnailImageData.Request) {
@discardableResult
func fetchThumbnailImageData(with request: HomeModels.FetchThumbnailImageData.Request) -> Task<Bool, Never> {
Task {
guard let imageData = await homeWorker?.fetchImageData(of: request.imageURL) else { return }
guard let imageData = await homeWorker?.fetchImageData(of: request.imageURL) else { return false }
let response = Models.FetchThumbnailImageData.Response(imageData: imageData,
indexPath: request.indexPath)

await MainActor.run {
presenter?.presentThumbnailImage(with: response)
}

return true
}
}

Expand Down
2 changes: 1 addition & 1 deletion iOS/Layover/Layover/Scenes/Home/HomeRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protocol HomeDataPassing {
var dataStore: HomeDataStore? { get }
}

final class HomeRouter: NSObject, HomeRoutingLogic, HomeDataPassing {
class HomeRouter: NSObject, HomeRoutingLogic, HomeDataPassing {

// MARK: - Properties

Expand Down
36 changes: 0 additions & 36 deletions iOS/Layover/LayoverTests/LayoverTests.swift

This file was deleted.

79 changes: 79 additions & 0 deletions iOS/Layover/LayoverTests/Mocks/MockDatas/PostList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"customCode": "SUCCESS",
"message": "요청이 성공적으로 처리되었습니다.",
"statusCode": 200,
"data": [
{
"member" : {
"id" : 1,
"username" : "loinsir",
"introduce" : "Hi, my name is hwani",
"profile_image_url" : "https://i.namu.wiki/i/HPFgEkrlX8wtU-agoxsqlzllzfJrcFkDSJYFQxdBHUNyjyZtUpS9zy-7-6lfz4ngzB-1wbLRyhIP4TmnwPwKJ0mUec5403r5TJnI3NZpsYJL6GEVQTmR52YoFGLMbaIe4aGSzh4B4InI9r2g0VV74g.svg"
},
"board" : {
"id" : 1,
"encoded_video_url" : "https://assets.afcdn.com/video49/20210722/v_645516.m3u8",
"video_thumbnail_url" : "https://think-note.com/wp-content/uploads/2023/07/eta_3.jpg",
"longitude" : "37.0532156213",
"latitude" : "127.060123123",
"title" : "최강 아이돌",
"content" : "게시글 설명"
},
"tag" : ["나도몰라요", "너도몰라요"]
},
{
"member" : {
"id" : 2,
"username" : "chopmozzi",
"introduce" : "Hi, my name is hwani",
"profile_image_url" : "https://m.segye.com/content/image/2023/03/15/20230315514234.jpg"
},
"board" : {
"id" : 2,
"encoded_video_url" : "https://qc66zhsq1708.edge.naverncp.com/hls/fMG98EEU8c1UirV-awtm4qKJyhaHRcnDymRFlPLZbTs_/layover-station/IMG_0136_AVC_,HD,SD,_1Pass_30fps.mp4.smil/master.m3u8",
"video_thumbnail_url" : "video_thumbnail_link",
"longitude" : "37.0532156213",
"latitude" : "127.060123123",
"title" : "프로듀스 101",
"content" : "게시글 설명"
},
"tag" : ["해시태그", "해시태그2"]
},
{
"member" : {
"id" : 3,
"username" : "anyukyung",
"introduce" : "Hi, my name is hwani",
"profile_image_url" : "https://images.khan.co.kr/article/2021/11/15/l_2021111502000877900178361.jpg"
},
"board" : {
"id" : 3,
"encoded_video_url" : "https://sample.vodobox.net/skate_phantom_flex_4k/skate_phantom_flex_4k.m3u8",
"video_thumbnail_url" : "https://cdnimg.melon.co.kr/resource/image/cds/musicstory/imgUrl20210831030133473.jpg/melon/quality/90/optimize",
"longitude" : "37.0532156213",
"latitude" : "127.060123123",
"title" : "프로미스 나인",
"content" : "게시글 설명"
},
"tag" : ["해시태그1", "해시태그2"]
},
{
"member" : {
"id" : 4,
"username" : "layover",
"introduce" : "Hi, my name is hwani",
"profile_image_url" : "profile_image_link"
},
"board" : {
"id" : 4,
"encoded_video_url" : "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8",
"video_thumbnail_url" : "https://res.heraldm.com/content/image/2023/04/16/20230416000040_0.jpg",
"longitude" : "37.0532156213",
"latitude" : "127.060123123",
"title" : "아이즈원",
"content" : "게시글 설명2"
},
"tag" : ["해시태그1", "해시태그6"]
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading