mirror of
https://github.com/ProtonMail/protoncore_ios.git
synced 2026-01-16 23:00:24 +00:00
Fix: [CP-XX] Fix merge duplication and update UnitTest
Refs: https://gitlab.protontech.ch/apple/shared/protoncore/-/merge_requests/2074
This commit is contained in:
commit
8737c55b70
5 changed files with 46 additions and 29 deletions
|
|
@ -23,14 +23,41 @@ import Foundation
|
|||
import ProtonCoreDoh
|
||||
|
||||
public final class PaymentsDoH: DoH, ServerConfig {
|
||||
public let signupDomain: String = "proton.me"
|
||||
public let captchaHost: String = "https://some.captcha.host"
|
||||
public let humanVerificationV3Host: String = "https://verify.proton.me"
|
||||
public let accountHost: String = "https://verify.proton.me"
|
||||
public let defaultHost: String = "https://some.default.host"
|
||||
public let apiHost: String = "payments-api.proton.me"
|
||||
public let defaultPath: String = "/api"
|
||||
public let proxyToken: String? = nil
|
||||
public let signupDomain: String
|
||||
public let captchaHost: String
|
||||
public let humanVerificationV3Host: String
|
||||
public let accountHost: String
|
||||
public let defaultHost: String
|
||||
public let apiHost: String
|
||||
public let defaultPath: String
|
||||
public let proxyToken: String?
|
||||
|
||||
public init() {}
|
||||
public init(signupDomain: String,
|
||||
captchaHost: String,
|
||||
humanVerificationV3Host: String,
|
||||
accountHost: String,
|
||||
defaultHost: String,
|
||||
apiHost: String,
|
||||
defaultPath: String,
|
||||
proxyToken: String?) {
|
||||
self.signupDomain = signupDomain
|
||||
self.captchaHost = captchaHost
|
||||
self.humanVerificationV3Host = humanVerificationV3Host
|
||||
self.accountHost = accountHost
|
||||
self.defaultHost = defaultHost
|
||||
self.apiHost = apiHost
|
||||
self.defaultPath = defaultPath
|
||||
self.proxyToken = proxyToken
|
||||
}
|
||||
|
||||
public convenience init() {
|
||||
self.init(signupDomain: "proton.me",
|
||||
captchaHost: "https://some.captcha.host",
|
||||
humanVerificationV3Host: "https://verify.proton.me",
|
||||
accountHost: "https://verify.proton.me",
|
||||
defaultHost: "https://some.default.host",
|
||||
apiHost: "payments-api.proton.me",
|
||||
defaultPath: "/api",
|
||||
proxyToken: nil)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -231,20 +231,6 @@ public final class ProtonPlansManager: NSObject, ProtonPlansManagerProviding, @u
|
|||
}
|
||||
}
|
||||
|
||||
public func restorePurchases() async throws -> CurrentSubscriptionResponse {
|
||||
do {
|
||||
try await AppStore.sync()
|
||||
return try await getCurrentPlan()
|
||||
} catch {
|
||||
debugPrint(error)
|
||||
if error is PlansComposerError {
|
||||
throw error
|
||||
} else {
|
||||
throw(ProtonPlansManagerError.unableToRestorePurchases)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func generateUserTransactionUUID() async throws -> UUID {
|
||||
let request = try paymentsAPI.url(for: .userTransactionUUID)
|
||||
|
||||
|
|
|
|||
|
|
@ -27,9 +27,11 @@ final class MockedRemoteManager: @unchecked Sendable {
|
|||
public var paymentsAPI: PaymentsAPIs!
|
||||
private var urlSessionConfig: URLSessionConfiguration!
|
||||
public var remoteManager: RemoteManager!
|
||||
let doh: PaymentsDoH
|
||||
|
||||
init() {
|
||||
paymentsAPI = PaymentsAPIs(doh: PaymentsDoH())
|
||||
doh = PaymentsDoH()
|
||||
paymentsAPI = PaymentsAPIs(doh: doh)
|
||||
URLProtocol.registerClass(MockURLProtocol.self)
|
||||
|
||||
urlSessionConfig = URLSessionConfiguration.ephemeral
|
||||
|
|
@ -47,7 +49,9 @@ final class MockedRemoteManager: @unchecked Sendable {
|
|||
}
|
||||
|
||||
public func setupURLSessionMock(withMockResponse mock: [String: Any]? = nil,
|
||||
responseStatusCode: Int = 200) {
|
||||
urlPath: String? = nil,
|
||||
responseStatusCode: Int = 200) {
|
||||
let requestURLPath = urlPath != nil ? urlPath : doh.defaultPath
|
||||
var responseData: Data = Data()
|
||||
if let mock = mock {
|
||||
guard let data = try? JSONSerialization.data(withJSONObject: mock) else {
|
||||
|
|
@ -69,7 +73,7 @@ final class MockedRemoteManager: @unchecked Sendable {
|
|||
}
|
||||
|
||||
MockURLProtocol.requestHandler = { request in
|
||||
let response = HTTPURLResponse(url: URL(string: "https://whatever.com/mock")!,
|
||||
let response = HTTPURLResponse(url: URL(string: requestURLPath!)!,
|
||||
statusCode: responseStatusCode,
|
||||
httpVersion: nil,
|
||||
headerFields: nil)!
|
||||
|
|
|
|||
|
|
@ -163,7 +163,6 @@ extension RemoteManagerTests {
|
|||
func test_create_payment_token_no_response_fail() async throws {
|
||||
|
||||
let expectedErrorCode = 500
|
||||
mockRemoteManager.setupURLSessionMock(responseStatusCode: expectedErrorCode)
|
||||
|
||||
let token = Token(amount: 200, currency: "USD", payment: nil, paymentMethodID: nil)
|
||||
guard let request = try? paymentsAPI.url(for: .createToken(token: token)) else {
|
||||
|
|
@ -171,9 +170,11 @@ extension RemoteManagerTests {
|
|||
return
|
||||
}
|
||||
|
||||
mockRemoteManager.setupURLSessionMock(urlPath: request.url.absoluteString, responseStatusCode: expectedErrorCode)
|
||||
|
||||
await XCTAssertThrowsErrorAsync(
|
||||
try await sut.postToURL(request: request),
|
||||
RemoteError.responseReturnedError(errorCode: expectedErrorCode)
|
||||
RemoteError.responseReturnedError(errorCode: expectedErrorCode, urlString: request.url.absoluteString)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ final class StoreObserverTests: XCTestCase, @unchecked Sendable {
|
|||
let configuration = TransactionsObserverConfiguration(sessionID: "asdasd12d",
|
||||
authToken: "12d12",
|
||||
appVersion: "V200",
|
||||
env: "black",
|
||||
doh: PaymentsDoH(),
|
||||
atlasSecret: "qwdn12od")
|
||||
sut.setConfiguration(configuration)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue