Skip to content

Commit cacb2e9

Browse files
committed
Add stages tests
1 parent c660c0f commit cacb2e9

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

StreamVideoTests/WebRTC/v2/StateMachine/Stages/WebRTCCoordinatorStateMachine_JoiningStageTests.swift

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,30 @@ final class WebRTCCoordinatorStateMachine_JoiningStageTests: XCTestCase, @unchec
312312
cancellable.cancel()
313313
}
314314

315+
func test_transition_fromConnected_configuresAudioSession() async throws {
316+
subject.context.coordinator = mockCoordinatorStack.coordinator
317+
subject.context.reconnectAttempts = 11
318+
await mockCoordinatorStack
319+
.coordinator
320+
.stateAdapter
321+
.set(sfuAdapter: mockCoordinatorStack.sfuStack.adapter)
322+
mockCoordinatorStack.webRTCAuthenticator.stubbedFunction[.waitForConnect] = Result<Void, Error>.success(())
323+
let cancellable = receiveEvent(
324+
.sfuEvent(.joinResponse(Stream_Video_Sfu_Event_JoinResponse())),
325+
every: 0.3
326+
)
327+
328+
try await assertTransition(
329+
from: .connected,
330+
expectedTarget: .joined,
331+
subject: subject
332+
) {
333+
let audioSession = await $0.context.coordinator?.stateAdapter.audioSession
334+
XCTAssertNotNil(audioSession?.delegate)
335+
}
336+
cancellable.cancel()
337+
}
338+
315339
func test_transition_fromConnectedSFUConnected_updatesParticipants() async throws {
316340
subject.context.coordinator = mockCoordinatorStack.coordinator
317341
subject.context.reconnectAttempts = 11
@@ -730,6 +754,30 @@ final class WebRTCCoordinatorStateMachine_JoiningStageTests: XCTestCase, @unchec
730754
cancellable.cancel()
731755
}
732756

757+
func test_transition_fromConnectedWithRejoin_configuresAudioSession() async throws {
758+
subject.context.coordinator = mockCoordinatorStack.coordinator
759+
subject.context.isRejoiningFromSessionID = .unique
760+
await mockCoordinatorStack
761+
.coordinator
762+
.stateAdapter
763+
.set(sfuAdapter: mockCoordinatorStack.sfuStack.adapter)
764+
mockCoordinatorStack.webRTCAuthenticator.stubbedFunction[.waitForConnect] = Result<Void, Error>.success(())
765+
let cancellable = receiveEvent(
766+
.sfuEvent(.joinResponse(Stream_Video_Sfu_Event_JoinResponse())),
767+
every: 0.3
768+
)
769+
770+
try await assertTransition(
771+
from: .connected,
772+
expectedTarget: .joined,
773+
subject: subject
774+
) {
775+
let audioSession = await $0.context.coordinator?.stateAdapter.audioSession
776+
XCTAssertNotNil(audioSession?.delegate)
777+
}
778+
cancellable.cancel()
779+
}
780+
733781
func test_transition_fromConnectedWithRejoinSFUConnected_updatesParticipantsAndFiltersOutUserWithPreviousSessionId(
734782
) async throws {
735783
subject.context.coordinator = mockCoordinatorStack.coordinator
@@ -1357,6 +1405,31 @@ final class WebRTCCoordinatorStateMachine_JoiningStageTests: XCTestCase, @unchec
13571405
cancellable.cancel()
13581406
}
13591407

1408+
func test_transition_fromMigrated_configuresAudioSession() async throws {
1409+
subject.context.coordinator = mockCoordinatorStack.coordinator
1410+
subject.context.reconnectAttempts = 11
1411+
subject.context.migratingFromSFU = "test-sfu"
1412+
await mockCoordinatorStack
1413+
.coordinator
1414+
.stateAdapter
1415+
.set(sfuAdapter: mockCoordinatorStack.sfuStack.adapter)
1416+
mockCoordinatorStack.webRTCAuthenticator.stubbedFunction[.waitForConnect] = Result<Void, Error>.success(())
1417+
let cancellable = receiveEvent(
1418+
.sfuEvent(.joinResponse(Stream_Video_Sfu_Event_JoinResponse())),
1419+
every: 0.3
1420+
)
1421+
1422+
try await assertTransition(
1423+
from: .migrated,
1424+
expectedTarget: .joined,
1425+
subject: subject
1426+
) {
1427+
let audioSession = await $0.context.coordinator?.stateAdapter.audioSession
1428+
XCTAssertNotNil(audioSession?.delegate)
1429+
}
1430+
cancellable.cancel()
1431+
}
1432+
13601433
func test_transition_fromMigratedSFUConnected_updatesParticipants() async throws {
13611434
subject.context.coordinator = mockCoordinatorStack.coordinator
13621435
subject.context.reconnectAttempts = 11

0 commit comments

Comments
 (0)