Replace the existing MockClientProxy with a generated one + special configuration options

This commit is contained in:
Stefan Ceriu
2024-02-27 16:22:47 +02:00
parent 14d76d9860
commit c8f728ca23
36 changed files with 793 additions and 311 deletions
@@ -0,0 +1,92 @@
//
// 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 Combine
import Foundation
struct ClientProxyMockConfiguration {
let userID: String
var deviceID: String?
var roomSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider()
}
extension ClientProxyMock {
convenience init(_ configuration: ClientProxyMockConfiguration) {
self.init()
userID = configuration.userID
deviceID = configuration.deviceID
homeserver = ""
roomSummaryProvider = configuration.roomSummaryProvider
alternateRoomSummaryProvider = MockRoomSummaryProvider()
inviteSummaryProvider = MockRoomSummaryProvider()
actionsPublisher = PassthroughSubject<ClientProxyAction, Never>().eraseToAnyPublisher()
loadingStatePublisher = CurrentValuePublisher<ClientProxyLoadingState, Never>(.notLoading)
userAvatarURLPublisher = CurrentValueSubject<URL?, Never>(nil).asCurrentValuePublisher()
userDisplayNamePublisher = CurrentValueSubject<String?, Never>("User display name").asCurrentValuePublisher()
ignoredUsersPublisher = CurrentValueSubject<[String]?, Never>([RoomMemberProxyMock].allMembers.map(\.userID)).asCurrentValuePublisher()
notificationSettings = NotificationSettingsProxyMock(with: .init())
isOnlyDeviceLeftReturnValue = .success(false)
accountURLActionReturnValue = "https://matrix.org/account"
directRoomForUserIDReturnValue = .failure(.failedRetrievingDirectRoom)
createDirectRoomWithExpectedRoomNameReturnValue = .failure(.failedCreatingRoom)
createRoomNameTopicIsRoomPrivateUserIDsAvatarURLReturnValue = .failure(.failedCreatingRoom)
uploadMediaReturnValue = .failure(.failedUploadingMedia(.unknown))
loadUserDisplayNameReturnValue = .failure(.failedRetrievingUserDisplayName)
setUserDisplayNameReturnValue = .failure(.failedSettingUserDisplayName)
loadUserAvatarURLReturnValue = .failure(.failedRetrievingUserAvatarURL)
setUserAvatarMediaReturnValue = .failure(.failedSettingUserAvatar)
removeUserAvatarReturnValue = .failure(.failedSettingUserAvatar)
logoutReturnValue = nil
searchUsersSearchTermLimitReturnValue = .success(.init(results: [], limited: false))
profileForReturnValue = .success(.init(userID: "@a:b.com", displayName: "Some user"))
sessionVerificationControllerProxyReturnValue = .failure(.failedRetrievingSessionVerificationController)
ignoreUserReturnValue = .failure(.failedIgnoringUser)
unignoreUserReturnValue = .failure(.failedUnignoringUser)
loadMediaContentForSourceThrowableError = ClientProxyError.failedLoadingMedia
loadMediaThumbnailForSourceWidthHeightThrowableError = ClientProxyError.failedLoadingMedia
loadMediaFileForSourceBodyThrowableError = ClientProxyError.failedLoadingMedia
secureBackupController = {
let secureBackupController = SecureBackupControllerMock()
secureBackupController.underlyingRecoveryState = .init(CurrentValueSubject<SecureBackupRecoveryState, Never>(.enabled))
secureBackupController.underlyingKeyBackupState = .init(CurrentValueSubject<SecureBackupKeyBackupState, Never>(.enabled))
return secureBackupController
}()
roomForIdentifierClosure = { [weak self] identifier in
guard let room = self?.roomSummaryProvider?.roomListPublisher.value.first(where: { $0.id == identifier }) else {
return nil
}
switch room {
case .empty:
return await RoomProxyMock(with: .init(name: "Empty room"))
case .filled(let details), .invalidated(let details):
return await RoomProxyMock(with: .init(name: details.name))
}
}
}
}
@@ -716,6 +716,534 @@ class BugReportServiceMock: BugReportServiceProtocol {
}
}
}
class ClientProxyMock: ClientProxyProtocol {
var actionsPublisher: AnyPublisher<ClientProxyAction, Never> {
get { return underlyingActionsPublisher }
set(value) { underlyingActionsPublisher = value }
}
var underlyingActionsPublisher: AnyPublisher<ClientProxyAction, Never>!
var loadingStatePublisher: CurrentValuePublisher<ClientProxyLoadingState, Never> {
get { return underlyingLoadingStatePublisher }
set(value) { underlyingLoadingStatePublisher = value }
}
var underlyingLoadingStatePublisher: CurrentValuePublisher<ClientProxyLoadingState, Never>!
var userID: String {
get { return underlyingUserID }
set(value) { underlyingUserID = value }
}
var underlyingUserID: String!
var deviceID: String?
var homeserver: String {
get { return underlyingHomeserver }
set(value) { underlyingHomeserver = value }
}
var underlyingHomeserver: String!
var userDisplayNamePublisher: CurrentValuePublisher<String?, Never> {
get { return underlyingUserDisplayNamePublisher }
set(value) { underlyingUserDisplayNamePublisher = value }
}
var underlyingUserDisplayNamePublisher: CurrentValuePublisher<String?, Never>!
var userAvatarURLPublisher: CurrentValuePublisher<URL?, Never> {
get { return underlyingUserAvatarURLPublisher }
set(value) { underlyingUserAvatarURLPublisher = value }
}
var underlyingUserAvatarURLPublisher: CurrentValuePublisher<URL?, Never>!
var ignoredUsersPublisher: CurrentValuePublisher<[String]?, Never> {
get { return underlyingIgnoredUsersPublisher }
set(value) { underlyingIgnoredUsersPublisher = value }
}
var underlyingIgnoredUsersPublisher: CurrentValuePublisher<[String]?, Never>!
var pusherNotificationClientIdentifier: String?
var roomSummaryProvider: RoomSummaryProviderProtocol?
var alternateRoomSummaryProvider: RoomSummaryProviderProtocol?
var inviteSummaryProvider: RoomSummaryProviderProtocol?
var notificationSettings: NotificationSettingsProxyProtocol {
get { return underlyingNotificationSettings }
set(value) { underlyingNotificationSettings = value }
}
var underlyingNotificationSettings: NotificationSettingsProxyProtocol!
var secureBackupController: SecureBackupControllerProtocol {
get { return underlyingSecureBackupController }
set(value) { underlyingSecureBackupController = value }
}
var underlyingSecureBackupController: SecureBackupControllerProtocol!
//MARK: - isOnlyDeviceLeft
var isOnlyDeviceLeftCallsCount = 0
var isOnlyDeviceLeftCalled: Bool {
return isOnlyDeviceLeftCallsCount > 0
}
var isOnlyDeviceLeftReturnValue: Result<Bool, ClientProxyError>!
var isOnlyDeviceLeftClosure: (() async -> Result<Bool, ClientProxyError>)?
func isOnlyDeviceLeft() async -> Result<Bool, ClientProxyError> {
isOnlyDeviceLeftCallsCount += 1
if let isOnlyDeviceLeftClosure = isOnlyDeviceLeftClosure {
return await isOnlyDeviceLeftClosure()
} else {
return isOnlyDeviceLeftReturnValue
}
}
//MARK: - startSync
var startSyncCallsCount = 0
var startSyncCalled: Bool {
return startSyncCallsCount > 0
}
var startSyncClosure: (() -> Void)?
func startSync() {
startSyncCallsCount += 1
startSyncClosure?()
}
//MARK: - stopSync
var stopSyncCallsCount = 0
var stopSyncCalled: Bool {
return stopSyncCallsCount > 0
}
var stopSyncClosure: (() -> Void)?
func stopSync() {
stopSyncCallsCount += 1
stopSyncClosure?()
}
//MARK: - accountURL
var accountURLActionCallsCount = 0
var accountURLActionCalled: Bool {
return accountURLActionCallsCount > 0
}
var accountURLActionReceivedAction: AccountManagementAction?
var accountURLActionReceivedInvocations: [AccountManagementAction] = []
var accountURLActionReturnValue: URL?
var accountURLActionClosure: ((AccountManagementAction) -> URL?)?
func accountURL(action: AccountManagementAction) -> URL? {
accountURLActionCallsCount += 1
accountURLActionReceivedAction = action
accountURLActionReceivedInvocations.append(action)
if let accountURLActionClosure = accountURLActionClosure {
return accountURLActionClosure(action)
} else {
return accountURLActionReturnValue
}
}
//MARK: - directRoomForUserID
var directRoomForUserIDCallsCount = 0
var directRoomForUserIDCalled: Bool {
return directRoomForUserIDCallsCount > 0
}
var directRoomForUserIDReceivedUserID: String?
var directRoomForUserIDReceivedInvocations: [String] = []
var directRoomForUserIDReturnValue: Result<String?, ClientProxyError>!
var directRoomForUserIDClosure: ((String) async -> Result<String?, ClientProxyError>)?
func directRoomForUserID(_ userID: String) async -> Result<String?, ClientProxyError> {
directRoomForUserIDCallsCount += 1
directRoomForUserIDReceivedUserID = userID
directRoomForUserIDReceivedInvocations.append(userID)
if let directRoomForUserIDClosure = directRoomForUserIDClosure {
return await directRoomForUserIDClosure(userID)
} else {
return directRoomForUserIDReturnValue
}
}
//MARK: - createDirectRoom
var createDirectRoomWithExpectedRoomNameCallsCount = 0
var createDirectRoomWithExpectedRoomNameCalled: Bool {
return createDirectRoomWithExpectedRoomNameCallsCount > 0
}
var createDirectRoomWithExpectedRoomNameReceivedArguments: (userID: String, expectedRoomName: String?)?
var createDirectRoomWithExpectedRoomNameReceivedInvocations: [(userID: String, expectedRoomName: String?)] = []
var createDirectRoomWithExpectedRoomNameReturnValue: Result<String, ClientProxyError>!
var createDirectRoomWithExpectedRoomNameClosure: ((String, String?) async -> Result<String, ClientProxyError>)?
func createDirectRoom(with userID: String, expectedRoomName: String?) async -> Result<String, ClientProxyError> {
createDirectRoomWithExpectedRoomNameCallsCount += 1
createDirectRoomWithExpectedRoomNameReceivedArguments = (userID: userID, expectedRoomName: expectedRoomName)
createDirectRoomWithExpectedRoomNameReceivedInvocations.append((userID: userID, expectedRoomName: expectedRoomName))
if let createDirectRoomWithExpectedRoomNameClosure = createDirectRoomWithExpectedRoomNameClosure {
return await createDirectRoomWithExpectedRoomNameClosure(userID, expectedRoomName)
} else {
return createDirectRoomWithExpectedRoomNameReturnValue
}
}
//MARK: - createRoom
var createRoomNameTopicIsRoomPrivateUserIDsAvatarURLCallsCount = 0
var createRoomNameTopicIsRoomPrivateUserIDsAvatarURLCalled: Bool {
return createRoomNameTopicIsRoomPrivateUserIDsAvatarURLCallsCount > 0
}
var createRoomNameTopicIsRoomPrivateUserIDsAvatarURLReceivedArguments: (name: String, topic: String?, isRoomPrivate: Bool, userIDs: [String], avatarURL: URL?)?
var createRoomNameTopicIsRoomPrivateUserIDsAvatarURLReceivedInvocations: [(name: String, topic: String?, isRoomPrivate: Bool, userIDs: [String], avatarURL: URL?)] = []
var createRoomNameTopicIsRoomPrivateUserIDsAvatarURLReturnValue: Result<String, ClientProxyError>!
var createRoomNameTopicIsRoomPrivateUserIDsAvatarURLClosure: ((String, String?, Bool, [String], URL?) async -> Result<String, ClientProxyError>)?
func createRoom(name: String, topic: String?, isRoomPrivate: Bool, userIDs: [String], avatarURL: URL?) async -> Result<String, ClientProxyError> {
createRoomNameTopicIsRoomPrivateUserIDsAvatarURLCallsCount += 1
createRoomNameTopicIsRoomPrivateUserIDsAvatarURLReceivedArguments = (name: name, topic: topic, isRoomPrivate: isRoomPrivate, userIDs: userIDs, avatarURL: avatarURL)
createRoomNameTopicIsRoomPrivateUserIDsAvatarURLReceivedInvocations.append((name: name, topic: topic, isRoomPrivate: isRoomPrivate, userIDs: userIDs, avatarURL: avatarURL))
if let createRoomNameTopicIsRoomPrivateUserIDsAvatarURLClosure = createRoomNameTopicIsRoomPrivateUserIDsAvatarURLClosure {
return await createRoomNameTopicIsRoomPrivateUserIDsAvatarURLClosure(name, topic, isRoomPrivate, userIDs, avatarURL)
} else {
return createRoomNameTopicIsRoomPrivateUserIDsAvatarURLReturnValue
}
}
//MARK: - uploadMedia
var uploadMediaCallsCount = 0
var uploadMediaCalled: Bool {
return uploadMediaCallsCount > 0
}
var uploadMediaReceivedMedia: MediaInfo?
var uploadMediaReceivedInvocations: [MediaInfo] = []
var uploadMediaReturnValue: Result<String, ClientProxyError>!
var uploadMediaClosure: ((MediaInfo) async -> Result<String, ClientProxyError>)?
func uploadMedia(_ media: MediaInfo) async -> Result<String, ClientProxyError> {
uploadMediaCallsCount += 1
uploadMediaReceivedMedia = media
uploadMediaReceivedInvocations.append(media)
if let uploadMediaClosure = uploadMediaClosure {
return await uploadMediaClosure(media)
} else {
return uploadMediaReturnValue
}
}
//MARK: - roomForIdentifier
var roomForIdentifierCallsCount = 0
var roomForIdentifierCalled: Bool {
return roomForIdentifierCallsCount > 0
}
var roomForIdentifierReceivedIdentifier: String?
var roomForIdentifierReceivedInvocations: [String] = []
var roomForIdentifierReturnValue: RoomProxyProtocol?
var roomForIdentifierClosure: ((String) async -> RoomProxyProtocol?)?
func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol? {
roomForIdentifierCallsCount += 1
roomForIdentifierReceivedIdentifier = identifier
roomForIdentifierReceivedInvocations.append(identifier)
if let roomForIdentifierClosure = roomForIdentifierClosure {
return await roomForIdentifierClosure(identifier)
} else {
return roomForIdentifierReturnValue
}
}
//MARK: - loadUserDisplayName
var loadUserDisplayNameCallsCount = 0
var loadUserDisplayNameCalled: Bool {
return loadUserDisplayNameCallsCount > 0
}
var loadUserDisplayNameReturnValue: Result<Void, ClientProxyError>!
var loadUserDisplayNameClosure: (() async -> Result<Void, ClientProxyError>)?
@discardableResult
func loadUserDisplayName() async -> Result<Void, ClientProxyError> {
loadUserDisplayNameCallsCount += 1
if let loadUserDisplayNameClosure = loadUserDisplayNameClosure {
return await loadUserDisplayNameClosure()
} else {
return loadUserDisplayNameReturnValue
}
}
//MARK: - setUserDisplayName
var setUserDisplayNameCallsCount = 0
var setUserDisplayNameCalled: Bool {
return setUserDisplayNameCallsCount > 0
}
var setUserDisplayNameReceivedName: String?
var setUserDisplayNameReceivedInvocations: [String] = []
var setUserDisplayNameReturnValue: Result<Void, ClientProxyError>!
var setUserDisplayNameClosure: ((String) async -> Result<Void, ClientProxyError>)?
func setUserDisplayName(_ name: String) async -> Result<Void, ClientProxyError> {
setUserDisplayNameCallsCount += 1
setUserDisplayNameReceivedName = name
setUserDisplayNameReceivedInvocations.append(name)
if let setUserDisplayNameClosure = setUserDisplayNameClosure {
return await setUserDisplayNameClosure(name)
} else {
return setUserDisplayNameReturnValue
}
}
//MARK: - loadUserAvatarURL
var loadUserAvatarURLCallsCount = 0
var loadUserAvatarURLCalled: Bool {
return loadUserAvatarURLCallsCount > 0
}
var loadUserAvatarURLReturnValue: Result<Void, ClientProxyError>!
var loadUserAvatarURLClosure: (() async -> Result<Void, ClientProxyError>)?
@discardableResult
func loadUserAvatarURL() async -> Result<Void, ClientProxyError> {
loadUserAvatarURLCallsCount += 1
if let loadUserAvatarURLClosure = loadUserAvatarURLClosure {
return await loadUserAvatarURLClosure()
} else {
return loadUserAvatarURLReturnValue
}
}
//MARK: - setUserAvatar
var setUserAvatarMediaCallsCount = 0
var setUserAvatarMediaCalled: Bool {
return setUserAvatarMediaCallsCount > 0
}
var setUserAvatarMediaReceivedMedia: MediaInfo?
var setUserAvatarMediaReceivedInvocations: [MediaInfo] = []
var setUserAvatarMediaReturnValue: Result<Void, ClientProxyError>!
var setUserAvatarMediaClosure: ((MediaInfo) async -> Result<Void, ClientProxyError>)?
func setUserAvatar(media: MediaInfo) async -> Result<Void, ClientProxyError> {
setUserAvatarMediaCallsCount += 1
setUserAvatarMediaReceivedMedia = media
setUserAvatarMediaReceivedInvocations.append(media)
if let setUserAvatarMediaClosure = setUserAvatarMediaClosure {
return await setUserAvatarMediaClosure(media)
} else {
return setUserAvatarMediaReturnValue
}
}
//MARK: - removeUserAvatar
var removeUserAvatarCallsCount = 0
var removeUserAvatarCalled: Bool {
return removeUserAvatarCallsCount > 0
}
var removeUserAvatarReturnValue: Result<Void, ClientProxyError>!
var removeUserAvatarClosure: (() async -> Result<Void, ClientProxyError>)?
func removeUserAvatar() async -> Result<Void, ClientProxyError> {
removeUserAvatarCallsCount += 1
if let removeUserAvatarClosure = removeUserAvatarClosure {
return await removeUserAvatarClosure()
} else {
return removeUserAvatarReturnValue
}
}
//MARK: - sessionVerificationControllerProxy
var sessionVerificationControllerProxyCallsCount = 0
var sessionVerificationControllerProxyCalled: Bool {
return sessionVerificationControllerProxyCallsCount > 0
}
var sessionVerificationControllerProxyReturnValue: Result<SessionVerificationControllerProxyProtocol, ClientProxyError>!
var sessionVerificationControllerProxyClosure: (() async -> Result<SessionVerificationControllerProxyProtocol, ClientProxyError>)?
func sessionVerificationControllerProxy() async -> Result<SessionVerificationControllerProxyProtocol, ClientProxyError> {
sessionVerificationControllerProxyCallsCount += 1
if let sessionVerificationControllerProxyClosure = sessionVerificationControllerProxyClosure {
return await sessionVerificationControllerProxyClosure()
} else {
return sessionVerificationControllerProxyReturnValue
}
}
//MARK: - logout
var logoutCallsCount = 0
var logoutCalled: Bool {
return logoutCallsCount > 0
}
var logoutReturnValue: URL?
var logoutClosure: (() async -> URL?)?
func logout() async -> URL? {
logoutCallsCount += 1
if let logoutClosure = logoutClosure {
return await logoutClosure()
} else {
return logoutReturnValue
}
}
//MARK: - setPusher
var setPusherWithThrowableError: Error?
var setPusherWithCallsCount = 0
var setPusherWithCalled: Bool {
return setPusherWithCallsCount > 0
}
var setPusherWithReceivedConfiguration: PusherConfiguration?
var setPusherWithReceivedInvocations: [PusherConfiguration] = []
var setPusherWithClosure: ((PusherConfiguration) async throws -> Void)?
func setPusher(with configuration: PusherConfiguration) async throws {
if let error = setPusherWithThrowableError {
throw error
}
setPusherWithCallsCount += 1
setPusherWithReceivedConfiguration = configuration
setPusherWithReceivedInvocations.append(configuration)
try await setPusherWithClosure?(configuration)
}
//MARK: - searchUsers
var searchUsersSearchTermLimitCallsCount = 0
var searchUsersSearchTermLimitCalled: Bool {
return searchUsersSearchTermLimitCallsCount > 0
}
var searchUsersSearchTermLimitReceivedArguments: (searchTerm: String, limit: UInt)?
var searchUsersSearchTermLimitReceivedInvocations: [(searchTerm: String, limit: UInt)] = []
var searchUsersSearchTermLimitReturnValue: Result<SearchUsersResultsProxy, ClientProxyError>!
var searchUsersSearchTermLimitClosure: ((String, UInt) async -> Result<SearchUsersResultsProxy, ClientProxyError>)?
func searchUsers(searchTerm: String, limit: UInt) async -> Result<SearchUsersResultsProxy, ClientProxyError> {
searchUsersSearchTermLimitCallsCount += 1
searchUsersSearchTermLimitReceivedArguments = (searchTerm: searchTerm, limit: limit)
searchUsersSearchTermLimitReceivedInvocations.append((searchTerm: searchTerm, limit: limit))
if let searchUsersSearchTermLimitClosure = searchUsersSearchTermLimitClosure {
return await searchUsersSearchTermLimitClosure(searchTerm, limit)
} else {
return searchUsersSearchTermLimitReturnValue
}
}
//MARK: - profile
var profileForCallsCount = 0
var profileForCalled: Bool {
return profileForCallsCount > 0
}
var profileForReceivedUserID: String?
var profileForReceivedInvocations: [String] = []
var profileForReturnValue: Result<UserProfileProxy, ClientProxyError>!
var profileForClosure: ((String) async -> Result<UserProfileProxy, ClientProxyError>)?
func profile(for userID: String) async -> Result<UserProfileProxy, ClientProxyError> {
profileForCallsCount += 1
profileForReceivedUserID = userID
profileForReceivedInvocations.append(userID)
if let profileForClosure = profileForClosure {
return await profileForClosure(userID)
} else {
return profileForReturnValue
}
}
//MARK: - ignoreUser
var ignoreUserCallsCount = 0
var ignoreUserCalled: Bool {
return ignoreUserCallsCount > 0
}
var ignoreUserReceivedUserID: String?
var ignoreUserReceivedInvocations: [String] = []
var ignoreUserReturnValue: Result<Void, ClientProxyError>!
var ignoreUserClosure: ((String) async -> Result<Void, ClientProxyError>)?
func ignoreUser(_ userID: String) async -> Result<Void, ClientProxyError> {
ignoreUserCallsCount += 1
ignoreUserReceivedUserID = userID
ignoreUserReceivedInvocations.append(userID)
if let ignoreUserClosure = ignoreUserClosure {
return await ignoreUserClosure(userID)
} else {
return ignoreUserReturnValue
}
}
//MARK: - unignoreUser
var unignoreUserCallsCount = 0
var unignoreUserCalled: Bool {
return unignoreUserCallsCount > 0
}
var unignoreUserReceivedUserID: String?
var unignoreUserReceivedInvocations: [String] = []
var unignoreUserReturnValue: Result<Void, ClientProxyError>!
var unignoreUserClosure: ((String) async -> Result<Void, ClientProxyError>)?
func unignoreUser(_ userID: String) async -> Result<Void, ClientProxyError> {
unignoreUserCallsCount += 1
unignoreUserReceivedUserID = userID
unignoreUserReceivedInvocations.append(userID)
if let unignoreUserClosure = unignoreUserClosure {
return await unignoreUserClosure(userID)
} else {
return unignoreUserReturnValue
}
}
//MARK: - loadMediaContentForSource
var loadMediaContentForSourceThrowableError: Error?
var loadMediaContentForSourceCallsCount = 0
var loadMediaContentForSourceCalled: Bool {
return loadMediaContentForSourceCallsCount > 0
}
var loadMediaContentForSourceReceivedSource: MediaSourceProxy?
var loadMediaContentForSourceReceivedInvocations: [MediaSourceProxy] = []
var loadMediaContentForSourceReturnValue: Data!
var loadMediaContentForSourceClosure: ((MediaSourceProxy) async throws -> Data)?
func loadMediaContentForSource(_ source: MediaSourceProxy) async throws -> Data {
if let error = loadMediaContentForSourceThrowableError {
throw error
}
loadMediaContentForSourceCallsCount += 1
loadMediaContentForSourceReceivedSource = source
loadMediaContentForSourceReceivedInvocations.append(source)
if let loadMediaContentForSourceClosure = loadMediaContentForSourceClosure {
return try await loadMediaContentForSourceClosure(source)
} else {
return loadMediaContentForSourceReturnValue
}
}
//MARK: - loadMediaThumbnailForSource
var loadMediaThumbnailForSourceWidthHeightThrowableError: Error?
var loadMediaThumbnailForSourceWidthHeightCallsCount = 0
var loadMediaThumbnailForSourceWidthHeightCalled: Bool {
return loadMediaThumbnailForSourceWidthHeightCallsCount > 0
}
var loadMediaThumbnailForSourceWidthHeightReceivedArguments: (source: MediaSourceProxy, width: UInt, height: UInt)?
var loadMediaThumbnailForSourceWidthHeightReceivedInvocations: [(source: MediaSourceProxy, width: UInt, height: UInt)] = []
var loadMediaThumbnailForSourceWidthHeightReturnValue: Data!
var loadMediaThumbnailForSourceWidthHeightClosure: ((MediaSourceProxy, UInt, UInt) async throws -> Data)?
func loadMediaThumbnailForSource(_ source: MediaSourceProxy, width: UInt, height: UInt) async throws -> Data {
if let error = loadMediaThumbnailForSourceWidthHeightThrowableError {
throw error
}
loadMediaThumbnailForSourceWidthHeightCallsCount += 1
loadMediaThumbnailForSourceWidthHeightReceivedArguments = (source: source, width: width, height: height)
loadMediaThumbnailForSourceWidthHeightReceivedInvocations.append((source: source, width: width, height: height))
if let loadMediaThumbnailForSourceWidthHeightClosure = loadMediaThumbnailForSourceWidthHeightClosure {
return try await loadMediaThumbnailForSourceWidthHeightClosure(source, width, height)
} else {
return loadMediaThumbnailForSourceWidthHeightReturnValue
}
}
//MARK: - loadMediaFileForSource
var loadMediaFileForSourceBodyThrowableError: Error?
var loadMediaFileForSourceBodyCallsCount = 0
var loadMediaFileForSourceBodyCalled: Bool {
return loadMediaFileForSourceBodyCallsCount > 0
}
var loadMediaFileForSourceBodyReceivedArguments: (source: MediaSourceProxy, body: String?)?
var loadMediaFileForSourceBodyReceivedInvocations: [(source: MediaSourceProxy, body: String?)] = []
var loadMediaFileForSourceBodyReturnValue: MediaFileHandleProxy!
var loadMediaFileForSourceBodyClosure: ((MediaSourceProxy, String?) async throws -> MediaFileHandleProxy)?
func loadMediaFileForSource(_ source: MediaSourceProxy, body: String?) async throws -> MediaFileHandleProxy {
if let error = loadMediaFileForSourceBodyThrowableError {
throw error
}
loadMediaFileForSourceBodyCallsCount += 1
loadMediaFileForSourceBodyReceivedArguments = (source: source, body: body)
loadMediaFileForSourceBodyReceivedInvocations.append((source: source, body: body))
if let loadMediaFileForSourceBodyClosure = loadMediaFileForSourceBodyClosure {
return try await loadMediaFileForSourceBodyClosure(source, body)
} else {
return loadMediaFileForSourceBodyReturnValue
}
}
}
class CompletionSuggestionServiceMock: CompletionSuggestionServiceProtocol {
var suggestionsPublisher: AnyPublisher<[SuggestionItem], Never> {
get { return underlyingSuggestionsPublisher }
@@ -76,7 +76,7 @@ extension View {
}
struct ShimmerOverlay_Previews: PreviewProvider, TestablePreview {
static let viewModel = HomeScreenViewModel(userSession: MockUserSession(clientProxy: MockClientProxy(userID: ""),
static let viewModel = HomeScreenViewModel(userSession: MockUserSession(clientProxy: ClientProxyMock(.init(userID: "")),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock()),
analyticsService: ServiceLocator.shared.analytics,
@@ -74,7 +74,7 @@ struct WaitlistScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = WaitlistScreenViewModel(homeserver: .mockMatrixDotOrg)
static let successViewModel = {
let viewModel = WaitlistScreenViewModel(homeserver: .mockMatrixDotOrg)
viewModel.update(userSession: MockUserSession(clientProxy: MockClientProxy(userID: "@alice:matrix.org"),
viewModel.update(userSession: MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@alice:matrix.org")),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock()))
return viewModel
@@ -62,7 +62,7 @@ struct BlockedUsersScreen: View {
// MARK: - Previews
struct BlockedUsersScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = BlockedUsersScreenViewModel(clientProxy: MockClientProxy(userID: RoomMemberProxyMock.mockMe.userID),
static let viewModel = BlockedUsersScreenViewModel(clientProxy: ClientProxyMock(.init(userID: RoomMemberProxyMock.mockMe.userID)),
userIndicatorController: UserIndicatorControllerMock())
static var previews: some View {
@@ -175,7 +175,7 @@ struct CreateRoomScreen: View {
struct CreateRoom_Previews: PreviewProvider, TestablePreview {
static let viewModel = {
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "@userid:example.com"),
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@userid:example.com")),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
let parameters = CreateRoomFlowParameters()
@@ -189,7 +189,7 @@ struct CreateRoom_Previews: PreviewProvider, TestablePreview {
}()
static let emtpyViewModel = {
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "@userid:example.com"),
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@userid:example.com")),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
let parameters = CreateRoomFlowParameters()
@@ -242,8 +242,8 @@ struct HomeScreen_Previews: PreviewProvider, TestablePreview {
.loaded(.mockRooms)
}
let clientProxy = MockClientProxy(userID: userID,
roomSummaryProvider: MockRoomSummaryProvider(state: roomSummaryProviderState))
let clientProxy = ClientProxyMock(.init(userID: userID,
roomSummaryProvider: MockRoomSummaryProvider(state: roomSummaryProviderState)))
let userSession = MockUserSession(clientProxy: clientProxy,
mediaProvider: MockMediaProvider(),
@@ -149,8 +149,8 @@ struct HomeScreenEmptyStateView_Previews: PreviewProvider, TestablePreview {
}
static let viewModel = {
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "@user:example.com",
roomSummaryProvider: MockRoomSummaryProvider(state: .loaded([]))),
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@user:example.com",
roomSummaryProvider: MockRoomSummaryProvider(state: .loaded([])))),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
@@ -65,8 +65,8 @@ struct HomeScreenRecoveryKeyConfirmationBanner_Previews: PreviewProvider, Testab
}
static func buildViewModel() -> HomeScreenViewModel {
let clientProxy = MockClientProxy(userID: "@alice:example.com",
roomSummaryProvider: MockRoomSummaryProvider(state: .loading))
let clientProxy = ClientProxyMock(.init(userID: "@alice:example.com",
roomSummaryProvider: MockRoomSummaryProvider(state: .loading)))
let userSession = MockUserSession(clientProxy: clientProxy,
mediaProvider: MockMediaProvider(),
@@ -176,10 +176,10 @@ private extension View {
struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview {
static let summaryProviderGeneric = MockRoomSummaryProvider(state: .loaded(.mockRooms))
static let viewModelGeneric = {
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "John Doe", roomSummaryProvider: summaryProviderGeneric),
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "John Doe", roomSummaryProvider: summaryProviderGeneric)),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
return HomeScreenViewModel(userSession: userSession,
analyticsService: ServiceLocator.shared.analytics,
appSettings: ServiceLocator.shared.settings,
@@ -189,7 +189,7 @@ struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview {
static let summaryProviderForNotificationsState = MockRoomSummaryProvider(state: .loaded(.mockRoomsWithNotificationsState))
static let viewModelForNotificationsState = {
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "John Doe", roomSummaryProvider: summaryProviderForNotificationsState),
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "John Doe", roomSummaryProvider: summaryProviderForNotificationsState)),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
@@ -65,8 +65,8 @@ struct HomeScreenSessionVerificationBanner_Previews: PreviewProvider, TestablePr
}
static func buildViewModel() -> HomeScreenViewModel {
let clientProxy = MockClientProxy(userID: "@alice:example.com",
roomSummaryProvider: MockRoomSummaryProvider(state: .loading))
let clientProxy = ClientProxyMock(.init(userID: "@alice:example.com",
roomSummaryProvider: MockRoomSummaryProvider(state: .loading)))
let userSession = MockUserSession(clientProxy: clientProxy,
mediaProvider: MockMediaProvider(),
@@ -80,7 +80,7 @@ struct InvitesScreen_Previews: PreviewProvider, TestablePreview {
private extension InvitesScreenViewModel {
static let noInvites: InvitesScreenViewModel = {
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "@userid:example.com"),
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@userid:example.com")),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
let regularViewModel = InvitesScreenViewModel(userSession: userSession,
@@ -91,7 +91,7 @@ private extension InvitesScreenViewModel {
}()
static let someInvite: InvitesScreenViewModel = {
let clientProxy = MockClientProxy(userID: "@userid:example.com")
let clientProxy = ClientProxyMock(.init(userID: "@userid:example.com"))
clientProxy.inviteSummaryProvider = MockRoomSummaryProvider(state: .loaded(.mockInvites))
clientProxy.roomSummaryProvider = MockRoomSummaryProvider(state: .loaded(.mockInvites))
let userSession = MockUserSession(clientProxy: clientProxy,
@@ -73,8 +73,8 @@ struct NotificationSettingsEditScreen_Previews: PreviewProvider, TestablePreview
notificationSettingsProxy.getDefaultRoomNotificationModeIsEncryptedIsOneToOneReturnValue = .allMessages
notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = [RoomSummary].mockRooms.compactMap(\.id)
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "@alice:example.com",
roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms))),
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@alice:example.com",
roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms)))),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
var viewModel = NotificationSettingsEditScreenViewModel(chatType: .groupChat,
@@ -88,8 +88,8 @@ struct NotificationSettingsEditScreen_Previews: PreviewProvider, TestablePreview
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init())
notificationSettingsProxy.getDefaultRoomNotificationModeIsEncryptedIsOneToOneReturnValue = .mentionsAndKeywordsOnly
notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = []
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "@alice:example.com",
roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms))),
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@alice:example.com",
roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms)))),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
var viewModel = NotificationSettingsEditScreenViewModel(chatType: .oneToOneChat,
@@ -103,8 +103,10 @@ struct NotificationSettingsEditScreen_Previews: PreviewProvider, TestablePreview
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init())
notificationSettingsProxy.getDefaultRoomNotificationModeIsEncryptedIsOneToOneReturnValue = .mentionsAndKeywordsOnly
notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = []
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "John Doe"), mediaProvider: MockMediaProvider(), voiceMessageMediaManager: VoiceMessageMediaManagerMock())
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "John Doe")),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
var viewModel = NotificationSettingsEditScreenViewModel(chatType: .oneToOneChat,
userSession: userSession,
notificationSettingsProxy: notificationSettingsProxy)
@@ -118,8 +120,8 @@ struct NotificationSettingsEditScreen_Previews: PreviewProvider, TestablePreview
notificationSettingsProxy.getDefaultRoomNotificationModeIsEncryptedIsOneToOneReturnValue = .allMessages
notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = [RoomSummary].mockRooms.compactMap(\.id)
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "@alice:example.com",
roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms))),
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@alice:example.com",
roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms)))),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
var viewModel = NotificationSettingsEditScreenViewModel(chatType: .groupChat,
@@ -61,7 +61,7 @@ struct NotificationSettingsEditScreenRoomCell_Previews: PreviewProvider, Testabl
static var previews: some View {
let summaryProvider = MockRoomSummaryProvider(state: .loaded(.mockRooms))
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "John Doe", roomSummaryProvider: summaryProvider),
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "John Doe", roomSummaryProvider: summaryProvider)),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
@@ -222,7 +222,8 @@ struct NotificationSettingsScreen_Previews: PreviewProvider, TestablePreview {
notificationSettingsProxy.isRoomMentionEnabledReturnValue = true
notificationSettingsProxy.isCallEnabledReturnValue = false
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "John Doe"), mediaProvider: MockMediaProvider(),
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "John Doe")),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
var viewModel = NotificationSettingsScreenViewModel(appSettings: appSettings,
@@ -251,7 +252,9 @@ struct NotificationSettingsScreen_Previews: PreviewProvider, TestablePreview {
notificationSettingsProxy.isRoomMentionEnabledReturnValue = true
notificationSettingsProxy.isCallEnabledReturnValue = false
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "John Doe"), mediaProvider: MockMediaProvider(), voiceMessageMediaManager: VoiceMessageMediaManagerMock())
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "John Doe")),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
var viewModel = NotificationSettingsScreenViewModel(appSettings: appSettings,
userNotificationCenter: notificationCenter,
@@ -244,8 +244,8 @@ struct SettingsScreen_Previews: PreviewProvider, TestablePreview {
let verificationController = SessionVerificationControllerProxyMock()
verificationController.isVerifiedReturnValue = .success(false)
let userSession = MockUserSession(sessionVerificationController: verificationController,
clientProxy: MockClientProxy(userID: "@userid:example.com",
deviceID: "AAAAAAAAAAA"),
clientProxy: ClientProxyMock(.init(userID: "@userid:example.com",
deviceID: "AAAAAAAAAAA")),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
return SettingsScreenViewModel(userSession: userSession,
@@ -124,7 +124,7 @@ struct UserDetailsEditScreen: View {
// MARK: - Previews
struct UserDetailsEditScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = UserDetailsEditScreenViewModel(clientProxy: MockClientProxy(userID: "@stefan:matrix.org"),
static let viewModel = UserDetailsEditScreenViewModel(clientProxy: ClientProxyMock(.init(userID: "@stefan:matrix.org")),
mediaProvider: MockMediaProvider(),
userIndicatorController: UserIndicatorControllerMock.default)
@@ -129,7 +129,7 @@ struct StartChatScreen: View {
struct StartChatScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = {
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "@userid:example.com"),
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@userid:example.com")),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
let userDiscoveryService = UserDiscoveryServiceMock()
@@ -62,7 +62,7 @@ class MockAuthenticationServiceProxy: AuthenticationServiceProxyProtocol {
return .failure(.invalidCredentials)
}
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: username),
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: username)),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
return .success(userSession)
@@ -71,6 +71,7 @@ struct PusherConfiguration {
let lang: String
}
// sourcery: AutoMockable
protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
var actionsPublisher: AnyPublisher<ClientProxyAction, Never> { get }
@@ -1,185 +0,0 @@
//
// Copyright 2022 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 Combine
import Foundation
import MatrixRustSDK
class MockClientProxy: ClientProxyProtocol {
let actionsSubject = PassthroughSubject<ClientProxyAction, Never>()
var actionsPublisher: AnyPublisher<ClientProxyAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
let loadingStatePublisher = CurrentValuePublisher<ClientProxyLoadingState, Never>(.notLoading)
let userID: String
let deviceID: String?
let homeserver = ""
let pusherNotificationClientIdentifier: String? = nil
var roomSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider()
var alternateRoomSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider()
var inviteSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider()
var userAvatarURLPublisher: CurrentValuePublisher<URL?, Never> { CurrentValueSubject<URL?, Never>(nil).asCurrentValuePublisher() }
var userDisplayNamePublisher: CurrentValuePublisher<String?, Never> { CurrentValueSubject<String?, Never>("User display name").asCurrentValuePublisher() }
var ignoredUsersPublisher: CurrentValuePublisher<[String]?, Never> {
let ignoredUsers = [RoomMemberProxyMock].allMembers.map(\.userID)
return CurrentValueSubject<[String]?, Never>(ignoredUsers).asCurrentValuePublisher()
}
var notificationSettings: NotificationSettingsProxyProtocol = NotificationSettingsProxyMock(with: .init())
lazy var secureBackupController: SecureBackupControllerProtocol = {
let secureBackupController = SecureBackupControllerMock()
secureBackupController.underlyingRecoveryState = .init(CurrentValueSubject<SecureBackupRecoveryState, Never>(.enabled))
secureBackupController.underlyingKeyBackupState = .init(CurrentValueSubject<SecureBackupKeyBackupState, Never>(.enabled))
return secureBackupController
}()
init(userID: String, deviceID: String? = nil, roomSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider()) {
self.userID = userID
self.deviceID = deviceID
self.roomSummaryProvider = roomSummaryProvider
}
func isOnlyDeviceLeft() async -> Result<Bool, ClientProxyError> {
.success(false)
}
func startSync() { }
func stopSync() { }
func accountURL(action: AccountManagementAction) -> URL? {
"https://matrix.org/account"
}
func directRoomForUserID(_ userID: String) async -> Result<String?, ClientProxyError> {
.failure(.failedRetrievingDirectRoom)
}
func createDirectRoom(with userID: String, expectedRoomName: String?) async -> Result<String, ClientProxyError> {
.failure(.failedCreatingRoom)
}
func createRoom(name: String, topic: String?, isRoomPrivate: Bool, userIDs: [String], avatarURL: URL?) async -> Result<String, ClientProxyError> {
.failure(.failedCreatingRoom)
}
func uploadMedia(_ media: MediaInfo) async -> Result<String, ClientProxyError> {
.failure(.failedUploadingMedia(.unknown))
}
var roomForIdentifierMocks: [String: RoomProxyMock] = .init()
@MainActor
func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol? {
guard roomForIdentifierMocks[identifier] == nil else {
return roomForIdentifierMocks[identifier]
}
guard let room = roomSummaryProvider?.roomListPublisher.value.first(where: { $0.id == identifier }) else {
return nil
}
switch room {
case .empty:
return RoomProxyMock(with: .init(name: "Empty room"))
case .filled(let details), .invalidated(let details):
return RoomProxyMock(with: .init(name: details.name))
}
}
func loadUserDisplayName() async -> Result<Void, ClientProxyError> {
.failure(.failedRetrievingUserDisplayName)
}
func setUserDisplayName(_ name: String) async -> Result<Void, ClientProxyError> {
.failure(.failedSettingUserDisplayName)
}
func loadUserAvatarURL() async -> Result<Void, ClientProxyError> {
.failure(.failedRetrievingUserAvatarURL)
}
func setUserAvatar(media: MediaInfo) async -> Result<Void, ClientProxyError> {
.failure(.failedSettingUserAvatar)
}
func removeUserAvatar() async -> Result<Void, ClientProxyError> {
.failure(.failedSettingUserAvatar)
}
func loadMediaContentForSource(_ source: MediaSourceProxy) async throws -> Data {
throw ClientProxyError.failedLoadingMedia
}
func loadMediaThumbnailForSource(_ source: MediaSourceProxy, width: UInt, height: UInt) async throws -> Data {
throw ClientProxyError.failedLoadingMedia
}
func loadMediaFileForSource(_ source: MediaSourceProxy, body: String?) async throws -> MediaFileHandleProxy {
throw ClientProxyError.failedLoadingMedia
}
var sessionVerificationControllerProxyResult: Result<SessionVerificationControllerProxyProtocol, ClientProxyError>?
func sessionVerificationControllerProxy() async -> Result<SessionVerificationControllerProxyProtocol, ClientProxyError> {
if let sessionVerificationControllerProxyResult {
return sessionVerificationControllerProxyResult
} else {
return .failure(.failedRetrievingSessionVerificationController)
}
}
func logout() async -> URL? {
nil
}
var setPusherErrorToThrow: Error?
var setPusherArgument: PusherConfiguration?
var setPusherCalled = false
func setPusher(with configuration: PusherConfiguration) async throws {
if let setPusherErrorToThrow { throw setPusherErrorToThrow }
setPusherCalled = true
setPusherArgument = configuration
}
var searchUsersResult: Result<SearchUsersResultsProxy, ClientProxyError> = .success(.init(results: [], limited: false))
func searchUsers(searchTerm: String, limit: UInt) async -> Result<SearchUsersResultsProxy, ClientProxyError> {
searchUsersResult
}
var getProfileResult: Result<UserProfileProxy, ClientProxyError> = .success(.init(userID: "@a:b.com", displayName: "Some user"))
private(set) var getProfileCalled = false
func profile(for userID: String) async -> Result<UserProfileProxy, ClientProxyError> {
getProfileCalled = true
return getProfileResult
}
func ignoreUser(_ userID: String) async -> Result<Void, ClientProxyError> {
.failure(.failedIgnoringUser)
}
func unignoreUser(_ userID: String) async -> Result<Void, ClientProxyError> {
.failure(.failedUnignoringUser)
}
}
@@ -261,7 +261,7 @@ class MockScreen: Identifiable {
ServiceLocator.shared.settings.migratedAccounts[userID] = true
let navigationStackCoordinator = NavigationStackCoordinator()
let session = MockUserSession(clientProxy: MockClientProxy(userID: userID),
let session = MockUserSession(clientProxy: ClientProxyMock(.init(userID: userID)),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
let coordinator = HomeScreenCoordinator(parameters: .init(userSession: session,
@@ -273,7 +273,7 @@ class MockScreen: Identifiable {
return navigationStackCoordinator
case .settings:
let navigationStackCoordinator = NavigationStackCoordinator()
let clientProxy = MockClientProxy(userID: "@mock:client.com")
let clientProxy = ClientProxyMock(.init(userID: "@mock:client.com"))
let coordinator = SettingsScreenCoordinator(parameters: .init(userSession: MockUserSession(clientProxy: clientProxy,
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock()),
@@ -303,7 +303,7 @@ class MockScreen: Identifiable {
case .notificationSettingsScreen:
let userNotificationCenter = UserNotificationCenterMock()
userNotificationCenter.authorizationStatusReturnValue = .denied
let session = MockUserSession(clientProxy: MockClientProxy(userID: "@mock:matrix.org"),
let session = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@mock:matrix.org")),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
let parameters = NotificationSettingsScreenCoordinatorParameters(userSession: session,
@@ -314,7 +314,7 @@ class MockScreen: Identifiable {
case .notificationSettingsScreenMismatchConfiguration:
let userNotificationCenter = UserNotificationCenterMock()
userNotificationCenter.authorizationStatusReturnValue = .denied
let session = MockUserSession(clientProxy: MockClientProxy(userID: "@mock:matrix.org"),
let session = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@mock:matrix.org")),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
let notificationSettings = NotificationSettingsProxyMock(with: .init())
@@ -560,7 +560,7 @@ class MockScreen: Identifiable {
appSettings.richTextEditorEnabled = id == .userSessionScreenRTE
let navigationSplitCoordinator = NavigationSplitCoordinator(placeholderCoordinator: PlaceholderScreenCoordinator())
let clientProxy = MockClientProxy(userID: "@mock:client.com", roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms)))
let clientProxy = ClientProxyMock(.init(userID: "@mock:client.com", roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms))))
ServiceLocator.shared.settings.migratedAccounts[clientProxy.userID] = true
ServiceLocator.shared.settings.hasShownWelcomeScreen = true
@@ -743,7 +743,9 @@ class MockScreen: Identifiable {
let userDiscoveryMock = UserDiscoveryServiceMock()
userDiscoveryMock.fetchSuggestionsReturnValue = .success([.mockAlice, .mockBob, .mockCharlie])
userDiscoveryMock.searchProfilesWithReturnValue = .success([])
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "@mock:client.com"), mediaProvider: MockMediaProvider(), voiceMessageMediaManager: VoiceMessageMediaManagerMock())
let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@mock:client.com")),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
let parameters: StartChatScreenCoordinatorParameters = .init(orientationManager: OrientationManagerMock(),
userSession: userSession,
userIndicatorController: UserIndicatorControllerMock(),
@@ -754,7 +756,7 @@ class MockScreen: Identifiable {
return navigationStackCoordinator
case .startChatWithSearchResults:
let navigationStackCoordinator = NavigationStackCoordinator()
let clientProxy = MockClientProxy(userID: "@mock:client.com")
let clientProxy = ClientProxyMock(.init(userID: "@mock:client.com"))
let userDiscoveryMock = UserDiscoveryServiceMock()
userDiscoveryMock.fetchSuggestionsReturnValue = .success([])
userDiscoveryMock.searchProfilesWithReturnValue = .success([.mockBob, .mockBobby])
@@ -805,9 +807,19 @@ class MockScreen: Identifiable {
case .invitesWithBadges:
ServiceLocator.shared.settings.seenInvites = Set([RoomSummary].mockInvites.dropFirst(1).compactMap(\.id))
let navigationStackCoordinator = NavigationStackCoordinator()
let clientProxy = MockClientProxy(userID: "@mock:client.com")
clientProxy.roomForIdentifierMocks["someAwesomeRoomId1"] = .init(with: .init(name: "First room"))
clientProxy.roomForIdentifierMocks["someAwesomeRoomId2"] = .init(with: .init(name: "Second room"))
let clientProxy = ClientProxyMock(.init(userID: "@mock:client.com"))
clientProxy.roomForIdentifierClosure = { identifier in
switch identifier {
case "someAwesomeRoomId1":
return RoomProxyMock(with: .init(name: "First room"))
case "someAwesomeRoomId2":
return RoomProxyMock(with: .init(name: "Second room"))
default:
return nil
}
}
let summaryProvider = MockRoomSummaryProvider(state: .loaded(.mockInvites))
clientProxy.inviteSummaryProvider = summaryProvider
@@ -817,9 +829,19 @@ class MockScreen: Identifiable {
case .invites:
ServiceLocator.shared.settings.seenInvites = Set([RoomSummary].mockInvites.compactMap(\.id))
let navigationStackCoordinator = NavigationStackCoordinator()
let clientProxy = MockClientProxy(userID: "@mock:client.com")
clientProxy.roomForIdentifierMocks["someAwesomeRoomId1"] = .init(with: .init(name: "First room"))
clientProxy.roomForIdentifierMocks["someAwesomeRoomId2"] = .init(with: .init(name: "Second room"))
let clientProxy = ClientProxyMock(.init(userID: "@mock:client.com"))
clientProxy.roomForIdentifierClosure = { identifier in
switch identifier {
case "someAwesomeRoomId1":
return RoomProxyMock(with: .init(name: "First room"))
case "someAwesomeRoomId2":
return RoomProxyMock(with: .init(name: "Second room"))
default:
return nil
}
}
let summaryProvider = MockRoomSummaryProvider(state: .loaded(.mockInvites))
clientProxy.inviteSummaryProvider = summaryProvider
@@ -828,7 +850,7 @@ class MockScreen: Identifiable {
return navigationStackCoordinator
case .invitesNoInvites:
let navigationStackCoordinator = NavigationStackCoordinator()
let clientProxy = MockClientProxy(userID: "@mock:client.com")
let clientProxy = ClientProxyMock(.init(userID: "@mock:client.com"))
let coordinator = InvitesScreenCoordinator(parameters: .init(userSession: MockUserSession(clientProxy: clientProxy, mediaProvider: MockMediaProvider(), voiceMessageMediaManager: VoiceMessageMediaManagerMock())))
navigationStackCoordinator.setRootCoordinator(coordinator)
return navigationStackCoordinator
@@ -867,7 +889,7 @@ class MockScreen: Identifiable {
return navigationStackCoordinator
case .createRoom:
let navigationStackCoordinator = NavigationStackCoordinator()
let clientProxy = MockClientProxy(userID: "@mock:client.com")
let clientProxy = ClientProxyMock(.init(userID: "@mock:client.com"))
let mockUserSession = MockUserSession(clientProxy: clientProxy, mediaProvider: MockMediaProvider(), voiceMessageMediaManager: VoiceMessageMediaManagerMock())
let createRoomParameters = CreateRoomFlowParameters()
let selectedUsers: [UserProfileProxy] = [.mockAlice, .mockBob, .mockCharlie]
@@ -880,7 +902,7 @@ class MockScreen: Identifiable {
return navigationStackCoordinator
case .createRoomNoUsers:
let navigationStackCoordinator = NavigationStackCoordinator()
let clientProxy = MockClientProxy(userID: "@mock:client.com")
let clientProxy = ClientProxyMock(.init(userID: "@mock:client.com"))
let mockUserSession = MockUserSession(clientProxy: clientProxy,
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock())