Commit 7bd650d
committed
refactor(mock-builders,tests): return LocalMessage from generateMessage
The mock-builder `generateMessage` produces `LocalMessage`-shaped data
at runtime (Date objects for `created_at`/`updated_at`/`pinned_at`,
`deleted_at: null`), so typing the return as `MessageResponse` was a
lie that forced test files to paper over it with `as unknown as
LocalMessage` everywhere.
- Mock-builders now return `LocalMessage`:
- generator/message: returns `LocalMessage`, adds `deleted_at: null`,
`pinned_at: null`, `status: 'received'`; uses Date objects for
the date fields (matches `LocalMessage` type); `message_text_
updated_at` stays ISO string (still on `MessageResponseBase`).
- API mocks and event dispatchers accept `MessageResponse | LocalMessage`:
- api/{sendMessage,deleteMessage,sendReaction,deleteReaction,
threadReplies,getOrCreateChannel}.ts
- event/{messageNew,messageDeleted,messageUpdated,reactionNew,
reactionDeleted,reactionUpdated}.ts (cast to `MessageResponse` at
the Event payload boundary — that's where the wire-shape mismatch
actually happens).
- generator/channel: `GeneratedChannelResponseCustomValues.messages`
widened to accept both.
- Test files cleaned up:
- Removed 33 `as unknown as LocalMessage` / `as unknown as
LocalMessage[]` casts. The message value flows through without
rewrapping.
- Removed `toLocalMessage` / `toLocalMessages` wrapper helpers (57
call sites across 3 files) — no longer needed.
- Replaced 13 `{...({...} as unknown as ComponentProps<typeof X>)}`
spread+cast patterns with direct prop passing. The spread was
hiding props that weren't actually accepted by the target
component (dead props from pre-migration JS).
Dead props removed (all verified by reading each component's prop
type):
- `MessageAuthor`: `alignment`, `groupStyles` (live on
`MessageContextValue` but `MessageAuthor` doesn't pick them).
- `MessageReplies`: `groupStyles`, `MessageRepliesAvatars`
(component override, comes via `ComponentsContext`), `openThread`
(typo — actual prop is `onOpenThread`).
- `Message`: `reactionsEnabled`, `MessageFooter` (override, goes
through `WithComponents`).
- `ScrollToBottomButton`: `t` (supplied via `TranslationProvider`).
- `ChannelPreviewView`: `client`, `latestMessagePreview`, `watchers`,
`latestMessage`, `latestMessageLength` (none are real props).
- `Giphy` test helper: tightened `props: Record<string, unknown>` to
`props: ComponentProps<typeof Giphy>` so callers are type-checked.
Other fixups:
- `ownCapabilities.test.tsx`: helper arg `targetMessage:
MessageResponse` -> `LocalMessage`.
- `useMessageListPagination.test.tsx`: `initialMessages` and
`channelUnreadState` / `targetedMessageId` callback args retyped to
`LocalMessage[]`.
- `optimistic-update.tsx`: `allMessages: LocalMessage[]`.
- `isAttachmentEqualHandler.test.tsx`: drop stale
`as unknown as string` on `updated_at: new Date()`.
- `useMessageListPagination.test.tsx`: drop stale
`as unknown as string` on `created_at`.
- Thread.test.tsx snapshot updated: missing optional
`quoted_message: null` / `reaction_groups: null` keys were artifacts
of the SDK's old `formatMessage` normalization. The current
`LocalMessage` type declares them optional; same runtime data.
test:typecheck: 0 errors. Full suite: same pre-existing SQLite flake,
no regressions.1 parent 1466189 commit 7bd650d
39 files changed
Lines changed: 227 additions & 345 deletions
File tree
- package/src
- __tests__/offline-support
- components
- Attachment/__tests__
- ChannelPreview/__tests__
- Channel/__tests__
- ImageGallery
- __tests__
- components/__tests__
- MessageList/__tests__
- MessageMenu/__tests__
- Message/MessageItemView/__tests__
- Thread/__tests__
- __snapshots__
- contexts/messageInputContext/__tests__
- mock-builders
- api
- event
- generator
- state-store/__tests__
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
31 | | - | |
| 30 | + | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
| |||
Lines changed: 4 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 12 | + | |
18 | 13 | | |
19 | 14 | | |
20 | 15 | | |
| |||
47 | 42 | | |
48 | 43 | | |
49 | 44 | | |
50 | | - | |
| 45 | + | |
51 | 46 | | |
52 | 47 | | |
53 | | - | |
| 48 | + | |
54 | 49 | | |
55 | 50 | | |
56 | 51 | | |
| |||
64 | 59 | | |
65 | 60 | | |
66 | 61 | | |
67 | | - | |
| 62 | + | |
68 | 63 | | |
69 | 64 | | |
70 | 65 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
396 | | - | |
| 396 | + | |
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
402 | | - | |
| 402 | + | |
403 | 403 | | |
404 | | - | |
| 404 | + | |
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
| |||
569 | 569 | | |
570 | 570 | | |
571 | 571 | | |
572 | | - | |
| 572 | + | |
573 | 573 | | |
574 | 574 | | |
575 | 575 | | |
| |||
Lines changed: 3 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
| 24 | + | |
43 | 25 | | |
44 | 26 | | |
45 | 27 | | |
| |||
63 | 45 | | |
64 | 46 | | |
65 | 47 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 48 | + | |
74 | 49 | | |
75 | 50 | | |
76 | 51 | | |
| |||
115 | 90 | | |
116 | 91 | | |
117 | 92 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
| 93 | + | |
126 | 94 | | |
127 | 95 | | |
128 | 96 | | |
| |||
Lines changed: 10 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
100 | 98 | | |
101 | 99 | | |
102 | 100 | | |
| |||
111 | 109 | | |
112 | 110 | | |
113 | 111 | | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
119 | 115 | | |
120 | 116 | | |
121 | 117 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
0 commit comments