Configure the AuthenticationService later now that we have 2 flows on the start screen. (#3316)

* Don't query the homeserver until confirming it (or selecting a different one).

* Setup the infrastructure to test AuthenticationService.

Implement basic tests for configuration & password login.

* Use the real AuthenticationService with a mock Client in all of the tests.

* Add tests for the ServerConfirmationScreenViewModel.

* Remove redundant view state and test for it.
This commit is contained in:
Doug
2024-09-25 14:40:18 +01:00
committed by GitHub
parent af8c16150b
commit a8dbda90d9
44 changed files with 1209 additions and 298 deletions
@@ -0,0 +1,75 @@
//
// Copyright 2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only
// Please see LICENSE in the repository root for full details.
//
import Foundation
import MatrixRustSDK
extension ClientSDKMock {
struct Configuration {
// MARK: Authentication
var serverAddress = "matrix.org"
var homeserverURL = "https://matrix-client.matrix.org"
var slidingSyncVersion = SlidingSyncVersion.native
var oidcLoginURL: String?
var supportsPasswordLogin = true
var elementWellKnown = "{\"registration_helper_url\":\"https://develop.element.io/#/mobile_register\"}"
var validCredentials = (username: "alice", password: "12345678")
// MARK: Session
var userID: String?
var session = Session(accessToken: UUID().uuidString,
refreshToken: nil,
userId: "@alice:matrix.org",
deviceId: UUID().uuidString,
homeserverUrl: "https://matrix-client.matrix.org",
oidcData: nil,
slidingSyncVersion: .native)
}
enum MockError: Error { case generic }
convenience init(configuration: Configuration) {
self.init()
homeserverLoginDetailsReturnValue = HomeserverLoginDetailsSDKMock(configuration: configuration)
slidingSyncVersionReturnValue = configuration.slidingSyncVersion
userIdServerNameThrowableError = MockError.generic
serverReturnValue = "https://\(configuration.serverAddress)"
getUrlUrlReturnValue = configuration.elementWellKnown
urlForOidcLoginOidcConfigurationReturnValue = OidcAuthorizationDataSDKMock(configuration: configuration)
loginUsernamePasswordInitialDeviceNameDeviceIdClosure = { username, password, _, _ in
guard username == configuration.validCredentials.username,
password == configuration.validCredentials.password else {
throw MockError.generic // use the matrix error
}
}
userIdReturnValue = configuration.userID
sessionReturnValue = configuration.session
}
}
extension HomeserverLoginDetailsSDKMock {
convenience init(configuration: ClientSDKMock.Configuration) {
self.init()
slidingSyncVersionReturnValue = configuration.slidingSyncVersion
supportsPasswordLoginReturnValue = configuration.supportsPasswordLogin
supportsOidcLoginReturnValue = configuration.oidcLoginURL != nil
urlReturnValue = configuration.homeserverURL
}
}
extension OidcAuthorizationDataSDKMock {
convenience init(configuration: ClientSDKMock.Configuration) {
self.init()
loginUrlReturnValue = configuration.oidcLoginURL
}
}
@@ -0,0 +1,29 @@
//
// Copyright 2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only
// Please see LICENSE in the repository root for full details.
//
import Foundation
struct EventTimelineItemSDKMockConfiguration {
var eventID: String = UUID().uuidString
}
extension EventTimelineItemSDKMock {
convenience init(configuration: EventTimelineItemSDKMockConfiguration) {
self.init()
eventIdReturnValue = configuration.eventID
isOwnReturnValue = false
timestampReturnValue = 0
isEditableReturnValue = false
canBeRepliedToReturnValue = false
senderReturnValue = ""
senderProfileReturnValue = .pending
let timelineItemContent = TimelineItemContentSDKMock()
timelineItemContent.kindReturnValue = .redactedMessage
contentReturnValue = timelineItemContent
}
}