Skip to content

Commit

Permalink
Add logs for unknown onEnd engagement action
Browse files Browse the repository at this point in the history
  • Loading branch information
ykyivskyi-gl authored and github-review-helper committed Jan 31, 2025
1 parent b89498d commit 1cbee5e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ extension ChatViewModel {
case .showEndedNotification:
handleOperatorEndedEngagement()
case let .unknown(unhandledCase):
// TODO: log unhandled case MOB-3971
environment.log.warning("Engagement ended with unknown case '\(unhandledCase)'.")
handleOperatorEndedEngagement()
@unknown default:
// TODO: log unhandled case MOB-3971
environment.log.warning("Engagement ended with unknown case.")
handleOperatorEndedEngagement()
}
// There's no need for nilling-out operator image in the bubble via
Expand Down
38 changes: 38 additions & 0 deletions GliaWidgetsTests/Sources/ChatViewModel/ChatViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,44 @@ class ChatViewModelTests: XCTestCase {
]
)
}

func test_engagementEndedByOperatorWithUnknownOnEndActionLogsWarning() {
var interactorEnv = Interactor.Environment.failing
interactorEnv.gcd.mainQueue = .mock
let interactor = Interactor.mock(environment: interactorEnv)
interactor.state = .ended(.byOperator)
var warnings: [String] = []
let mockUnknownAction = "Unknown reason"

var viewModelEnv = ChatViewModel.Environment.failing()
viewModelEnv.fileManager.urlsForDirectoryInDomainMask = { _, _ in [.mock] }
viewModelEnv.fileManager.createDirectoryAtUrlWithIntermediateDirectories = { _, _, _ in }
let fileUploadListViewModelEnv = SecureConversations.FileUploadListViewModel.Environment.mock
fileUploadListViewModelEnv.uploader.uploads = []
viewModelEnv.createFileUploadListModel = { _ in .mock(environment: fileUploadListViewModelEnv) }
viewModelEnv.log = .mock
viewModelEnv.log.warningClosure = { message, _, _, _ in
warnings.append("\(message)")
}
let viewModel = ChatViewModel.mock(interactor: interactor, environment: viewModelEnv)
enum Call {
case engagementActionShowAlertWithOperatorEndedEngagement
}
var calls: [Call] = []
viewModel.engagementAction = { action in
switch action {
case .showAlert(.operatorEndedEngagement):
calls.append(.engagementActionShowAlertWithOperatorEndedEngagement)
default:
break
}
}

interactor.setEndedEngagement(.mock(actionOnEnd: .unknown(mockUnknownAction)))
viewModel.interactorEvent(.stateChanged(.ended(.byOperator)))
XCTAssertEqual(calls, [.engagementActionShowAlertWithOperatorEndedEngagement])
XCTAssertEqual(warnings, ["Engagement ended with unknown case '\(mockUnknownAction)'."])
}

func test_closeActionDoesNotShowConfirmationIfThereIsTransferredSC() throws {
var interactorEnv = Interactor.Environment.failing
Expand Down

0 comments on commit 1cbee5e

Please sign in to comment.