Commit 3215a12
authored
improvement(testing): consolidate @sim/db mocks into one table-aware chain mock (#5856)
* improvement(testing): consolidate @sim/db mocks into one table-aware chain mock
- back databaseMock and dbChainMock with the SAME db instance so a module
bound to either export hits identical chain fns — rival-mock divergence
between the two @sim/testing db mocks is structurally impossible now
- add queueTableRows(table, rows): FIFO per-table select routing keyed by
schema-mock table identity, consumed at where() materialization and
resolved by every downstream terminal (limit/orderBy/groupBy/for/joins)
- delete createMockDb (duplicate chain implementation, no external users)
- migrate the five suites that hand-rolled table routing + databaseMock
delegation (billing plan/usage/usage-log, admin dashboard-organizations,
workspaces/utils) onto queueTableRows; net -295 lines
- add a contract test for the mock itself and a test script to
@sim/testing so its tests actually run under turbo
* fix(testing): harden table routing — join-table queues, direct-await from, mutation isolation
- track the chain's tables as a list (from + joins) so rows queued for a
join-only table route correctly; from-table queue checked first
- make the from/join builder a lazy thenable so awaiting a select with no
where clause resolves queued rows (dequeue at await, never double-consumed)
- update/delete/set clear the routing context so a mutation's where() can
never consume rows queued for a select
- document the left-to-right chain-construction assumption; contract tests
for all three behaviors
* fix(testing): close routing over each chain's own tables for direct-await builders
* refactor(testing): move all chain routing state into per-chain closures
- shared dbChainMockFns entries become pure spy/override ports: their default
implementation returns a sentinel that chain-local builders replace, while
any mock* override on the spy wins verbatim
- each select().from() captures its own immutable table list; where(),
joins, terminals, and direct awaits all resolve through that closure, so
partially-built chains for different tables interleave without cross-talk
- no module-level routing state remains
* fix(testing): lazy queue consumption at resolution and wrapper restore on reset
- each chain holds one lazy rows supplier: the queued set is dequeued only
when a default thenable actually resolves, so a chain answered by a
per-test terminal override leaves its queued rows for the next chain
- resetDbChainMock also mockReset()s the stable db entry-point wrappers so
direct overrides on databaseMock.db.* cannot outlive a suite1 parent ae7b5ef commit 3215a12
9 files changed
Lines changed: 488 additions & 572 deletions
File tree
- apps/sim/lib
- admin
- billing/core
- workspaces
- packages/testing
- src/mocks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | 10 | | |
14 | 11 | | |
15 | 12 | | |
| |||
65 | 62 | | |
66 | 63 | | |
67 | 64 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | 65 | | |
138 | 66 | | |
139 | | - | |
140 | 67 | | |
141 | 68 | | |
142 | 69 | | |
| |||
173 | 100 | | |
174 | 101 | | |
175 | 102 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | 103 | | |
182 | 104 | | |
183 | 105 | | |
184 | 106 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
218 | 138 | | |
219 | 139 | | |
220 | 140 | | |
| |||
231 | 151 | | |
232 | 152 | | |
233 | 153 | | |
234 | | - | |
235 | | - | |
| 154 | + | |
| 155 | + | |
236 | 156 | | |
237 | 157 | | |
0 commit comments