From e8b2a4aa6a538b792b44bcde0c54c5604443bf21 Mon Sep 17 00:00:00 2001 From: Igor Kravchenko Date: Thu, 5 Dec 2024 20:27:53 +0200 Subject: [PATCH] Update SC availability taking into account 'transferring' state Add 'transferring' and 'engagement.capabilities.text == true' to be used for SC availability. MOB-3654 --- .../SecureConversations.TranscriptModel.swift | 6 +- .../SecureConversations.Availability.swift | 40 +++++++++-- ...SecureConversations.WelcomeViewModel.swift | 17 +++-- .../Availability.Environment.Failing.swift | 6 +- .../AvailabilityTests.swift | 38 +++++++++- .../TranscriptModelTests+GVA.swift | 6 +- .../TranscriptModelTests+MessageRetry.swift | 3 +- .../TranscriptModelTests+ResponseCard.swift | 3 +- .../TranscriptModelTests+URLs.swift | 3 +- .../ChatTranscript/TranscriptModelTests.swift | 72 ++++++++++++------- ...eConversations.WelcomeViewModel.Mock.swift | 3 +- ...reConversations.WelcomeViewModelSpec.swift | 18 ++--- .../ChatViewModel/ChatViewModelTests.swift | 3 +- 13 files changed, 158 insertions(+), 60 deletions(-) diff --git a/GliaWidgets/SecureConversations/ChatTranscript/SecureConversations.TranscriptModel.swift b/GliaWidgets/SecureConversations/ChatTranscript/SecureConversations.TranscriptModel.swift index 7a0537973..8faceb289 100644 --- a/GliaWidgets/SecureConversations/ChatTranscript/SecureConversations.TranscriptModel.swift +++ b/GliaWidgets/SecureConversations/ChatTranscript/SecureConversations.TranscriptModel.swift @@ -146,10 +146,14 @@ extension SecureConversations { availability.checkSecureConversationsAvailability(for: environment.queueIds) { [weak self] result in guard let self else { return } switch result { - case let .success(.available(queueIds)): + case let .success(.available(.queues(queueIds))): self.environment.queueIds = queueIds self.isSecureConversationsAvailable = true self.fileUploadListModel.isEnabled = true + case .success(.available(.transferred)): + self.environment.queueIds = [] + self.isSecureConversationsAvailable = true + self.fileUploadListModel.isEnabled = true case .failure, .success(.unavailable(.emptyQueue)), .success(.unavailable(.unauthenticated)): // For chat screen we no longer show unavailability dialog, but unavailability banner instead. self.isSecureConversationsAvailable = false diff --git a/GliaWidgets/SecureConversations/SecureConversations.Availability.swift b/GliaWidgets/SecureConversations/SecureConversations.Availability.swift index 943bb70a2..05c107af1 100644 --- a/GliaWidgets/SecureConversations/SecureConversations.Availability.swift +++ b/GliaWidgets/SecureConversations/SecureConversations.Availability.swift @@ -40,8 +40,16 @@ extension SecureConversations { let filteredQueues = fetchedQueues.filter(defaultPredicate) // Check if matched queues match support `messaging` and - // have status other than `closed` + // have status other than `closed`. guard !filteredQueues.isEmpty else { + // In case of "transferred SC" we should treat SC as available. + if let engagement = environment.getCurrentEngagement(), + engagement.status == .transferring, + engagement.capabilities?.text == true { + completion(.success(.available(.transferred))) + return + } + environment.log.warning("Provided queue IDs do not match with queues that have status other than closed and support messaging.") completion(.success(.unavailable(.emptyQueue))) return @@ -49,7 +57,7 @@ extension SecureConversations { let queueIds = filteredQueues.map { $0.id } environment.log.info("Secure Messaging is available in queues with IDs: \(queueIds).") - completion(.success(.available(queueIds: queueIds))) + completion(.success(.available(.queues(queueIds: queueIds)))) } private var defaultPredicate: (CoreSdkClient.Queue) -> Bool { @@ -67,12 +75,17 @@ extension SecureConversations.Availability { var isAuthenticated: () -> Bool var log: CoreSdkClient.Logger var queuesMonitor: QueuesMonitor + var getCurrentEngagement: CoreSdkClient.GetCurrentEngagement } } extension SecureConversations.Availability { enum Status: Equatable { - case available(queueIds: [String] = []) + enum Available: Equatable { + case queues(queueIds: [String]) + case transferred + } + case available(Available) case unavailable(UnavailabilityReason) static func == (lhs: Status, rhs: Status) -> Bool { @@ -85,6 +98,15 @@ extension SecureConversations.Availability { return false } } + + var isAvailable: Bool { + switch self { + case .available: + true + case .unavailable: + false + } + } } } @@ -101,7 +123,8 @@ extension SecureConversations.Availability.Environment { listQueues: environment.listQueues, isAuthenticated: environment.isAuthenticated, log: environment.log, - queuesMonitor: environment.queuesMonitor + queuesMonitor: environment.queuesMonitor, + getCurrentEngagement: environment.getCurrentEngagement ) } @@ -110,7 +133,8 @@ extension SecureConversations.Availability.Environment { listQueues: environment.listQueues, isAuthenticated: environment.isAuthenticated, log: environment.log, - queuesMonitor: environment.queuesMonitor + queuesMonitor: environment.queuesMonitor, + getCurrentEngagement: environment.getCurrentEngagement ) } } @@ -129,13 +153,15 @@ extension SecureConversations.Availability.Environment { listQueues: @escaping CoreSdkClient.ListQueues = { _ in }, isAuthenticated: @escaping () -> Bool = { false }, log: CoreSdkClient.Logger = .mock, - queuesMonitor: QueuesMonitor = .mock() + queuesMonitor: QueuesMonitor = .mock(), + getCurrentEngagement: @escaping CoreSdkClient.GetCurrentEngagement = { .mock() } ) -> Self { .init( listQueues: listQueues, isAuthenticated: isAuthenticated, log: log, - queuesMonitor: queuesMonitor + queuesMonitor: queuesMonitor, + getCurrentEngagement: getCurrentEngagement ) } } diff --git a/GliaWidgets/SecureConversations/Welcome/SecureConversations.WelcomeViewModel.swift b/GliaWidgets/SecureConversations/Welcome/SecureConversations.WelcomeViewModel.swift index 4c52cab37..df8252d0d 100644 --- a/GliaWidgets/SecureConversations/Welcome/SecureConversations.WelcomeViewModel.swift +++ b/GliaWidgets/SecureConversations/Welcome/SecureConversations.WelcomeViewModel.swift @@ -22,7 +22,7 @@ extension SecureConversations { /// Flag indicating attachment(s) availability. /// By default attachments are not available, until site configurations are fetched. private(set) var isAttachmentsAvailable: Bool = false { didSet { reportChange() } } - var availabilityStatus: Availability.Status = .available(queueIds: []) { didSet { reportChange() } } + var availabilityStatus: Availability.Status = .available(.queues(queueIds: [])) { didSet { reportChange() } } var messageInputState: MessageInputState = .normal { didSet { reportChange() } } var sendMessageRequestState: SendMessageRequestState = .waiting { didSet { reportChange() } } @@ -64,9 +64,12 @@ extension SecureConversations { availability.checkSecureConversationsAvailability(for: environment.queueIds) { [weak self] result in guard let self else { return } switch result { - case let .success(.available(queueIds)): + case let .success(.available(.queues(queueIds))): self.environment.queueIds = queueIds - self.availabilityStatus = .available(queueIds: queueIds) + self.availabilityStatus = .available(.queues(queueIds: queueIds)) + case .success(.available(.transferred)): + self.environment.queueIds = [] + self.availabilityStatus = .available(.transferred) case .success(.unavailable(.emptyQueue)), .failure: self.availabilityStatus = .unavailable(.emptyQueue) self.delegate?(.showAlert(.unavailableMessageCenter())) @@ -178,7 +181,7 @@ extension SecureConversations.WelcomeViewModel { ) -> SecureConversations.WelcomeStyle { var style = instance.environment.welcomeStyle - if instance.availabilityStatus != .available() { + if !instance.availabilityStatus.isAvailable { style.messageTitleStyle = nil } @@ -191,7 +194,7 @@ extension SecureConversations.WelcomeViewModel { var filePickerButton: WelcomeViewProps.FilePickerButton? let isFilePickerEnabled = !instance.fileUploadListModel.isLimitReached - if instance.availabilityStatus == .available(), instance.isAttachmentsAvailable { + if instance.availabilityStatus.isAvailable, instance.isAttachmentsAvailable { filePickerButton = WelcomeViewProps.FilePickerButton( isEnabled: isFilePickerEnabled, tap: Command { originView in @@ -203,7 +206,7 @@ extension SecureConversations.WelcomeViewModel { return filePickerButton } static func textViewState(for instance: SecureConversations.WelcomeViewModel) -> TextViewProps? { - guard instance.availabilityStatus == .available() else { + guard instance.availabilityStatus.isAvailable else { return nil } @@ -254,7 +257,7 @@ extension SecureConversations.WelcomeViewModel { for instance: SecureConversations.WelcomeViewModel ) -> SendMessageButton? { // Is service available? - guard instance.availabilityStatus == .available() else { + guard instance.availabilityStatus.isAvailable else { return nil } diff --git a/GliaWidgetsTests/SecureConversations/Availability.Environment.Failing.swift b/GliaWidgetsTests/SecureConversations/Availability.Environment.Failing.swift index d94a9806f..1f98679ac 100644 --- a/GliaWidgetsTests/SecureConversations/Availability.Environment.Failing.swift +++ b/GliaWidgetsTests/SecureConversations/Availability.Environment.Failing.swift @@ -10,6 +10,10 @@ extension SecureConversations.Availability.Environment { return false }, log: .failing, - queuesMonitor: .failing + queuesMonitor: .failing, + getCurrentEngagement: { + fail("\(Self.self).getCurrentEngagement") + return .mock() + } ) } diff --git a/GliaWidgetsTests/SecureConversations/AvailabilityTests.swift b/GliaWidgetsTests/SecureConversations/AvailabilityTests.swift index 94f056daf..cf952fee1 100644 --- a/GliaWidgetsTests/SecureConversations/AvailabilityTests.swift +++ b/GliaWidgetsTests/SecureConversations/AvailabilityTests.swift @@ -32,6 +32,7 @@ final class AvailabilityTests: XCTestCase { env.log = logger env.isAuthenticated = { true } env.queuesMonitor = .mock(listQueues: env.listQueues) + env.getCurrentEngagement = { .mock() } let queueIds = [UUID.mock.uuidString] let availability = Availability(environment: env) var receivedResult: Result? @@ -81,7 +82,7 @@ final class AvailabilityTests: XCTestCase { let result = try XCTUnwrap(receivedResult) switch result { case let .success(.available(queueIds)): - XCTAssertEqual(queueIds, [queueId]) + XCTAssertEqual(queueIds, .queues(queueIds: [queueId])) default: XCTFail("Result should be `.success(.available)`") } @@ -100,6 +101,7 @@ final class AvailabilityTests: XCTestCase { env.log = logger env.isAuthenticated = { true } env.queuesMonitor = .mock(listQueues: env.listQueues) + env.getCurrentEngagement = { .mock() } let availability = Availability(environment: env) var receivedResult: Result? availability.checkSecureConversationsAvailability(for: queueIds) { result in @@ -121,6 +123,7 @@ final class AvailabilityTests: XCTestCase { env.log = logger env.isAuthenticated = { true } env.queuesMonitor = .mock(listQueues: env.listQueues) + env.getCurrentEngagement = { .mock() } let availability = Availability(environment: env) var receivedResult: Result? availability.checkSecureConversationsAvailability(for: [queueId]) { result in @@ -136,6 +139,7 @@ final class AvailabilityTests: XCTestCase { env.listQueues = { callback in callback([.mock(id: queueId, status: .closed, media: [.text])], nil) } + env.getCurrentEngagement = { .mock() } var logger = CoreSdkClient.Logger.failing logger.prefixedClosure = { _ in logger } logger.warningClosure = { _, _, _, _ in } @@ -170,7 +174,7 @@ final class AvailabilityTests: XCTestCase { } let result = try XCTUnwrap(receivedResult) switch result { - case let .success(.available(queueIds)): + case let .success(.available(.queues(queueIds))): XCTAssertEqual(queueIds, [queueId]) default: XCTFail("Result should be `.success(.available)`") @@ -189,6 +193,7 @@ final class AvailabilityTests: XCTestCase { env.log = logger env.isAuthenticated = { true } env.queuesMonitor = .mock(listQueues: env.listQueues) + env.getCurrentEngagement = { .mock() } let availability = Availability(environment: env) var receivedResult: Result? availability.checkSecureConversationsAvailability(for: []) { result in @@ -196,4 +201,33 @@ final class AvailabilityTests: XCTestCase { } try XCTAssertEqual(XCTUnwrap(receivedResult), .success(.unavailable(.emptyQueue))) } + + func testAvailableStatusIfTransferredAndCapabilitiesTextTrue() throws { + var env = Availability.Environment.failing + env.getCurrentEngagement = { + .mock(status: .transferring, capabilities: .init(text: true)) + } + env.listQueues = { callback in + callback([], nil) + } + var logger = CoreSdkClient.Logger.failing + logger.prefixedClosure = { _ in logger } + logger.infoClosure = { _, _, _, _ in } + logger.warningClosure = { _, _, _, _ in } + env.log = logger + env.isAuthenticated = { true } + env.queuesMonitor = .mock(listQueues: env.listQueues) + let availability = Availability(environment: env) + var receivedResult: Result? + availability.checkSecureConversationsAvailability(for: []) { result in + receivedResult = result + } + let result = try XCTUnwrap(receivedResult) + switch result { + case let .success(status): + XCTAssertEqual(status, .available(.transferred)) + default: + XCTFail("Result should be `.success(.available)`. Got `\(result)` instead.") + } + } } diff --git a/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+GVA.swift b/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+GVA.swift index f40a17778..98c066b29 100644 --- a/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+GVA.swift +++ b/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+GVA.swift @@ -153,7 +153,8 @@ extension SecureConversationsTranscriptModelTests { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: logger, - queuesMonitor: .mock() + queuesMonitor: .mock(), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( @@ -200,7 +201,8 @@ private extension SecureConversationsTranscriptModelTests { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: logger, - queuesMonitor: .mock() + queuesMonitor: .mock(), + getCurrentEngagement: { .mock() } ) return TranscriptModel( diff --git a/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+MessageRetry.swift b/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+MessageRetry.swift index 63385de7a..5619165bc 100644 --- a/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+MessageRetry.swift +++ b/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+MessageRetry.swift @@ -140,7 +140,8 @@ private extension SecureConversationsTranscriptModelTests { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: logger, - queuesMonitor: .mock() + queuesMonitor: .mock(), + getCurrentEngagement: { .mock() } ) return TranscriptModel( diff --git a/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+ResponseCard.swift b/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+ResponseCard.swift index 7fd5455d1..0bfc85114 100644 --- a/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+ResponseCard.swift +++ b/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+ResponseCard.swift @@ -48,7 +48,8 @@ private extension SecureConversationsTranscriptModelTests { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: logger, - queuesMonitor: .mock() + queuesMonitor: .mock(), + getCurrentEngagement: { .mock() } ) return TranscriptModel( diff --git a/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+URLs.swift b/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+URLs.swift index 9544538e4..4a227fdfa 100644 --- a/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+URLs.swift +++ b/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests+URLs.swift @@ -92,7 +92,8 @@ private extension SecureConversationsTranscriptModelTests { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: logger, - queuesMonitor: .mock() + queuesMonitor: .mock(), + getCurrentEngagement: { .mock() } ) return TranscriptModel( diff --git a/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests.swift b/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests.swift index 40d281d30..4c1d14b53 100644 --- a/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests.swift +++ b/GliaWidgetsTests/SecureConversations/ChatTranscript/TranscriptModelTests.swift @@ -21,7 +21,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: logger, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( isCustomCardSupported: false, @@ -52,7 +53,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { false }, log: logger, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( isCustomCardSupported: false, @@ -87,7 +89,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( @@ -135,7 +138,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( isCustomCardSupported: false, @@ -169,7 +173,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( isCustomCardSupported: false, @@ -217,7 +222,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( @@ -260,7 +266,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( @@ -299,7 +306,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( @@ -344,7 +352,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( @@ -385,7 +394,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( @@ -429,7 +439,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( @@ -470,7 +481,7 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { callback(.success(0)) } modelEnv.startSocketObservation = {} - modelEnv.gcd.mainQueue.asyncAfterDeadline = { _, callback in } + modelEnv.gcd.mainQueue.asyncAfterDeadline = { _, _ in } modelEnv.loadChatMessagesFromHistory = { true } modelEnv.createEntryWidget = { _ in .mock() } let scheduler = CoreSdkClient.ReactiveSwift.TestScheduler() @@ -480,7 +491,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let interactor: Interactor = .failing @@ -547,7 +559,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let interactor: Interactor = .failing @@ -611,6 +624,7 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { } availabilityEnv.isAuthenticated = { true } availabilityEnv.queuesMonitor = .mock(listQueues: availabilityEnv.listQueues) + availabilityEnv.getCurrentEngagement = { .mock() } let model = TranscriptModel( isCustomCardSupported: false, environment: modelEnvironment, @@ -705,6 +719,7 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { } availabilityEnv.isAuthenticated = { true } availabilityEnv.queuesMonitor = .mock(listQueues: availabilityEnv.listQueues) + availabilityEnv.getCurrentEngagement = { .mock() } let model = TranscriptModel( isCustomCardSupported: false, environment: modelEnvironment, @@ -729,7 +744,7 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { modelEnvironment.createFileUploadListModel = { .mock(environment: $0) } - modelEnvironment.createEntryWidget = { _ in .mock() } + modelEnvironment.createEntryWidget = { _ in .mock() } var availabilityEnv = SecureConversations.Availability.Environment.failing availabilityEnv.log = logger availabilityEnv.listQueues = { callback in @@ -737,6 +752,7 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { } availabilityEnv.isAuthenticated = { true } availabilityEnv.queuesMonitor = .mock(listQueues: availabilityEnv.listQueues) + availabilityEnv.getCurrentEngagement = { .mock() } let model = TranscriptModel( isCustomCardSupported: false, environment: modelEnvironment, @@ -759,7 +775,7 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { XCTFail("Unexpected action: \(receivedAction)") } } - + func testLoadHistoryAlsoInvokesSecureMarkMessagesAsReadIfShouldNotShowLeaveSecureConversationDialog() { var modelEnv = TranscriptModel.Environment.failing let fileUploadListModel = FileUploadListViewModel.mock() @@ -790,7 +806,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( @@ -806,10 +823,10 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { viewModel.start() scheduler.run() - + XCTAssertEqual(calls, [.secureMarkMessagesAsRead]) } - + func testLoadHistoryNotInvokesSecureMarkMessagesAsReadIfShouldShowLeaveSecureConversationDialog() { var modelEnv = TranscriptModel.Environment.failing let fileUploadListModel = FileUploadListViewModel.mock() @@ -840,7 +857,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( @@ -856,7 +874,7 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { viewModel.start() scheduler.run() - + XCTAssertTrue(calls.isEmpty) } @@ -890,7 +908,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( @@ -903,7 +922,7 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { failedToDeliverStatusText: "", interactor: .failing ) - + viewModel.engagementAction = { action in if case .showAlert(let type) = action, case let .leaveCurrentConversation(_, declined) = type { declined?() @@ -912,10 +931,10 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { viewModel.start() scheduler.run() - + XCTAssertEqual(calls, [.secureMarkMessagesAsRead]) } - + func testReceiveMessageMarksMessagesAsRead() { enum Call: Equatable { case secureMarkMessagesAsRead } var calls: [Call] = [] @@ -950,7 +969,8 @@ final class SecureConversationsTranscriptModelTests: XCTestCase { listQueues: modelEnv.listQueues, isAuthenticated: { true }, log: .failing, - queuesMonitor: .mock(listQueues: modelEnv.listQueues) + queuesMonitor: .mock(listQueues: modelEnv.listQueues), + getCurrentEngagement: { .mock() } ) let viewModel = TranscriptModel( diff --git a/GliaWidgetsTests/SecureConversations/Welcome/SecureConversations.WelcomeViewModel.Mock.swift b/GliaWidgetsTests/SecureConversations/Welcome/SecureConversations.WelcomeViewModel.Mock.swift index 086e3ce7d..96926b768 100644 --- a/GliaWidgetsTests/SecureConversations/Welcome/SecureConversations.WelcomeViewModel.Mock.swift +++ b/GliaWidgetsTests/SecureConversations/Welcome/SecureConversations.WelcomeViewModel.Mock.swift @@ -53,7 +53,8 @@ extension SecureConversations.Availability { listQueues: { _ in }, isAuthenticated: { true }, log: .mock, - queuesMonitor: .mock() + queuesMonitor: .mock(), + getCurrentEngagement: { .mock() } ) ) } diff --git a/GliaWidgetsTests/SecureConversations/Welcome/SecureConversations.WelcomeViewModelSpec.swift b/GliaWidgetsTests/SecureConversations/Welcome/SecureConversations.WelcomeViewModelSpec.swift index dc4d5e7da..cfdf90d0b 100644 --- a/GliaWidgetsTests/SecureConversations/Welcome/SecureConversations.WelcomeViewModelSpec.swift +++ b/GliaWidgetsTests/SecureConversations/Welcome/SecureConversations.WelcomeViewModelSpec.swift @@ -265,7 +265,7 @@ extension SecureConversationsWelcomeViewModelTests { } viewModel = .init(environment: environment, availability: .mock) - viewModel.availabilityStatus = .available() + viewModel.availabilityStatus = .available(.queues(queueIds: [])) if case .welcome(let props) = viewModel.props() { XCTAssertNotNil(props.filePickerButton) @@ -335,7 +335,7 @@ extension SecureConversationsWelcomeViewModelTests { } func testSendMessageButtonStateFileUploads() { - viewModel.availabilityStatus = .available() + viewModel.availabilityStatus = .available(.queues(queueIds: [])) let uploadFile: FileUpload.Environment.UploadFile = .toSecureMessaging { file, progress, completion in completion(.failure(CoreSdkClient.GliaCoreError(reason: ""))) return .mock @@ -354,7 +354,7 @@ extension SecureConversationsWelcomeViewModelTests { } func testSendMessageButtonStateInProgressFileUpload() { - viewModel.availabilityStatus = .available() + viewModel.availabilityStatus = .available(.queues(queueIds: [])) let fileUpload: FileUpload = .mock() fileUpload.startUpload() viewModel.fileUploadListModel.environment.uploader.uploads = [fileUpload] @@ -367,7 +367,7 @@ extension SecureConversationsWelcomeViewModelTests { } func testSendMessageButtonStateEmptyText() { - viewModel.availabilityStatus = .available() + viewModel.availabilityStatus = .available(.queues(queueIds: [])) viewModel.messageText = "" if case .welcome(let props) = viewModel.props() { @@ -378,7 +378,7 @@ extension SecureConversationsWelcomeViewModelTests { } func testSendMessageButtonStateSuccessfulUpload() { - viewModel.availabilityStatus = .available() + viewModel.availabilityStatus = .available(.queues(queueIds: [])) viewModel.fileUploadListModel.environment.uploader = FileUploader(maximumUploads: 100, environment: .mock) viewModel.messageText = "" @@ -390,7 +390,7 @@ extension SecureConversationsWelcomeViewModelTests { } func testSendMessageButtonStateNoQueues() { - viewModel.availabilityStatus = .available() + viewModel.availabilityStatus = .available(.queues(queueIds: [])) viewModel.messageText = "text" viewModel.fileUploadListModel.environment.uploader = FileUploader(maximumUploads: 100, environment: .mock) viewModel.environment.queueIds = [] @@ -403,7 +403,7 @@ extension SecureConversationsWelcomeViewModelTests { } func testSendMessageButtonStateLoadingMessageRequestState() { - viewModel.availabilityStatus = .available() + viewModel.availabilityStatus = .available(.queues(queueIds: [])) viewModel.messageText = "text" viewModel.fileUploadListModel.environment.uploader = FileUploader(maximumUploads: 100, environment: .mock) viewModel.environment.queueIds = [""] @@ -417,7 +417,7 @@ extension SecureConversationsWelcomeViewModelTests { } func testSendMessageButtonStateWaitingMessageRequestState() { - viewModel.availabilityStatus = .available() + viewModel.availabilityStatus = .available(.queues(queueIds: [])) viewModel.messageText = "text" viewModel.fileUploadListModel.environment.uploader = FileUploader(maximumUploads: 100, environment: .mock) viewModel.environment.queueIds = [""] @@ -623,7 +623,7 @@ extension SecureConversationsWelcomeViewModelTests { viewModel = .init(environment: .mock(queueIds: [uuid]), availability: availability) - XCTAssertEqual(viewModel.availabilityStatus, .available()) + XCTAssertEqual(viewModel.availabilityStatus, .available(.queues(queueIds: []))) } func testAvailabilityUnavailableEmptyQueues() { diff --git a/GliaWidgetsTests/Sources/ChatViewModel/ChatViewModelTests.swift b/GliaWidgetsTests/Sources/ChatViewModel/ChatViewModelTests.swift index 6a1f03a96..7f58231d0 100644 --- a/GliaWidgetsTests/Sources/ChatViewModel/ChatViewModelTests.swift +++ b/GliaWidgetsTests/Sources/ChatViewModel/ChatViewModelTests.swift @@ -467,7 +467,8 @@ class ChatViewModelTests: XCTestCase { listQueues: transcriptModelEnv.listQueues, isAuthenticated: { true }, log: logger, - queuesMonitor: .mock() + queuesMonitor: .mock(), + getCurrentEngagement: { .mock() } ) let transcriptModel = TranscriptModel( isCustomCardSupported: false,