Skip to content

Instantly share code, notes, and snippets.

Avatar

Bianca Itiroko itirokob

View GitHub Profile
@itirokob
itirokob / AppleAuthenticationProviderTests.swift
Created Nov 4, 2020
Testing AppleAuthenticationProviders behavior
View AppleAuthenticationProviderTests.swift
func test_didFetchAuthorizationCredential_shouldCallDelegatesDidCompleteWithCredential() {
//Given
let sut = AppleAuthenticationProvider()
sut.delegate = delegateSpy
let mockedCredential: ASAuthorizationAppleIDCredentialProtocol = MockedCredential()
//When
sut.didFetch(authorizationCredential: mockedCredential)
//Then
@itirokob
itirokob / AppleAuthenticationProvider.swift
Created Nov 4, 2020
Implementing SWA delegates in specific class
View AppleAuthenticationProvider.swift
public func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
// Call didFetch(authorizationCredential:)
}
//To test didFetch(authorizationCredential:), mock ASAuthorizationAppleIDCredentialProtocol and
//assert that your delegate is being called properly
func didFetch(authorizationCredential: ASAuthorizationAppleIDCredentialProtocol) {
let credential = mapCredential(from: authorizationCredential)
delegate?.didCompleteWith(credential: credential)
}
View ASAuthorizationAppleIDCredential+extension.swift
protocol ASAuthorizationAppleIDCredentialProtocol {
var fullName: PersonNameComponents? { get }
var email: String? { get }
var user: String { get }
var authCode: String? { get }
var idToken: String? { get }
}
extension ASAuthorizationAppleIDCredential: ASAuthorizationAppleIDCredentialProtocol {}