Skip to content

Commit 5c7327a

Browse files
committed
Fixed MockTyping and MockTyping to use mockSubscription for generating user events.
1 parent 7a70359 commit 5c7327a

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

Example/AblyChatExample/Mocks/MockSubscriptions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ struct MockPresenceSubscription: Sendable, AsyncSequence {
137137
private let stream: AsyncStream<Element>
138138
private let continuation: AsyncStream<Element>.Continuation
139139

140-
func emitPresenceEvent() {
141-
let presence = PresenceEvent(action: [.enter, .leave].randomElement()!,
142-
clientID: MockStrings.names.randomElement()!,
140+
func emitPresenceEvent(clientID: String, event: PresenceEventType) {
141+
let presence = PresenceEvent(action: event,
142+
clientID: clientID,
143143
timestamp: Date(),
144144
data: nil)
145145
continuation.yield(presence)
@@ -149,7 +149,7 @@ struct MockPresenceSubscription: Sendable, AsyncSequence {
149149
Task {
150150
while (true) {
151151
try? await Task.sleep(nanoseconds: 5 * 1_000_000_000)
152-
emitPresenceEvent()
152+
emitPresenceEvent(clientID: MockStrings.names.randomElement()!, event: [.enter, .leave].randomElement()!)
153153
}
154154
}
155155
}

Example/AblyChatExample/Mocks/Mocks.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,29 @@ actor MockTyping: Typing {
142142
let roomID: String
143143
let channel: RealtimeChannel
144144

145+
private var mockSubscription: MockTypingSubscription
146+
145147
init(clientID: String, roomID: String) {
146148
self.clientID = clientID
147149
self.roomID = roomID
148150
self.channel = MockRealtimeChannel()
151+
self.mockSubscription = MockTypingSubscription(clientID: clientID, roomID: roomID)
149152
}
150153

151154
func subscribe(bufferingPolicy: BufferingPolicy) -> Subscription<TypingEvent> {
152-
.init(mockAsyncSequence: MockTypingSubscription(clientID: clientID, roomID: roomID))
155+
.init(mockAsyncSequence: mockSubscription)
153156
}
154157

155158
func get() async throws -> Set<String> {
156159
Set(MockStrings.names.prefix(2))
157160
}
158161

159162
func start() async throws {
160-
fatalError("Not yet implemented")
163+
mockSubscription.emit()
161164
}
162165

163166
func stop() async throws {
164-
fatalError("Not yet implemented")
167+
mockSubscription.emit()
165168
}
166169

167170
func subscribeToDiscontinuities() async -> Subscription<ARTErrorInfo> {
@@ -173,9 +176,12 @@ actor MockPresence: Presence {
173176
let clientID: String
174177
let roomID: String
175178

179+
private var mockSubscription: MockPresenceSubscription
180+
176181
init(clientID: String, roomID: String) {
177182
self.clientID = clientID
178183
self.roomID = roomID
184+
self.mockSubscription = MockPresenceSubscription(clientID: clientID, roomID: roomID)
179185
}
180186

181187
func get() async throws -> any PaginatedResult<PresenceMember> {
@@ -191,11 +197,11 @@ actor MockPresence: Presence {
191197
}
192198

193199
func enter() async throws {
194-
fatalError("Not yet implemented")
200+
mockSubscription.emitPresenceEvent(clientID: clientID, event: .enter)
195201
}
196202

197203
func enter(data: PresenceData) async throws {
198-
fatalError("Not yet implemented")
204+
mockSubscription.emitPresenceEvent(clientID: clientID, event: .enter)
199205
}
200206

201207
func update() async throws {
@@ -207,19 +213,19 @@ actor MockPresence: Presence {
207213
}
208214

209215
func leave() async throws {
210-
fatalError("Not yet implemented")
216+
mockSubscription.emitPresenceEvent(clientID: clientID, event: .leave)
211217
}
212218

213219
func leave(data: PresenceData) async throws {
214-
fatalError("Not yet implemented")
220+
mockSubscription.emitPresenceEvent(clientID: clientID, event: .leave)
215221
}
216222

217223
func subscribe(event: PresenceEventType) -> Subscription<PresenceEvent> {
218-
.init(mockAsyncSequence: MockPresenceSubscription(clientID: clientID, roomID: roomID))
224+
.init(mockAsyncSequence: mockSubscription)
219225
}
220226

221227
func subscribe(events: [PresenceEventType]) -> Subscription<PresenceEvent> {
222-
.init(mockAsyncSequence: MockPresenceSubscription(clientID: clientID, roomID: roomID))
228+
.init(mockAsyncSequence: mockSubscription)
223229
}
224230

225231
func subscribeToDiscontinuities() async -> Subscription<ARTErrorInfo> {

0 commit comments

Comments
 (0)