-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #344 from boostcampwm2023/iOS/test#335
test: SignUp Interactor, Worker, Presenter 테스트 추가
- Loading branch information
Showing
11 changed files
with
638 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
iOS/Layover/LayoverTests/Mocks/Workers/MockSignUpWorker.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.