Generating SDK Mocks through the usage of swift run tools generate-sdk-mocks (#982)

* basic implementation, that works for now only with the local SDK

* replaced a handmade mock with a generated mock
This commit is contained in:
Mauro
2023-05-30 09:48:55 +02:00
committed by GitHub
parent 25e2b05a4a
commit 088ca622a1
39 changed files with 857 additions and 194 deletions
@@ -21,12 +21,12 @@ struct CreateRoomCoordinatorParameters {
let userSession: UserSessionProtocol
weak var userIndicatorController: UserIndicatorControllerProtocol?
let createRoomParameters: CurrentValuePublisher<CreateRoomFlowParameters, Never>
let selectedUsers: CurrentValuePublisher<[UserProfile], Never>
let selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never>
}
enum CreateRoomCoordinatorAction {
case openRoom(withIdentifier: String)
case deselectUser(UserProfile)
case deselectUser(UserProfileProxy)
case updateDetails(CreateRoomFlowParameters)
}
@@ -23,12 +23,12 @@ enum CreateRoomScreenErrorType: Error {
enum CreateRoomViewModelAction {
case openRoom(withIdentifier: String)
case deselectUser(UserProfile)
case deselectUser(UserProfileProxy)
case updateDetails(CreateRoomFlowParameters)
}
struct CreateRoomViewState: BindableState {
var selectedUsers: [UserProfile]
var selectedUsers: [UserProfileProxy]
var bindings: CreateRoomViewStateBindings
var canCreateRoom: Bool {
@@ -47,5 +47,5 @@ struct CreateRoomViewStateBindings {
enum CreateRoomViewAction {
case createRoom
case deselectUser(UserProfile)
case deselectUser(UserProfileProxy)
}
@@ -32,7 +32,7 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol
init(userSession: UserSessionProtocol,
userIndicatorController: UserIndicatorControllerProtocol?,
createRoomParameters: CurrentValuePublisher<CreateRoomFlowParameters, Never>,
selectedUsers: CurrentValuePublisher<[UserProfile], Never>) {
selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never>) {
let parameters = createRoomParameters.value
self.userSession = userSession
self.userIndicatorController = userIndicatorController
@@ -164,7 +164,7 @@ struct CreateRoom_Previews: PreviewProvider {
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "@userid:example.com"),
mediaProvider: MockMediaProvider())
let parameters = CreateRoomFlowParameters()
let selectedUsers: [UserProfile] = [.mockAlice, .mockBob, .mockCharlie]
let selectedUsers: [UserProfileProxy] = [.mockAlice, .mockBob, .mockCharlie]
return CreateRoomViewModel(userSession: userSession, userIndicatorController: nil, createRoomParameters: .init(parameters), selectedUsers: .init(selectedUsers))
}()
@@ -18,7 +18,7 @@ import Combine
import SwiftUI
struct InviteUsersScreenCoordinatorParameters {
let selectedUsers: CurrentValuePublisher<[UserProfile], Never>
let selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never>
let roomType: InviteUsersScreenRoomType
let mediaProvider: MediaProviderProtocol
let userDiscoveryService: UserDiscoveryServiceProtocol
@@ -27,7 +27,7 @@ struct InviteUsersScreenCoordinatorParameters {
enum InviteUsersScreenCoordinatorAction {
case proceed
case invite(users: [String])
case toggleUser(UserProfile)
case toggleUser(UserProfileProxy)
}
final class InviteUsersScreenCoordinator: CoordinatorProtocol {
@@ -24,7 +24,7 @@ enum InviteUsersScreenErrorType: Error {
enum InviteUsersScreenViewModelAction {
case proceed
case invite(users: [String])
case toggleUser(UserProfile)
case toggleUser(UserProfileProxy)
}
enum InviteUsersScreenRoomType {
@@ -37,7 +37,7 @@ struct InviteUsersScreenViewState: BindableState {
var usersSection: UserDiscoverySection = .init(type: .suggestions, users: [])
var selectedUsers: [UserProfile] = []
var selectedUsers: [UserProfileProxy] = []
var membershipState: [String: MembershipState] = .init()
var isSearching: Bool {
@@ -50,16 +50,16 @@ struct InviteUsersScreenViewState: BindableState {
var scrollToLastID: String?
func isUserSelected(_ user: UserProfile) -> Bool {
func isUserSelected(_ user: UserProfileProxy) -> Bool {
isUserDisabled(user) || selectedUsers.contains { $0.userID == user.userID }
}
func isUserDisabled(_ user: UserProfile) -> Bool {
func isUserDisabled(_ user: UserProfileProxy) -> Bool {
let membershipState = membershipState(user)
return membershipState == .invite || membershipState == .join
}
func membershipState(_ user: UserProfile) -> MembershipState? {
func membershipState(_ user: UserProfileProxy) -> MembershipState? {
membershipState[user.userID]
}
@@ -87,5 +87,5 @@ struct InviteUsersScreenViewStateBindings {
enum InviteUsersScreenViewAction {
case proceed
case toggleUser(UserProfile)
case toggleUser(UserProfileProxy)
}
@@ -30,7 +30,7 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
actionsSubject.eraseToAnyPublisher()
}
init(selectedUsers: CurrentValuePublisher<[UserProfile], Never>,
init(selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never>,
roomType: InviteUsersScreenRoomType,
mediaProvider: MediaProviderProtocol,
userDiscoveryService: UserDiscoveryServiceProtocol) {
@@ -85,7 +85,7 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
@CancellableTask
private var fetchUsersTask: Task<Void, Never>?
private func setupSubscriptions(selectedUsers: CurrentValuePublisher<[UserProfile], Never>) {
private func setupSubscriptions(selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never>) {
context.$viewState
.map(\.bindings.searchQuery)
.debounceAndRemoveDuplicates()
@@ -125,7 +125,7 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
}
}
private func handleResult(for sectionType: UserDiscoverySectionType, result: Result<[UserProfile], UserDiscoveryErrorType>) {
private func handleResult(for sectionType: UserDiscoverySectionType, result: Result<[UserProfileProxy], UserDiscoveryErrorType>) {
switch result {
case .success(let users):
state.usersSection = .init(type: sectionType, users: users)
@@ -123,7 +123,7 @@ struct InviteUsersScreen: View {
.disabled(context.viewState.isActionDisabled)
}
private func deselect(_ user: UserProfile) {
private func deselect(_ user: UserProfileProxy) {
context.send(viewAction: .toggleUser(user))
}
}
@@ -17,7 +17,7 @@
import SwiftUI
struct InviteUsersScreenSelectedItem: View {
let user: UserProfile
let user: UserProfileProxy
let imageProvider: ImageProviderProtocol?
let dismissAction: () -> Void
@@ -33,7 +33,7 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
private let parameters: RoomDetailsScreenCoordinatorParameters
private var viewModel: RoomDetailsScreenViewModelProtocol
private var cancellables: Set<AnyCancellable> = .init()
private let selectedUsers: CurrentValueSubject<[UserProfile], Never> = .init([])
private let selectedUsers: CurrentValueSubject<[UserProfileProxy], Never> = .init([])
private var navigationStackCoordinator: NavigationStackCoordinator {
parameters.navigationStackCoordinator
}
@@ -142,7 +142,7 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
parameters.navigationStackCoordinator.setSheetCoordinator(userIndicatorController)
}
private func toggleUser(_ user: UserProfile) {
private func toggleUser(_ user: UserProfileProxy) {
var selectedUsers = selectedUsers.value
if let index = selectedUsers.firstIndex(where: { $0.userID == user.userID }) {
selectedUsers.remove(at: index)
@@ -40,8 +40,8 @@ final class StartChatScreenCoordinator: CoordinatorProtocol {
createRoomParameters.asCurrentValuePublisher()
}
private let selectedUsers = CurrentValueSubject<[UserProfile], Never>([])
private var selectedUsersPublisher: CurrentValuePublisher<[UserProfile], Never> {
private let selectedUsers = CurrentValueSubject<[UserProfileProxy], Never>([])
private var selectedUsersPublisher: CurrentValuePublisher<[UserProfileProxy], Never> {
selectedUsers.asCurrentValuePublisher()
}
@@ -128,7 +128,7 @@ final class StartChatScreenCoordinator: CoordinatorProtocol {
// MARK: - Private
private func toggleUser(_ user: UserProfile) {
private func toggleUser(_ user: UserProfileProxy) {
var selectedUsers = selectedUsers.value
if let index = selectedUsers.firstIndex(where: { $0.userID == user.userID }) {
selectedUsers.remove(at: index)
@@ -51,5 +51,5 @@ struct StartChatScreenViewStateBindings {
enum StartChatScreenViewAction {
case close
case createRoom
case selectUser(UserProfile)
case selectUser(UserProfileProxy)
}
@@ -117,7 +117,7 @@ class StartChatScreenViewModel: StartChatScreenViewModelType, StartChatScreenVie
}
}
private func handleResult(for sectionType: UserDiscoverySectionType, result: Result<[UserProfile], UserDiscoveryErrorType>) {
private func handleResult(for sectionType: UserDiscoverySectionType, result: Result<[UserProfileProxy], UserDiscoveryErrorType>) {
switch result {
case .success(let users):
state.usersSection = .init(type: sectionType, users: users)
@@ -126,7 +126,7 @@ class StartChatScreenViewModel: StartChatScreenViewModelType, StartChatScreenVie
}
}
private func createDirectRoom(with user: UserProfile) async {
private func createDirectRoom(with user: UserProfileProxy) async {
defer {
hideLoadingIndicator()
}