@@ -91,130 +91,130 @@ import XCTest
9191 await client. connect ( )
9292 }
9393
94- func testBehavior( ) async throws {
95- let channel = sut. channel ( " public:messages " )
96- var subscriptions : Set < ObservationToken > = [ ]
97-
98- channel. onPostgresChange ( InsertAction . self, table: " messages " ) { _ in
99- }
100- . store ( in: & subscriptions)
101-
102- channel. onPostgresChange ( UpdateAction . self, table: " messages " ) { _ in
103- }
104- . store ( in: & subscriptions)
105-
106- channel. onPostgresChange ( DeleteAction . self, table: " messages " ) { _ in
107- }
108- . store ( in: & subscriptions)
109-
110- let socketStatuses = LockIsolated ( [ RealtimeClientStatus] ( ) )
111-
112- sut. onStatusChange { status in
113- socketStatuses. withValue { $0. append ( status) }
114- }
115- . store ( in: & subscriptions)
116-
117- // Set up server to respond to heartbeats
118- server. onEvent = { @Sendable [ server] event in
119- guard let msg = event. realtimeMessage else { return }
120-
121- if msg. event == " heartbeat " {
122- server? . send (
123- RealtimeMessageV2 (
124- joinRef: msg. joinRef,
125- ref: msg. ref,
126- topic: " phoenix " ,
127- event: " phx_reply " ,
128- payload: [ " response " : [ : ] ]
129- )
130- )
131- }
132- }
133-
134- await waitUntil {
135- socketStatuses. value. count >= 3
136- }
137-
138- XCTAssertEqual (
139- Array ( socketStatuses. value. prefix ( 3 ) ) ,
140- [ . disconnected, . connecting, . connected]
141- )
142-
143- let messageTask = sut. mutableState. messageTask
144- XCTAssertNotNil ( messageTask)
145-
146- let heartbeatTask = sut. mutableState. heartbeatTask
147- XCTAssertNotNil ( heartbeatTask)
148-
149- let channelStatuses = LockIsolated ( [ RealtimeChannelStatus] ( ) )
150- channel. onStatusChange { status in
151- channelStatuses. withValue {
152- $0. append ( status)
153- }
154- }
155- . store ( in: & subscriptions)
156-
157- let subscribeTask = Task {
158- try await channel. subscribeWithError ( )
159- }
160- await Task . yield ( )
161- server. send ( . messagesSubscribed)
162-
163- // Wait until it subscribes to assert WS events
164- do {
165- try await subscribeTask. value
166- } catch {
167- XCTFail ( " Expected .subscribed but got error: \( error) " )
168- }
169- XCTAssertEqual ( channelStatuses. value, [ . unsubscribed, . subscribing, . subscribed] )
170-
171- assertInlineSnapshot ( of: client. sentEvents. map ( \. json) , as: . json) {
172- #"""
173- [
174- {
175- "text" : {
176- "event" : "phx_join",
177- "join_ref" : "1",
178- "payload" : {
179- "access_token" : "custom.access.token",
180- "config" : {
181- "broadcast" : {
182- "ack" : false,
183- "self" : false
184- },
185- "postgres_changes" : [
186- {
187- "event" : "INSERT",
188- "schema" : "public",
189- "table" : "messages"
190- },
191- {
192- "event" : "UPDATE",
193- "schema" : "public",
194- "table" : "messages"
195- },
196- {
197- "event" : "DELETE",
198- "schema" : "public",
199- "table" : "messages"
200- }
201- ],
202- "presence" : {
203- "enabled" : false,
204- "key" : ""
205- },
206- "private" : false
207- },
208- "version" : "realtime-swift\/0.0.0"
209- },
210- "ref" : "1",
211- "topic" : "realtime:public:messages"
212- }
213- }
214- ]
215- """#
216- }
217- }
94+ // func testBehavior() async throws {
95+ // let channel = sut.channel("public:messages")
96+ // var subscriptions: Set<ObservationToken> = []
97+ //
98+ // channel.onPostgresChange(InsertAction.self, table: "messages") { _ in
99+ // }
100+ // .store(in: &subscriptions)
101+ //
102+ // channel.onPostgresChange(UpdateAction.self, table: "messages") { _ in
103+ // }
104+ // .store(in: &subscriptions)
105+ //
106+ // channel.onPostgresChange(DeleteAction.self, table: "messages") { _ in
107+ // }
108+ // .store(in: &subscriptions)
109+ //
110+ // let socketStatuses = LockIsolated([RealtimeClientStatus]())
111+ //
112+ // sut.onStatusChange { status in
113+ // socketStatuses.withValue { $0.append(status) }
114+ // }
115+ // .store(in: &subscriptions)
116+ //
117+ // // Set up server to respond to heartbeats
118+ // server.onEvent = { @Sendable [server] event in
119+ // guard let msg = event.realtimeMessage else { return }
120+ //
121+ // if msg.event == "heartbeat" {
122+ // server?.send(
123+ // RealtimeMessageV2(
124+ // joinRef: msg.joinRef,
125+ // ref: msg.ref,
126+ // topic: "phoenix",
127+ // event: "phx_reply",
128+ // payload: ["response": [:]]
129+ // )
130+ // )
131+ // }
132+ // }
133+ //
134+ // await waitUntil {
135+ // socketStatuses.value.count >= 3
136+ // }
137+ //
138+ // XCTAssertEqual(
139+ // Array(socketStatuses.value.prefix(3)),
140+ // [.disconnected, .connecting, .connected]
141+ // )
142+ //
143+ // let messageTask = sut.mutableState.messageTask
144+ // XCTAssertNotNil(messageTask)
145+ //
146+ // let heartbeatTask = sut.mutableState.heartbeatTask
147+ // XCTAssertNotNil(heartbeatTask)
148+ //
149+ // let channelStatuses = LockIsolated([RealtimeChannelStatus]())
150+ // channel.onStatusChange { status in
151+ // channelStatuses.withValue {
152+ // $0.append(status)
153+ // }
154+ // }
155+ // .store(in: &subscriptions)
156+ //
157+ // let subscribeTask = Task {
158+ // try await channel.subscribeWithError()
159+ // }
160+ // await Task.yield()
161+ // server.send(.messagesSubscribed)
162+ //
163+ // // Wait until it subscribes to assert WS events
164+ // do {
165+ // try await subscribeTask.value
166+ // } catch {
167+ // XCTFail("Expected .subscribed but got error: \(error)")
168+ // }
169+ // XCTAssertEqual(channelStatuses.value, [.unsubscribed, .subscribing, .subscribed])
170+ //
171+ // assertInlineSnapshot(of: client.sentEvents.map(\.json), as: .json) {
172+ // #"""
173+ // [
174+ // {
175+ // "text" : {
176+ // "event" : "phx_join",
177+ // "join_ref" : "1",
178+ // "payload" : {
179+ // "access_token" : "custom.access.token",
180+ // "config" : {
181+ // "broadcast" : {
182+ // "ack" : false,
183+ // "self" : false
184+ // },
185+ // "postgres_changes" : [
186+ // {
187+ // "event" : "INSERT",
188+ // "schema" : "public",
189+ // "table" : "messages"
190+ // },
191+ // {
192+ // "event" : "UPDATE",
193+ // "schema" : "public",
194+ // "table" : "messages"
195+ // },
196+ // {
197+ // "event" : "DELETE",
198+ // "schema" : "public",
199+ // "table" : "messages"
200+ // }
201+ // ],
202+ // "presence" : {
203+ // "enabled" : false,
204+ // "key" : ""
205+ // },
206+ // "private" : false
207+ // },
208+ // "version" : "realtime-swift\/0.0.0"
209+ // },
210+ // "ref" : "1",
211+ // "topic" : "realtime:public:messages"
212+ // }
213+ // }
214+ // ]
215+ // """#
216+ // }
217+ // }
218218
219219 func testSubscribeTimeout( ) async throws {
220220 let channel = sut. channel ( " public:messages " )
0 commit comments