-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathDataStoreTests.swift
75 lines (60 loc) · 2.02 KB
/
DataStoreTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import Foundation
import Testing
@testable import WordPress
@Suite(.timeLimit(.minutes(1)))
struct InMemoryDataStoreTests {
@Test
func testUpdatesAfterCreation() async {
let store = InMemoryDataStore<DisplayUser>()
let stream = await store.listStream(query: .all)
await confirmation("The stream produces an update") { confirmation in
for await _ in stream.prefix(1) {
confirmation()
}
}
}
@Test
func testUpdatesAfterStore() async {
let store = InMemoryDataStore<DisplayUser>()
let stream = await store.listStream(query: .all)
Task.detached {
try await Task.sleep(for: .milliseconds(50))
try await store.store([.MockUser])
}
await confirmation("The stream produces an update", expectedCount: 2) { confirmation in
for await _ in stream.prefix(2) {
confirmation()
}
}
}
@Test
func testUpdatesAfterDelete() async throws {
let store = InMemoryDataStore<DisplayUser>()
try await store.store([.MockUser])
let stream = await store.listStream(query: .all)
Task.detached {
try await Task.sleep(for: .milliseconds(50))
try await store.delete(query: .all)
}
await confirmation("The stream produces an update", expectedCount: 2) { confirmation in
for await _ in stream.prefix(2) {
confirmation()
}
}
}
@Test
func testStreamTerminates() async {
var store: InMemoryDataStore<DisplayUser>? = .init()
let stream = await store!.listStream(query: .all)
Task.detached {
try await Task.sleep(for: .milliseconds(50))
store = nil
}
await confirmation("The stream produces one update and then terminates", expectedCount: 1) { confirmation in
for await _ in stream {
// Do nothing
}
confirmation()
}
}
}