|
| 1 | +// |
| 2 | +// RealtimeChannelTests.swift |
| 3 | +// Supabase |
| 4 | +// |
| 5 | +// Created by Guilherme Souza on 09/09/24. |
| 6 | +// |
| 7 | + |
| 8 | +import InlineSnapshotTesting |
| 9 | +@testable import Realtime |
| 10 | +import XCTest |
| 11 | +import XCTestDynamicOverlay |
| 12 | + |
| 13 | +final class RealtimeChannelTests: XCTestCase { |
| 14 | + var sut: RealtimeChannelV2! |
| 15 | + |
| 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) |
| 32 | + |
| 33 | + assertInlineSnapshot(of: sut.callbackManager.callbacks, as: .dump) { |
| 34 | + """ |
| 35 | + ▿ 4 elements |
| 36 | + ▿ RealtimeCallback |
| 37 | + ▿ postgres: PostgresCallback |
| 38 | + - callback: (Function) |
| 39 | + ▿ filter: PostgresJoinConfig |
| 40 | + ▿ event: Optional<PostgresChangeEvent> |
| 41 | + - some: PostgresChangeEvent.all |
| 42 | + - filter: Optional<String>.none |
| 43 | + - id: 0 |
| 44 | + - schema: "public" |
| 45 | + - table: Optional<String>.none |
| 46 | + - id: 1 |
| 47 | + ▿ RealtimeCallback |
| 48 | + ▿ postgres: PostgresCallback |
| 49 | + - callback: (Function) |
| 50 | + ▿ filter: PostgresJoinConfig |
| 51 | + ▿ event: Optional<PostgresChangeEvent> |
| 52 | + - some: PostgresChangeEvent.insert |
| 53 | + - filter: Optional<String>.none |
| 54 | + - id: 0 |
| 55 | + - schema: "public" |
| 56 | + - table: Optional<String>.none |
| 57 | + - id: 2 |
| 58 | + ▿ RealtimeCallback |
| 59 | + ▿ postgres: PostgresCallback |
| 60 | + - callback: (Function) |
| 61 | + ▿ filter: PostgresJoinConfig |
| 62 | + ▿ event: Optional<PostgresChangeEvent> |
| 63 | + - some: PostgresChangeEvent.update |
| 64 | + - filter: Optional<String>.none |
| 65 | + - id: 0 |
| 66 | + - schema: "public" |
| 67 | + - table: Optional<String>.none |
| 68 | + - id: 3 |
| 69 | + ▿ RealtimeCallback |
| 70 | + ▿ postgres: PostgresCallback |
| 71 | + - callback: (Function) |
| 72 | + ▿ filter: PostgresJoinConfig |
| 73 | + ▿ event: Optional<PostgresChangeEvent> |
| 74 | + - some: PostgresChangeEvent.delete |
| 75 | + - filter: Optional<String>.none |
| 76 | + - id: 0 |
| 77 | + - schema: "public" |
| 78 | + - table: Optional<String>.none |
| 79 | + - id: 4 |
| 80 | +
|
| 81 | + """ |
| 82 | + } |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +extension Socket { |
| 87 | + static var mock: Socket { |
| 88 | + Socket( |
| 89 | + broadcastURL: unimplemented(), |
| 90 | + status: unimplemented(), |
| 91 | + options: unimplemented(), |
| 92 | + accessToken: unimplemented(), |
| 93 | + apiKey: unimplemented(), |
| 94 | + makeRef: unimplemented(), |
| 95 | + connect: unimplemented(), |
| 96 | + addChannel: unimplemented(), |
| 97 | + removeChannel: unimplemented(), |
| 98 | + push: unimplemented(), |
| 99 | + httpSend: unimplemented() |
| 100 | + ) |
| 101 | + } |
| 102 | +} |
0 commit comments