Skip to content

Commit

Permalink
Merge pull request #344 from boostcampwm2023/iOS/test#335
Browse files Browse the repository at this point in the history
test: SignUp Interactor, Worker, Presenter 테스트 추가
  • Loading branch information
loinsir authored Jan 11, 2024
2 parents 94a6c1e + c0ff6fb commit eea4d87
Show file tree
Hide file tree
Showing 11 changed files with 638 additions and 37 deletions.
25 changes: 24 additions & 1 deletion iOS/Layover/Layover.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
19AE482A2B2A127E00DD4612 /* HLSAssetResourceLoaderDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19AE48292B2A127E00DD4612 /* HLSAssetResourceLoaderDelegate.swift */; };
19AE482C2B2A1A8B00DD4612 /* HLSSliceResourceLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19AE482B2B2A1A8B00DD4612 /* HLSSliceResourceLoader.swift */; };
19AE482E2B2A24C700DD4612 /* URL+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19AE482D2B2A24C700DD4612 /* URL+.swift */; };
19B665D92B4EEDDD0083E63C /* SignUpWorkerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19B665D52B4EEDDD0083E63C /* SignUpWorkerTests.swift */; };
19B665DA2B4EEDDD0083E63C /* SignUpInteractorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19B665D62B4EEDDD0083E63C /* SignUpInteractorTests.swift */; };
19B665DB2B4EEDDD0083E63C /* SignUpPresenterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19B665D72B4EEDDD0083E63C /* SignUpPresenterTests.swift */; };
19B665DD2B4F0A7B0083E63C /* MockSignUpWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19B665DC2B4F0A7B0083E63C /* MockSignUpWorker.swift */; };
19C7AFCE2B02410F003B35F2 /* AuthManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19C7AFCD2B02410F003B35F2 /* AuthManager.swift */; };
19C7AFD62B02584D003B35F2 /* KeychainStored.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19C7AFD52B02584D003B35F2 /* KeychainStored.swift */; };
19E79AC02B0A85D0009EA9ED /* LoopingPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19E79ABF2B0A85D0009EA9ED /* LoopingPlayerView.swift */; };
Expand Down Expand Up @@ -368,6 +372,10 @@
19AE48292B2A127E00DD4612 /* HLSAssetResourceLoaderDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HLSAssetResourceLoaderDelegate.swift; sourceTree = "<group>"; };
19AE482B2B2A1A8B00DD4612 /* HLSSliceResourceLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HLSSliceResourceLoader.swift; sourceTree = "<group>"; };
19AE482D2B2A24C700DD4612 /* URL+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+.swift"; sourceTree = "<group>"; };
19B665D52B4EEDDD0083E63C /* SignUpWorkerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignUpWorkerTests.swift; sourceTree = "<group>"; };
19B665D62B4EEDDD0083E63C /* SignUpInteractorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignUpInteractorTests.swift; sourceTree = "<group>"; };
19B665D72B4EEDDD0083E63C /* SignUpPresenterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignUpPresenterTests.swift; sourceTree = "<group>"; };
19B665DC2B4F0A7B0083E63C /* MockSignUpWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockSignUpWorker.swift; sourceTree = "<group>"; };
19C7AFCD2B02410F003B35F2 /* AuthManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthManager.swift; sourceTree = "<group>"; };
19C7AFD52B02584D003B35F2 /* KeychainStored.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainStored.swift; sourceTree = "<group>"; };
19E79ABF2B0A85D0009EA9ED /* LoopingPlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoopingPlayerView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -619,6 +627,7 @@
194C21C72B1DF09B00C62645 /* Scenes */ = {
isa = PBXGroup;
children = (
19B665D32B4EEDDD0083E63C /* SignUp */,
19AE481D2B29D02700DD4612 /* EditProfile */,
19AE48122B28C2A800DD4612 /* Setting */,
192513632B26F7BB001533FA /* TagPlayList */,
Expand Down Expand Up @@ -647,6 +656,7 @@
1925136C2B26F84E001533FA /* MockTagPlayListWorker.swift */,
192513842B27852C001533FA /* MockUserWorker.swift */,
19AE481B2B28C53800DD4612 /* MockSettingWorker.swift */,
19B665DC2B4F0A7B0083E63C /* MockSignUpWorker.swift */,
);
path = Workers;
sourceTree = "<group>";
Expand Down Expand Up @@ -793,6 +803,16 @@
path = HLSResourceLoader;
sourceTree = "<group>";
};
19B665D32B4EEDDD0083E63C /* SignUp */ = {
isa = PBXGroup;
children = (
19B665D62B4EEDDD0083E63C /* SignUpInteractorTests.swift */,
19B665D72B4EEDDD0083E63C /* SignUpPresenterTests.swift */,
19B665D52B4EEDDD0083E63C /* SignUpWorkerTests.swift */,
);
path = SignUp;
sourceTree = "<group>";
};
19BB8A572B07BEE30070B922 /* UIComponents */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1436,7 +1456,6 @@
FC2511AB2B04EA6B004717BC /* MapConfigurator.swift in Sources */,
1945523B2B05258200299768 /* HomeConfigurator.swift in Sources */,
FCF19BE22B2A4088003002E0 /* AVFileType+.swift in Sources */,
FC5BE11D2B148D160036366D /* EditProfileWorker.swift in Sources */,
19A1693A2B17BCC400DB34C0 /* MemberDTO.swift in Sources */,
194551F62B037F2D00299768 /* LoginViewController.swift in Sources */,
FC767FA52B125F430088CF9B /* UIViewController+.swift in Sources */,
Expand Down Expand Up @@ -1581,6 +1600,7 @@
files = (
192513852B27852C001533FA /* MockUserWorker.swift in Sources */,
192513832B277CD7001533FA /* ProfilePresenterTests.swift in Sources */,
19B665DD2B4F0A7B0083E63C /* MockSignUpWorker.swift in Sources */,
192513812B277CD7001533FA /* ProfileInteractorTests.swift in Sources */,
194C21C42B1DEE6B00C62645 /* HomeInteractorTests.swift in Sources */,
FC4E0C0F2B282AE500152596 /* UploadPostPresenterTests.swift in Sources */,
Expand All @@ -1600,11 +1620,14 @@
1925136D2B26F84E001533FA /* MockTagPlayListWorker.swift in Sources */,
19AE481A2B28C2B700DD4612 /* SettingPresenterTests.swift in Sources */,
19AE48172B28C2B700DD4612 /* SettingViewControllerTests.swift in Sources */,
19B665DA2B4EEDDD0083E63C /* SignUpInteractorTests.swift in Sources */,
19B665DB2B4EEDDD0083E63C /* SignUpPresenterTests.swift in Sources */,
194C21C32B1DEE6B00C62645 /* HomeViewControllerTests.swift in Sources */,
192513692B26F7CE001533FA /* TagPlayListInteractorTests.swift in Sources */,
19AE48232B29D03D00DD4612 /* EditProfileInteractorTests.swift in Sources */,
194C21CC2B1DF39200C62645 /* MockHomeWorker.swift in Sources */,
FC4E0C0E2B282AE500152596 /* UploadPostWorkerTests.swift in Sources */,
19B665D92B4EEDDD0083E63C /* SignUpWorkerTests.swift in Sources */,
FC4E0C112B28595200152596 /* MockUploadPostWorker.swift in Sources */,
FC4E0C0D2B282AE500152596 /* UploadPostInteractorTests.swift in Sources */,
);
Expand Down
38 changes: 17 additions & 21 deletions iOS/Layover/Layover/Scenes/SignUpScene/SignUpInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import UIKit

