Skip to content

Instantly share code, notes, and snippets.

View itirokob's full-sized avatar

Bianca Itiroko itirokob

View GitHub Profile
@itirokob
itirokob / ASAuthorizationAppleIDCredential+extension.swift
Created November 4, 2020 14:21
Conform SWA credential to new protocol
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 {}
@itirokob
itirokob / AppleAuthenticationProvider.swift
Created November 4, 2020 14:24
Implementing SWA delegates in specific class
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)
}
@itirokob
itirokob / AppleAuthenticationProviderTests.swift
Created November 4, 2020 14:25
Testing AppleAuthenticationProviders behavior
func test_didFetchAuthorizationCredential_shouldCallDelegatesDidCompleteWithCredential() {
//Given
let sut = AppleAuthenticationProvider()
sut.delegate = delegateSpy
let mockedCredential: ASAuthorizationAppleIDCredentialProtocol = MockedCredential()
//When
sut.didFetch(authorizationCredential: mockedCredential)
//Then