QR Code Login Flow (#2767)

Co-authored-by: Hugh Nimmo-Smith <hughns@users.noreply.github.com>
Co-authored-by: Hugh Nimmo-Smith <hughns@element.io>
This commit is contained in:
Mauro
2024-05-29 17:07:17 +02:00
committed by GitHub
parent 66a8f6f3d1
commit 4e23f7be22
72 changed files with 1241 additions and 226 deletions
+2 -1
View File
@@ -17,10 +17,11 @@
import UIKit
extension AppMediatorMock {
static var `default`: AppMediatorProtocol {
static var `default`: AppMediatorMock {
let mock = AppMediatorMock()
mock.underlyingAppState = .active
mock.requestAuthorizationIfNeededUnderlyingReturnValue = true
mock.underlyingWindowManager = WindowManagerMock()
return mock
@@ -1014,6 +1014,70 @@ class AppMediatorMock: AppMediatorProtocol {
setIdleTimerDisabledReceivedInvocations.append(disabled)
setIdleTimerDisabledClosure?(disabled)
}
//MARK: - requestAuthorizationIfNeeded
var requestAuthorizationIfNeededUnderlyingCallsCount = 0
var requestAuthorizationIfNeededCallsCount: Int {
get {
if Thread.isMainThread {
return requestAuthorizationIfNeededUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = requestAuthorizationIfNeededUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
requestAuthorizationIfNeededUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
requestAuthorizationIfNeededUnderlyingCallsCount = newValue
}
}
}
}
var requestAuthorizationIfNeededCalled: Bool {
return requestAuthorizationIfNeededCallsCount > 0
}
var requestAuthorizationIfNeededUnderlyingReturnValue: Bool!
var requestAuthorizationIfNeededReturnValue: Bool! {
get {
if Thread.isMainThread {
return requestAuthorizationIfNeededUnderlyingReturnValue
} else {
var returnValue: Bool? = nil
DispatchQueue.main.sync {
returnValue = requestAuthorizationIfNeededUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
requestAuthorizationIfNeededUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
requestAuthorizationIfNeededUnderlyingReturnValue = newValue
}
}
}
}
var requestAuthorizationIfNeededClosure: (() async -> Bool)?
func requestAuthorizationIfNeeded() async -> Bool {
requestAuthorizationIfNeededCallsCount += 1
if let requestAuthorizationIfNeededClosure = requestAuthorizationIfNeededClosure {
return await requestAuthorizationIfNeededClosure()
} else {
return requestAuthorizationIfNeededReturnValue
}
}
}
class AudioConverterMock: AudioConverterProtocol {
@@ -7203,18 +7267,23 @@ class PollInteractionHandlerMock: PollInteractionHandlerProtocol {
}
}
class QRCodeLoginServiceMock: QRCodeLoginServiceProtocol {
var qrLoginProgressPublisher: AnyPublisher<QrLoginProgress, Never> {
get { return underlyingQrLoginProgressPublisher }
set(value) { underlyingQrLoginProgressPublisher = value }
}
var underlyingQrLoginProgressPublisher: AnyPublisher<QrLoginProgress, Never>!
//MARK: - requestAuthorizationIfNeeded
//MARK: - loginWithQRCode
var requestAuthorizationIfNeededUnderlyingCallsCount = 0
var requestAuthorizationIfNeededCallsCount: Int {
var loginWithQRCodeDataUnderlyingCallsCount = 0
var loginWithQRCodeDataCallsCount: Int {
get {
if Thread.isMainThread {
return requestAuthorizationIfNeededUnderlyingCallsCount
return loginWithQRCodeDataUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = requestAuthorizationIfNeededUnderlyingCallsCount
returnValue = loginWithQRCodeDataUnderlyingCallsCount
}
return returnValue!
@@ -7222,27 +7291,29 @@ class QRCodeLoginServiceMock: QRCodeLoginServiceProtocol {
}
set {
if Thread.isMainThread {
requestAuthorizationIfNeededUnderlyingCallsCount = newValue
loginWithQRCodeDataUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
requestAuthorizationIfNeededUnderlyingCallsCount = newValue
loginWithQRCodeDataUnderlyingCallsCount = newValue
}
}
}
}
var requestAuthorizationIfNeededCalled: Bool {
return requestAuthorizationIfNeededCallsCount > 0
var loginWithQRCodeDataCalled: Bool {
return loginWithQRCodeDataCallsCount > 0
}
var loginWithQRCodeDataReceivedData: Data?
var loginWithQRCodeDataReceivedInvocations: [Data] = []
var requestAuthorizationIfNeededUnderlyingReturnValue: Bool!
var requestAuthorizationIfNeededReturnValue: Bool! {
var loginWithQRCodeDataUnderlyingReturnValue: Result<UserSessionProtocol, QRCodeLoginServiceError>!
var loginWithQRCodeDataReturnValue: Result<UserSessionProtocol, QRCodeLoginServiceError>! {
get {
if Thread.isMainThread {
return requestAuthorizationIfNeededUnderlyingReturnValue
return loginWithQRCodeDataUnderlyingReturnValue
} else {
var returnValue: Bool? = nil
var returnValue: Result<UserSessionProtocol, QRCodeLoginServiceError>? = nil
DispatchQueue.main.sync {
returnValue = requestAuthorizationIfNeededUnderlyingReturnValue
returnValue = loginWithQRCodeDataUnderlyingReturnValue
}
return returnValue!
@@ -7250,22 +7321,24 @@ class QRCodeLoginServiceMock: QRCodeLoginServiceProtocol {
}
set {
if Thread.isMainThread {
requestAuthorizationIfNeededUnderlyingReturnValue = newValue
loginWithQRCodeDataUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
requestAuthorizationIfNeededUnderlyingReturnValue = newValue
loginWithQRCodeDataUnderlyingReturnValue = newValue
}
}
}
}
var requestAuthorizationIfNeededClosure: (() async -> Bool)?
var loginWithQRCodeDataClosure: ((Data) async -> Result<UserSessionProtocol, QRCodeLoginServiceError>)?
func requestAuthorizationIfNeeded() async -> Bool {
requestAuthorizationIfNeededCallsCount += 1
if let requestAuthorizationIfNeededClosure = requestAuthorizationIfNeededClosure {
return await requestAuthorizationIfNeededClosure()
func loginWithQRCode(data: Data) async -> Result<UserSessionProtocol, QRCodeLoginServiceError> {
loginWithQRCodeDataCallsCount += 1
loginWithQRCodeDataReceivedData = data
loginWithQRCodeDataReceivedInvocations.append(data)
if let loginWithQRCodeDataClosure = loginWithQRCodeDataClosure {
return await loginWithQRCodeDataClosure(data)
} else {
return requestAuthorizationIfNeededReturnValue
return loginWithQRCodeDataReturnValue
}
}
}
@@ -1,28 +0,0 @@
//
// Copyright 2024 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
struct QRCodeLoginServiceMockConfiguration {
var isAuthorized = true
}
extension QRCodeLoginServiceMock {
convenience init(configuration: QRCodeLoginServiceMockConfiguration) {
self.init()
requestAuthorizationIfNeededReturnValue = configuration.isAuthorized
}
}