@@ -43,22 +43,56 @@ struct DefaultRoomReactionsTests {
4343 #expect( channel. lastMessagePublishedExtras as? Dictionary == [ " headers " : [ " someHeadersKey " : " someHeadersValue " ] ] )
4444 }
4545
46- // @spec CHA-ER4
46+ // @spec CHA-ER4a
4747 @Test
48- func subscribe_returnsSubscription( ) async throws {
49- // all setup values here are arbitrary
48+ func subscriptionCanBeRegisteredToReceiveReactionEvents( ) async throws {
5049 // Given
51- let channel = MockRealtimeChannel ( name: " basketball::$chat::$reactions " )
50+ let channel = MockRealtimeChannel (
51+ messageJSONToEmitOnSubscribe: [
52+ " name " : " roomReaction " ,
53+ " clientId " : " who-sent-the-message " ,
54+ " data " : [
55+ " type " : " :like: " ,
56+ " metadata " : [
57+ " foo " : " bar " ,
58+ ] ,
59+ ] ,
60+ " timestamp " : " 1726232498871 " ,
61+ " extras " : [
62+ " headers " : [
63+ " baz " : " qux " ,
64+ ] ,
65+ ] ,
66+ ] as? [ String : any Sendable ]
67+ )
5268 let featureChannel = MockFeatureChannel ( channel: channel)
69+ let defaultRoomReactions = await DefaultRoomReactions ( featureChannel: featureChannel, clientID: " mockClientId " , roomID: " basketball " , logger: TestLogger ( ) )
5370
5471 // When
72+ let reactionSubscription = await defaultRoomReactions. subscribe ( )
73+
74+ // Then
75+ let reaction = try #require( await reactionSubscription. first { _ in true } )
76+ #expect( reaction. type == " :like: " )
77+ }
78+
79+ // CHA-ER4c is currently untestable due to not subscribing to those events on lower level
80+ // @spec CHA-ER4d
81+ @Test
82+ func malformedRealtimeEventsShallNotBeEmittedToSubscribers( ) async throws {
83+ // Given
84+ let channel = MockRealtimeChannel (
85+ messageJSONToEmitOnSubscribe: [ " foo " : " bar " ] // malformed realtime message
86+ )
87+ let featureChannel = MockFeatureChannel ( channel: channel)
5588 let defaultRoomReactions = await DefaultRoomReactions ( featureChannel: featureChannel, clientID: " mockClientId " , roomID: " basketball " , logger: TestLogger ( ) )
5689
5790 // When
58- let subscription : Subscription < Reaction > ? = await defaultRoomReactions. subscribe ( )
91+ let malformedMessagesSubscription = await defaultRoomReactions. testsOnly_subscribeToMalformedMessageEvents ( )
92+ _ = await defaultRoomReactions. subscribe ( )
5993
6094 // Then
61- #expect ( subscription != nil )
95+ _ = try #require ( await malformedMessagesSubscription . first { _ in true } )
6296 }
6397
6498 // @spec CHA-ER5
0 commit comments