Skip to content

Commit 073b104

Browse files
Add another smoke test of the public API
Just to convince myself that the write API is somewhat working. Will get further confidence upon porting across more of the JS integration tests in the future.
1 parent f5f6294 commit 073b104

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

Tests/AblyLiveObjectsTests/AblyLiveObjectsTests.swift

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,67 @@ struct AblyLiveObjectsTests {
122122
#expect(invalidObjectThrownError.code == 92000)
123123
#expect(invalidObjectThrownError.message == "invalid object message: object operation required")
124124
}
125+
126+
/// A basic test of the public API of the LiveObjects plugin.
127+
@Test(arguments: [true, false])
128+
func smokeTest(useBinaryProtocol: Bool) async throws {
129+
let client = try await ClientHelper.realtimeWithObjects(options: .init(useBinaryProtocol: useBinaryProtocol))
130+
let channel = client.channels.get(UUID().uuidString, options: ClientHelper.channelOptionsWithObjects())
131+
try await channel.attachAsync()
132+
133+
let root = try await channel.objects.getRoot()
134+
let rootSubscription = try root.updates()
135+
136+
// Create a counter
137+
let counter = try await channel.objects.createCounter(count: 52)
138+
let counterSubscription = try counter.updates()
139+
140+
// Create a map and check its initial entries
141+
let map = try await channel.objects.createMap(entries: [
142+
"boolKey": .primitive(.bool(true)),
143+
"numberKey": .primitive(.number(10)),
144+
])
145+
#expect(
146+
try Dictionary(uniqueKeysWithValues: map.entries) == [
147+
"boolKey": .primitive(.bool(true)),
148+
"numberKey": .primitive(.number(10)),
149+
],
150+
)
151+
let mapSubscription = try map.updates()
152+
153+
// Perform a `set` on the root and check it comes through on subscription
154+
try await root.set(key: "mapKey", value: .liveMap(map))
155+
let rootUpdate = try #require(await rootSubscription.first { _ in true })
156+
#expect(rootUpdate.update == ["mapKey": .updated])
157+
#expect(try Dictionary(uniqueKeysWithValues: root.entries) == ["mapKey": .liveMap(map)])
158+
159+
// Perform a `set` on the map and check it comes through on subscription and that the map is updated
160+
try await map.set(key: "counterKey", value: .liveCounter(counter))
161+
let mapUpdate = try #require(await mapSubscription.first { _ in true })
162+
#expect(mapUpdate.update == ["counterKey": .updated])
163+
#expect(
164+
try Dictionary(uniqueKeysWithValues: map.entries) == [
165+
"boolKey": .primitive(.bool(true)),
166+
"numberKey": .primitive(.number(10)),
167+
"counterKey": .liveCounter(counter),
168+
],
169+
)
170+
171+
// Perform an `increment` on the counter and check it comes through on subscription and that the counter is updated
172+
try await counter.increment(amount: 30)
173+
let counterUpdate = try #require(await counterSubscription.first { _ in true })
174+
#expect(counterUpdate.amount == 30)
175+
#expect(try counter.value == 82)
176+
177+
// Perform a `remove` on the map and check it comes through on subscription and that the map is updated
178+
try await map.remove(key: "boolKey")
179+
let mapRemoveUpdate = try #require(await mapSubscription.first { _ in true })
180+
#expect(mapRemoveUpdate.update == ["boolKey": .removed])
181+
#expect(
182+
try Dictionary(uniqueKeysWithValues: map.entries) == [
183+
"numberKey": .primitive(.number(10)),
184+
"counterKey": .liveCounter(counter),
185+
],
186+
)
187+
}
125188
}

0 commit comments

Comments
 (0)