@@ -29,20 +29,65 @@ struct DefaultRoomReactionsTests {
2929 #expect( channel. publishedMessages. last? . extras == [ " headers " : [ " someHeadersKey " : " someHeadersValue " ] , " ephemeral " : true ] )
3030 }
3131
32- // @spec CHA-ER4
32+ // @spec CHA-ER4a
3333 @Test
34- func subscribe_returnsSubscription( ) async throws {
35- // all setup values here are arbitrary
34+ func subscriptionCanBeRegisteredToReceiveReactionEvents( ) async throws {
3635 // Given
37- let channel = MockRealtimeChannel ( name: " basketball::$chat " )
36+ let channel = MockRealtimeChannel (
37+ messageJSONToEmitOnSubscribe: [
38+ " name " : " roomReaction " ,
39+ " clientId " : " who-sent-the-message " ,
40+ " data " : [
41+ " type " : " :like: " ,
42+ " metadata " : [
43+ " foo " : " bar " ,
44+ ] ,
45+ ] ,
46+ " timestamp " : " 1726232498871 " ,
47+ " extras " : [
48+ " headers " : [
49+ " baz " : " qux " ,
50+ ] ,
51+ ] ,
52+ ] as? [ String : any Sendable ]
53+ )
54+ let defaultRoomReactions = DefaultRoomReactions ( channel: channel, clientID: " mockClientId " , roomID: " basketball " , logger: TestLogger ( ) )
3855
3956 // When
57+ let reactionSubscription = defaultRoomReactions. subscribe { reaction in
58+ // Then
59+ #expect( reaction. type == " :like: " )
60+ }
61+ }
62+
63+ // CHA-ER4c is currently untestable due to not subscribing to those events on lower level
64+ // @spec CHA-ER4d
65+ @Test
66+ func malformedRealtimeEventsShallNotBeEmittedToSubscribers( ) async throws {
67+ // Given
68+ let channel = MockRealtimeChannel (
69+ messageJSONToEmitOnSubscribe: [
70+ " foo " : " bar " // malformed reaction message
71+ ] ,
72+ messageToEmitOnSubscribe: {
73+ let message = ARTMessage ( )
74+ message. action = . create // arbitrary
75+ message. serial = " 123 " // arbitrary
76+ message. clientId = " " // arbitrary
77+ message. data = [
78+ " type " : " :like: " ,
79+ ]
80+ message. extras = [ : ] as any ARTJsonCompatible
81+ message. version = " 0 "
82+ return message
83+ } ( )
84+ )
4085 let defaultRoomReactions = DefaultRoomReactions ( channel: channel, clientID: " mockClientId " , roomID: " basketball " , logger: TestLogger ( ) )
4186
4287 // When
43- let subscription : Subscription < Reaction > ? = defaultRoomReactions. subscribe ( )
44-
45- // Then
46- #expect ( subscription != nil )
88+ let reactionSubscription = defaultRoomReactions. subscribe { reaction in
89+ // Then: `messageJSONToEmitOnSubscribe` is processed ahead of `messageToEmitOnSubscribe` in the mock, but the first message is not the malformed one
90+ #expect ( reaction . type == " :like: " )
91+ }
4792 }
4893}
0 commit comments