Fix up Tests - modify validateSession to use our network wrapper.

This commit is contained in:
Matt Kiazyk 2021-10-19 10:54:47 -05:00
parent 1496f32e28
commit e11cdd1198
No known key found for this signature in database
GPG key ID: 33D9938D5D45EFE2
4 changed files with 16 additions and 3 deletions

View file

@ -10,7 +10,7 @@ import os.log
class AppState: ObservableObject {
private let client = AppleAPI.Client()
// MARK: - Published Properties
@Published var authenticationState: AuthenticationState = .unauthenticated
@ -112,7 +112,7 @@ class AppState: ObservableObject {
// MARK: - Authentication
func validateSession() -> AnyPublisher<Void, Error> {
return client.validateSession()
return Current.network.validateSession()
.receive(on: DispatchQueue.main)
.handleEvents(receiveCompletion: { completion in
if case .failure = completion {

View file

@ -169,7 +169,7 @@ private func _installedXcodes(destination: Path) -> [InstalledXcode] {
public struct Network {
private static let client = AppleAPI.Client()
public var dataTask: (URLRequest) -> AnyPublisher<URLSession.DataTaskPublisher.Output, Error> = {
public var dataTask: (URLRequest) -> AnyPublisher<URLSession.DataTaskPublisher.Output, Error> = {
AppleAPI.Current.network.session.dataTaskPublisher(for: $0)
.mapError { $0 as Error }
.eraseToAnyPublisher()
@ -183,6 +183,10 @@ public struct Network {
public func downloadTask(with url: URL, to saveLocation: URL, resumingWith resumeData: Data?) -> (progress: Progress, publisher: AnyPublisher<(saveLocation: URL, response: URLResponse), Error>) {
return downloadTask(url, saveLocation, resumeData)
}
public var validateSession: () -> AnyPublisher<Void, Error> = {
return client.validateSession()
}
}
public struct Keychain {

View file

@ -81,6 +81,10 @@ class AppStateTests: XCTestCase {
return true
}
}
Xcodes.Current.network.validateSession = {
return Just(())
.setFailureType(to: Error.self).eraseToAnyPublisher()
}
Xcodes.Current.network.dataTask = { urlRequest in
// Don't have a valid session
if urlRequest.url! == URLRequest.olympusSession.url! {

View file

@ -68,6 +68,11 @@ extension Network {
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
)
},
validateSession: {
return Just(())
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
}
)
}