Skip to content

Commit b7a8c95

Browse files
committed
Add more tests
1 parent bf8c7ed commit b7a8c95

File tree

3 files changed

+117
-2
lines changed

3 files changed

+117
-2
lines changed

StreamVideoTests/Call/Call_Tests.swift

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,45 @@ final class Call_Tests: StreamVideoTestCase {
475475

476476
XCTAssertEqual(mockCallController.timesCalled(.join), 1)
477477
}
478-
478+
479+
func test_join_stateContainsJoinSource_joinSourceWasPassedToCallController() async throws {
480+
let mockCallController = MockCallController()
481+
let call = MockCall(.dummy(callController: mockCallController))
482+
call.stub(for: \.state, with: .init())
483+
mockCallController.stub(for: .join, with: JoinCallResponse.dummy())
484+
485+
call.state.joinSource = .callKit
486+
_ = try await call.join()
487+
488+
XCTAssertEqual(
489+
mockCallController.recordedInputPayload(
490+
(Bool, CallSettings?, CreateCallOptions?, Bool, Bool, JoinSource).self,
491+
for: .join
492+
)?.first?.5,
493+
.callKit
494+
)
495+
}
496+
497+
func test_join_stateDoesNotJoinSource_joinSourceDefaultsToInAppAndWasPassedToCallController() async throws {
498+
let mockCallController = MockCallController()
499+
let call = MockCall(.dummy(callController: mockCallController))
500+
call.stub(for: \.state, with: .init())
501+
mockCallController.stub(for: .join, with: JoinCallResponse.dummy())
502+
503+
call.state.joinSource = nil
504+
_ = try await call.join()
505+
506+
XCTAssertEqual(
507+
mockCallController.recordedInputPayload(
508+
(Bool, CallSettings?, CreateCallOptions?, Bool, Bool, JoinSource).self,
509+
for: .join
510+
)?.first?.5,
511+
.inApp
512+
)
513+
}
514+
515+
// MARK: - updateParticipantsSorting
516+
479517
func test_call_customSorting() async throws {
480518
// Given
481519
let nameComparator: StreamSortComparator<CallParticipant> = {

StreamVideoTests/Utils/AudioSession/RTCAudioStore/RTCAudioStore_Tests.swift

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,37 @@ import XCTest
99

1010
final class RTCAudioStore_Tests: XCTestCase, @unchecked Sendable {
1111

12+
private final class SpyReducer: RTCAudioStoreReducer, @unchecked Sendable {
13+
var reduceError: Error?
14+
private(set) var reduceWasCalled: (state: RTCAudioStore.State, action: RTCAudioStoreAction, calledAt: Date)?
15+
func reduce(
16+
state: RTCAudioStore.State,
17+
action: RTCAudioStoreAction,
18+
file: StaticString,
19+
function: StaticString,
20+
line: UInt
21+
) throws -> RTCAudioStore.State {
22+
reduceWasCalled = (state, action, .init())
23+
guard let reduceError else {
24+
return state
25+
}
26+
throw reduceError
27+
}
28+
}
29+
30+
private final class SpyMiddleware: RTCAudioStoreMiddleware, @unchecked Sendable {
31+
private(set) var applyWasCalled: (state: RTCAudioStore.State, action: RTCAudioStoreAction, calledAt: Date)?
32+
func apply(
33+
state: RTCAudioStore.State,
34+
action: RTCAudioStoreAction,
35+
file: StaticString,
36+
function: StaticString,
37+
line: UInt
38+
) {
39+
applyWasCalled = (state, action, .init())
40+
}
41+
}
42+
1243
// MARK: - Properties
1344

1445
private lazy var subject: RTCAudioStore! = .init()
@@ -37,4 +68,49 @@ final class RTCAudioStore_Tests: XCTestCase, @unchecked Sendable {
3768
&& self.subject.state.isAudioEnabled == false
3869
}
3970
}
71+
72+
// MARK: - dispatch
73+
74+
func test_dispatch_middlewareWasCalledBeforeReducer() async throws {
75+
let reducer = SpyReducer()
76+
let middleware = SpyMiddleware()
77+
subject.add(reducer)
78+
subject.add(middleware)
79+
80+
subject.dispatch(.audioSession(.isActive(true)))
81+
await fulfillment { middleware.applyWasCalled != nil && reducer.reduceWasCalled != nil }
82+
83+
let middlewareWasCalledAt = try XCTUnwrap(middleware.applyWasCalled?.calledAt)
84+
let reducerWasCalledAt = try XCTUnwrap(reducer.reduceWasCalled?.calledAt)
85+
XCTAssertTrue(reducerWasCalledAt.timeIntervalSince(middlewareWasCalledAt) > 0)
86+
}
87+
88+
// MARK: - dispatchAsync
89+
90+
func test_dispatchAsync_middlewareWasCalledBeforeReducer() async throws {
91+
let reducer = SpyReducer()
92+
let middleware = SpyMiddleware()
93+
subject.add(reducer)
94+
subject.add(middleware)
95+
96+
try await subject.dispatchAsync(.audioSession(.isActive(true)))
97+
98+
let middlewareWasCalledAt = try XCTUnwrap(middleware.applyWasCalled?.calledAt)
99+
let reducerWasCalledAt = try XCTUnwrap(reducer.reduceWasCalled?.calledAt)
100+
XCTAssertTrue(reducerWasCalledAt.timeIntervalSince(middlewareWasCalledAt) > 0)
101+
}
102+
103+
func test_dispatchAsync_reducerThrowsError_rethrowsError() async throws {
104+
let expected = ClientError(.unique)
105+
let reducer = SpyReducer()
106+
reducer.reduceError = expected
107+
subject.add(reducer)
108+
109+
do {
110+
try await subject.dispatchAsync(.audioSession(.isActive(true)))
111+
XCTFail()
112+
} catch {
113+
XCTAssertEqual((error as? ClientError)?.localizedDescription, expected.localizedDescription)
114+
}
115+
}
40116
}

StreamVideoTests/WebRTC/v2/WebRTCCoorindator_Tests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ final class WebRTCCoordinator_Tests: XCTestCase, @unchecked Sendable {
7171
options: expectedOptions,
7272
ring: true,
7373
notify: true,
74-
source: .inApp
74+
source: .callKit
7575
)
7676
}
7777
) { stage in
@@ -84,6 +84,7 @@ final class WebRTCCoordinator_Tests: XCTestCase, @unchecked Sendable {
8484
XCTAssertEqual(expectedStage.options?.team, expectedOptions.team)
8585
XCTAssertTrue(expectedStage.ring)
8686
XCTAssertTrue(expectedStage.notify)
87+
XCTAssertEqual(expectedStage.context.joinSource, .callKit)
8788
await self.assertEqualAsync(
8889
await self.subject.stateAdapter.initialCallSettings,
8990
expectedCallSettings

0 commit comments

Comments
 (0)