I am trying to implement Google Sign In to my project. And I created an interface adapter as the gateway between the Google Sign In and the app.
import GoogleSignIn
import RxSwift
class GoogleSignInAdapter: NSObject {
struct SignInDTO {
let idToken: String
let fullName: String
let email: String
}
private(set) lazy var signInSuccessful = signInSuccessfulRelay.asSignal()
private let signInSuccessfulRelay = PublishRelay<SignInDTO>()
private(set) lazy var signInFailed = signInFailedRelay.asSignal()
private let signInFailedRelay = PublishRelay<Error>()
init() {
GIDSignIn.sharedInstance()?.clientID = "******"
GIDSignIn.sharedInstance()?.delegate = self
}
}
extension GoogleSignInAdapter: GIDSignInDelegate {
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let error = error {
signInFailedRelay.accept(error)
} else {
let idToken = user.authentication.idToken
let fullName = user.profile.name
let email = user.profile.email
let result = SignInDTO(idToken: idToken, fullName: fullName, email: email)
signInSuccessfulRelay.accept(result)
}
}
func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {
}
}
I am still having trouble to mock and test this adapter so I can trigger the signInSuccessfulRelay and signInFailedRelay with their respective params because the only way to do it is by triggering the delegate itself. But the only way that I can get it to trigger is by using the GIDSignInButton which is a derivative of UIView. That means I have to introduce a part of the view (which is more suited for UI testing instead of unit testing) into the unit test. Can anybody tell me how to make the tests for this class?