protocol SignUpBusinessLogic {
func validateNickname(with request: SignUpModels.ValidateNickname.Request)
func checkDuplication(with request: SignUpModels.CheckDuplication.Request)
func signUp(with request: SignUpModels.SignUp.Request)
func checkDuplication(with request: SignUpModels.CheckDuplication.Request) async
func signUp(with request: SignUpModels.SignUp.Request) async
}

protocol SignUpDataStore: AnyObject {
Expand Down Expand Up @@ -40,33 +40,29 @@ final class SignUpInteractor: SignUpBusinessLogic, SignUpDataStore {
presenter?.presentNicknameValidation(with: SignUpModels.ValidateNickname.Response(nicknameState: response))
}

func checkDuplication(with request: SignUpModels.CheckDuplication.Request) {
Task {
let response = await userWorker?.checkNotDuplication(for: request.nickname)
await MainActor.run {
presenter?.presentNicknameDuplication(with: SignUpModels.CheckDuplication.Response(isValid: response ?? false))
}
func checkDuplication(with request: SignUpModels.CheckDuplication.Request) async {
let response = await userWorker?.checkNotDuplication(for: request.nickname)
await MainActor.run {
presenter?.presentNicknameDuplication(with: SignUpModels.CheckDuplication.Response(isValid: response ?? false))
}
}

// MARK: - UseCase: SignUp

func signUp(with request: SignUpModels.SignUp.Request) {
func signUp(with request: SignUpModels.SignUp.Request) async {
guard let signUpType, let socialToken else { return }

Task {
switch signUpType {
case .kakao:
if await signUpWorker?.signUp(withKakao: socialToken, username: request.nickname) == true {
await MainActor.run {
presenter?.presentSignUpSuccess()
}
switch signUpType {
case .kakao:
if await signUpWorker?.signUp(withKakao: socialToken, username: request.nickname) == true {
await MainActor.run {
presenter?.presentSignUpSuccess()
}
case .apple:
if await signUpWorker?.signUp(withApple: socialToken, username: request.nickname) == true {
await MainActor.run {
presenter?.presentSignUpSuccess()
}
}
case .apple:
if await signUpWorker?.signUp(withApple: socialToken, username: request.nickname) == true {
await MainActor.run {
presenter?.presentSignUpSuccess()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class SignUpPresenter: SignUpPresentationLogic {

func presentNicknameDuplication(with response: SignUpModels.CheckDuplication.Response) {
let viewModel = Models.CheckDuplication.ViewModel(canSignUp: response.isValid)
viewController?.displayNickanmeDuplication(response: viewModel)
viewController?.displayNicknameDuplication(response: viewModel)
}

func presentSignUpSuccess() {
Expand Down
12 changes: 8 additions & 4 deletions iOS/Layover/Layover/Scenes/SignUpViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

protocol SignUpDisplayLogic: AnyObject {
func displayNicknameValidation(response: SignUpModels.ValidateNickname.ViewModel)
func displayNickanmeDuplication(response: SignUpModels.CheckDuplication.ViewModel)
func displayNicknameDuplication(response: SignUpModels.CheckDuplication.ViewModel)
func navigateToMain()
}

Expand Down Expand Up @@ -137,7 +137,9 @@ final class SignUpViewController: BaseViewController {
@objc private func checkDuplicateNicknameButtonDidTap(_ sender: UIButton) {
guard let nickname = nicknameTextfield.text else { return }
checkDuplicateNicknameButton.isEnabled = false
interactor?.checkDuplication(with: SignUpModels.CheckDuplication.Request(nickname: nickname))
Task {
await interactor?.checkDuplication(with: SignUpModels.CheckDuplication.Request(nickname: nickname))
}
}

@objc private func popViewController() {
Expand All @@ -146,7 +148,9 @@ final class SignUpViewController: BaseViewController {

@objc private func signUpButtonDidTap(_ sender: UIButton) {
guard let nickname = nicknameTextfield.text else { return }
interactor?.signUp(with: SignUpModels.SignUp.Request(nickname: nickname))
Task {
await interactor?.signUp(with: SignUpModels.SignUp.Request(nickname: nickname))
}
}
}

Expand All @@ -159,7 +163,7 @@ extension SignUpViewController: SignUpDisplayLogic {
nicknameAlertLabel.textColor = .error
}

func displayNickanmeDuplication(response: SignUpModels.CheckDuplication.ViewModel) {
func displayNicknameDuplication(response: SignUpModels.CheckDuplication.ViewModel) {
nicknameAlertLabel.isHidden = false
nicknameAlertLabel.text = response.alertDescription
nicknameAlertLabel.textColor = response.canSignUp ? .correct : .error
Expand Down
8 changes: 1 addition & 7 deletions iOS/Layover/Layover/Workers/Mocks/MockSignUpWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import OSLog

final class MockSignUpWorker {
class MockSignUpWorker: SignUpWorkerProtocol {

// MARK: - Properties

Expand All @@ -21,11 +21,6 @@ final class MockSignUpWorker {
authManager: StubAuthManager())) {
self.provider = provider
}
}

// MARK: - SignUpWorkerProtocol

extension MockSignUpWorker: SignUpWorkerProtocol {

func signUp(withKakao socialToken: String, username: String) async -> Bool {
guard let mockFileLocation = Bundle.main.url(forResource: "LoginData", withExtension: "json"),
Expand Down Expand Up @@ -86,5 +81,4 @@ extension MockSignUpWorker: SignUpWorkerProtocol {
return false
}
}

}
85 changes: 85 additions & 0 deletions iOS/Layover/LayoverTests/Mocks/Workers/MockSignUpWorker.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// MockSignUpWorker.swift
// LayoverTests
//
// Created by 김인환 on 1/11/24.
// Copyright © 2024 CodeBomber. All rights reserved.
//

@testable import Layover
import Foundation
import OSLog

class MockSignUpWorker: SignUpWorkerProtocol {

// MARK: - Properties

private let provider: ProviderType

// MARK: - Initializer

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

func signUp(withKakao socialToken: String, username: String) async -> Bool {
guard let mockFileLocation = Bundle(for: type(of: self)).url(forResource: "LoginData", withExtension: "json"),
let mockData = try? Data(contentsOf: mockFileLocation) else {
return false
}

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

do {
var bodyParameters = [String: String]()
bodyParameters.updateValue(socialToken, forKey: "accessToken")
bodyParameters.updateValue(username, forKey: "username")

let endPoint = EndPoint<Response<LoginDTO>>(path: "/oauth/signup/kakao",
method: .POST,
bodyParameters: bodyParameters)
let response = try await provider.request(with: endPoint, authenticationIfNeeded: false, retryCount: 0)
return true
} catch {
os_log(.error, log: .data, "%@", error.localizedDescription)
return false
}
}

func signUp(withApple identityToken: String, username: String) async -> Bool {
guard let fileLocation: URL = Bundle(for: type(of: self)).url(forResource: "LoginData", withExtension: "json") else {
return false
}
guard let mockData: Data = try? Data(contentsOf: fileLocation) else {
return false
}
MockURLProtocol.requestHandler = { request in
let response = HTTPURLResponse(url: request.url!,
statusCode: 200,
httpVersion: nil,
headerFields: nil)
return (response, mockData, nil)
}
do {
var bodyParameters: [String: String] = [:]
bodyParameters.updateValue(identityToken, forKey: "identityToken")
bodyParameters.updateValue(username, forKey: "username")

let endPoint = EndPoint<Response<LoginDTO>>(path: "/oauth/signup/apple",
method: .POST,
bodyParameters: bodyParameters)
let response = try await provider.request(with: endPoint, authenticationIfNeeded: false, retryCount: 0)
return true
} catch {
os_log(.error, log: .data, "%@", error.localizedDescription)
return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import OSLog

final class MockUserWorker: UserWorkerProtocol {
class MockUserWorker: UserWorkerProtocol {

// MARK: - Properties

Expand Down
Loading

0 comments on commit eea4d87

Please sign in to comment.