@@ -11,38 +11,58 @@ import XCTest
1111import  XCTestDynamicOverlay
1212
1313final  class  RealtimeChannelTests :  XCTestCase  { 
14-   var  sut :  RealtimeChannelV2 ! 
14+   let  sut   =  RealtimeChannelV2 ( 
15+     topic:  " topic " , 
16+     config:  RealtimeChannelConfig ( 
17+       broadcast:  BroadcastJoinConfig ( ) , 
18+       presence:  PresenceJoinConfig ( ) , 
19+       isPrivate:  false 
20+     ) , 
21+     socket:  . mock, 
22+     logger:  nil 
23+   ) 
1524
16-   func  testOnPostgresChange( )  { 
17-     sut =  RealtimeChannelV2 ( 
18-       topic:  " topic " , 
19-       config:  RealtimeChannelConfig ( 
20-         broadcast:  BroadcastJoinConfig ( ) , 
21-         presence:  PresenceJoinConfig ( ) , 
22-         isPrivate:  false 
23-       ) , 
24-       socket:  . mock, 
25-       logger:  nil 
26-     ) 
27-     var  subscriptions  =  Set < RealtimeChannelV2 . Subscription > ( ) 
28-     sut. onPostgresChange ( AnyAction . self)  {  _ in  } . store ( in:  & subscriptions) 
29-     sut. onPostgresChange ( InsertAction . self)  {  _ in  } . store ( in:  & subscriptions) 
30-     sut. onPostgresChange ( UpdateAction . self)  {  _ in  } . store ( in:  & subscriptions) 
31-     sut. onPostgresChange ( DeleteAction . self)  {  _ in  } . store ( in:  & subscriptions) 
25+   func  testAttachCallbacks( )  { 
26+     var  subscriptions  =  Set < RealtimeSubscription > ( ) 
27+ 
28+     sut. onPostgresChange ( 
29+       AnyAction . self, 
30+       schema:  " public " , 
31+       table:  " users " , 
32+       filter:  " id=eq.1 " 
33+     )  {  _ in  } . store ( in:  & subscriptions) 
34+     sut. onPostgresChange ( 
35+       InsertAction . self, 
36+       schema:  " private " 
37+     )  {  _ in  } . store ( in:  & subscriptions) 
38+     sut. onPostgresChange ( 
39+       UpdateAction . self, 
40+       table:  " messages " 
41+     )  {  _ in  } . store ( in:  & subscriptions) 
42+     sut. onPostgresChange ( 
43+       DeleteAction . self
44+     )  {  _ in  } . store ( in:  & subscriptions) 
45+ 
46+     sut. onBroadcast ( event:  " test " )  {  _ in  } . store ( in:  & subscriptions) 
47+     sut. onBroadcast ( event:  " cursor-pos " )  {  _ in  } . store ( in:  & subscriptions) 
48+ 
49+     sut. onPresenceChange  {  _ in  } . store ( in:  & subscriptions) 
3250
3351    assertInlineSnapshot ( of:  sut. callbackManager. callbacks,  as:  . dump)  { 
3452      """ 
35-       ▿ 4  elements 
53+       ▿ 7  elements 
3654        ▿ RealtimeCallback 
3755          ▿ postgres: PostgresCallback 
3856            - callback: (Function) 
3957            ▿ filter: PostgresJoinConfig 
4058              ▿ event: Optional<PostgresChangeEvent> 
4159                - some: PostgresChangeEvent.all 
42-               - filter: Optional<String>.none 
60+               ▿ filter: Optional<String> 
61+                 - some:  " id=eq.1 " 
4362              - id: 0 
4463              - schema:  " public " 
45-               - table: Optional<String>.none 
64+               ▿ table: Optional<String> 
65+                 - some:  " users " 
4666            - id: 1 
4767        ▿ RealtimeCallback 
4868          ▿ postgres: PostgresCallback 
@@ -52,7 +72,7 @@ final class RealtimeChannelTests: XCTestCase {
5272                - some: PostgresChangeEvent.insert 
5373              - filter: Optional<String>.none 
5474              - id: 0 
55-               - schema:  " public " 
75+               - schema:  " private " 
5676              - table: Optional<String>.none 
5777            - id: 2 
5878        ▿ RealtimeCallback 
@@ -64,7 +84,8 @@ final class RealtimeChannelTests: XCTestCase {
6484              - filter: Optional<String>.none 
6585              - id: 0 
6686              - schema:  " public " 
67-               - table: Optional<String>.none 
87+               ▿ table: Optional<String> 
88+                 - some:  " messages " 
6889            - id: 3 
6990        ▿ RealtimeCallback 
7091          ▿ postgres: PostgresCallback 
@@ -77,6 +98,20 @@ final class RealtimeChannelTests: XCTestCase {
7798              - schema:  " public " 
7899              - table: Optional<String>.none 
79100            - id: 4 
101+         ▿ RealtimeCallback 
102+           ▿ broadcast: BroadcastCallback 
103+             - callback: (Function) 
104+             - event:  " test " 
105+             - id: 5 
106+         ▿ RealtimeCallback 
107+           ▿ broadcast: BroadcastCallback 
108+             - callback: (Function) 
109+             - event:  " cursor-pos " 
110+             - id: 6 
111+         ▿ RealtimeCallback 
112+           ▿ presence: PresenceCallback 
113+             - callback: (Function) 
114+             - id: 7 
80115
81116       """ 
82117    } 
0 commit comments