Skip to content

Commit

Permalink
Update SC availability taking into account 'transferring' state
Browse files Browse the repository at this point in the history
Add 'transferring' and 'engagement.capabilities.text == true' to be used for SC availability.

MOB-3654
  • Loading branch information
igorkravchenko committed Dec 6, 2024
1 parent 517d35c commit aada08d
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(queueIds: [])))
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
Expand All @@ -67,6 +75,7 @@ extension SecureConversations.Availability {
var isAuthenticated: () -> Bool
var log: CoreSdkClient.Logger
var queuesMonitor: QueuesMonitor
var getCurrentEngagement: CoreSdkClient.GetCurrentEngagement
}
}

Expand Down Expand Up @@ -101,7 +110,8 @@ extension SecureConversations.Availability.Environment {
listQueues: environment.listQueues,
isAuthenticated: environment.isAuthenticated,
log: environment.log,
queuesMonitor: environment.queuesMonitor
queuesMonitor: environment.queuesMonitor,
getCurrentEngagement: environment.getCurrentEngagement
)
}

Expand All @@ -110,7 +120,8 @@ extension SecureConversations.Availability.Environment {
listQueues: environment.listQueues,
isAuthenticated: environment.isAuthenticated,
log: environment.log,
queuesMonitor: environment.queuesMonitor
queuesMonitor: environment.queuesMonitor,
getCurrentEngagement: environment.getCurrentEngagement
)
}
}
Expand All @@ -129,13 +140,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
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ extension SecureConversations.Availability.Environment {
return false
},
log: .failing,
queuesMonitor: .failing
queuesMonitor: .failing,
getCurrentEngagement: {
fail("\(Self.self).getCurrentEngagement")
return .mock()
}
)
}
5 changes: 5 additions & 0 deletions GliaWidgetsTests/SecureConversations/AvailabilityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Availability.Status, CoreSdkClient.SalemoveError>?
Expand Down Expand Up @@ -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.Status, CoreSdkClient.SalemoveError>?
availability.checkSecureConversationsAvailability(for: queueIds) { result in
Expand All @@ -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.Status, CoreSdkClient.SalemoveError>?
availability.checkSecureConversationsAvailability(for: [queueId]) { result in
Expand All @@ -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 }
Expand Down Expand Up @@ -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.Status, CoreSdkClient.SalemoveError>?
availability.checkSecureConversationsAvailability(for: []) { result in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ extension SecureConversationsTranscriptModelTests {
listQueues: modelEnv.listQueues,
isAuthenticated: { true },
log: logger,
queuesMonitor: .mock()
queuesMonitor: .mock(),
getCurrentEngagement: { .mock() }
)

let viewModel = TranscriptModel(
Expand Down Expand Up @@ -200,7 +201,8 @@ private extension SecureConversationsTranscriptModelTests {
listQueues: modelEnv.listQueues,
isAuthenticated: { true },
log: logger,
queuesMonitor: .mock()
queuesMonitor: .mock(),
getCurrentEngagement: { .mock() }
)

return TranscriptModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ private extension SecureConversationsTranscriptModelTests {
listQueues: modelEnv.listQueues,
isAuthenticated: { true },
log: logger,
queuesMonitor: .mock()
queuesMonitor: .mock(),
getCurrentEngagement: { .mock() }
)

return TranscriptModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ private extension SecureConversationsTranscriptModelTests {
listQueues: modelEnv.listQueues,
isAuthenticated: { true },
log: logger,
queuesMonitor: .mock()
queuesMonitor: .mock(),
getCurrentEngagement: { .mock() }
)

return TranscriptModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ private extension SecureConversationsTranscriptModelTests {
listQueues: modelEnv.listQueues,
isAuthenticated: { true },
log: logger,
queuesMonitor: .mock()
queuesMonitor: .mock(),
getCurrentEngagement: { .mock() }
)

return TranscriptModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ extension SecureConversations.Availability {
listQueues: { _ in },
isAuthenticated: { true },
log: .mock,
queuesMonitor: .mock()
queuesMonitor: .mock(),
getCurrentEngagement: { .mock() }
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit aada08d

Please sign in to comment.