Commit 5cf7e8d
improvement(codebase): migrate tests to dbChainMock, extract react-query hooks (#4235)
* improvement(codebase): migrate tests to dbChainMock, extract react-query hooks
Migrate 97 test files to centralized dbChainMock/dbChainMockFns helpers from
@sim/testing — removes hoisted chain-wiring boilerplate.
Extend dbChainMock to cover insert/update/delete/transaction/execute patterns.
Extract useGitHubStars and useVoiceSettings react-query hooks from inline fetches.
Centralize additional mocks (authMockFns, hybridAuthMockFns) and update docs.
* fix(github-stars): centralize fallback via initialData, remove stale constants
Move the placeholder star count into useGitHubStars as initialData with
initialDataUpdatedAt: 0 so `data` is always a narrowed string while still
refetching on mount. Fixes two Bugbot issues: stale '25.8k' in chat.tsx
(vs '27.8k' in navbar) and empty-string return in fetchGitHubStars that
bypassed `??` fallbacks in consumers.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(testing): wire dbChainMock.db to shared transaction and execute fns
dbChainMock.db.transaction was an inline vi.fn() separate from the exported
dbChainMockFns.transaction, so dbChainMockFns.transaction.mockResolvedValueOnce
and assertions silently targeted the wrong instance. dbChainMock.db also
omitted execute, so tests for any module that calls db.execute (logging-session,
table service, billing balance) would throw TypeError. Both mocks now reference
the module-level constants so overrides and resetDbChainMock affect the same fn.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(chat,testing): memoize welcome message and add selectDistinct to dbChainMock.db
Why:
- Welcome ChatMessage was rebuilt inline each render, producing a fresh
timestamp and new array identity — cascading to ChatMessageContainer
and VoiceInterface props on every tick.
- dbChainMockFns exports selectDistinct/selectDistinctOn but the
dbChainMock.db object omitted them, so tests that stub those builders
hit undefined on the mocked module.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(chat): re-attach scroll listener once container mounts
The scroll effect's empty dep array meant it ran only on the first
render, when `chatConfig` is still loading and the component returns
`<ChatLoadingState />` — so `messagesContainerRef.current` was null and
the listener was never attached. Depend on the gating conditions that
control which tree renders, so the effect re-runs once the real
container is in the DOM (and re-attaches when toggling in/out of voice
mode).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(chat): reset chat state on identifier change via key prop
Keying `<ChatClient>` on `identifier` guarantees a full remount on
route transitions between chats, so `conversationId`, `messages`, and
every other piece of local state start fresh — no reset effect
required.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent 1ced54a commit 5cf7e8d
File tree
100 files changed
+972
-1451
lines changed- .claude/rules
- .cursor/rules
- apps/sim
- app
- (landing)
- actions
- api
- auth/oauth
- connections
- credentials
- disconnect
- token
- chat
- [identifier]
- otp
- manage/[id]
- copilot
- api-keys
- chats
- chat
- delete
- stop
- update-messages
- checkpoints
- revert
- feedback
- files
- delete
- parse
- presigned
- serve/[...path]
- upload
- folders
- [id]
- function/execute
- jobs/[jobId]
- knowledge
- [id]
- connectors/[connectorId]
- documents
- sync
- documents
- [documentId]
- search
- mcp
- events
- serve/[serverId]
- schedules
- [id]
- execute
- table/[tableId]/import-csv
- tools
- crowdstrike/query
- custom
- webhooks/trigger/[path]
- workflows
- [id]
- chat/status
- execute
- executions/[executionId]/cancel
- form/status
- variables
- workspaces
- [id]
- docx/preview
- pdf/preview
- pptx/preview
- invitations
- [invitationId]
- chat
- [identifier]
- components/auth
- email
- password
- background
- ee/access-control/utils
- executor/handlers
- agent
- condition
- hooks/queries
- lib
- audit
- billing
- credits
- webhooks
- copilot
- async-runs
- chat
- request/handlers
- validation
- execution
- knowledge/connectors
- logs/execution
- snapshot
- messaging/email
- table/__tests__
- webhooks
- providers
- workflows
- persistence
- workspaces
- permissions
- socket/middleware
- packages/testing/src/mocks
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
100 files changed
+972
-1451
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
192 | 196 | | |
193 | 197 | | |
194 | 198 | | |
| 199 | + | |
| 200 | + | |
195 | 201 | | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
| 202 | + | |
201 | 203 | | |
202 | | - | |
203 | | - | |
204 | | - | |
| 204 | + | |
| 205 | + | |
205 | 206 | | |
206 | 207 | | |
207 | | - | |
208 | | - | |
209 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
210 | 216 | | |
211 | 217 | | |
212 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
213 | 231 | | |
214 | 232 | | |
215 | 233 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
This file was deleted.
Lines changed: 2 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | 3 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
| 4 | + | |
11 | 5 | | |
12 | 6 | | |
13 | 7 | | |
| |||
16 | 10 | | |
17 | 11 | | |
18 | 12 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 13 | + | |
28 | 14 | | |
29 | 15 | | |
30 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
7 | 13 | | |
8 | 14 | | |
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 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
35 | 20 | | |
36 | 21 | | |
37 | | - | |
| 22 | + | |
38 | 23 | | |
39 | 24 | | |
40 | 25 | | |
| |||
48 | 33 | | |
49 | 34 | | |
50 | 35 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | 36 | | |
56 | 37 | | |
57 | 38 | | |
| |||
61 | 42 | | |
62 | 43 | | |
63 | 44 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 45 | + | |
68 | 46 | | |
69 | 47 | | |
70 | 48 | | |
| |||
98 | 76 | | |
99 | 77 | | |
100 | 78 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 79 | + | |
| 80 | + | |
109 | 81 | | |
110 | 82 | | |
111 | 83 | | |
| |||
138 | 110 | | |
139 | 111 | | |
140 | 112 | | |
141 | | - | |
142 | 113 | | |
143 | 114 | | |
144 | 115 | | |
145 | 116 | | |
146 | 117 | | |
147 | 118 | | |
148 | 119 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 120 | + | |
| 121 | + | |
157 | 122 | | |
158 | 123 | | |
159 | 124 | | |
| |||
169 | 134 | | |
170 | 135 | | |
171 | 136 | | |
172 | | - | |
173 | | - | |
174 | | - | |
| 137 | + | |
175 | 138 | | |
176 | 139 | | |
177 | 140 | | |
| |||
180 | 143 | | |
181 | 144 | | |
182 | 145 | | |
183 | | - | |
184 | 146 | | |
185 | 147 | | |
186 | 148 | | |
| |||
204 | 166 | | |
205 | 167 | | |
206 | 168 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
| 169 | + | |
| 170 | + | |
215 | 171 | | |
216 | 172 | | |
217 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 7 | + | |
15 | 8 | | |
16 | 9 | | |
17 | 10 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | 11 | | |
38 | 12 | | |
39 | 13 | | |
| |||
42 | 16 | | |
43 | 17 | | |
44 | 18 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | 19 | | |
52 | 20 | | |
53 | 21 | | |
| |||
73 | 41 | | |
74 | 42 | | |
75 | 43 | | |
76 | | - | |
77 | 44 | | |
78 | 45 | | |
79 | 46 | | |
| |||
90 | 57 | | |
91 | 58 | | |
92 | 59 | | |
93 | | - | |
94 | 60 | | |
95 | 61 | | |
96 | 62 | | |
| |||
0 commit comments