-
Notifications
You must be signed in to change notification settings - Fork 368
chore(llc): add type safety in extraData getters #2274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(llc): add type safety in extraData getters #2274
Conversation
WalkthroughType-safe getters were introduced for several properties in the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ChannelModel
participant User
Client->>ChannelModel: Access .name/.disabled/.hidden/.truncatedAt
ChannelModel->>ChannelModel: Use safeCast<T>() on extraData values
ChannelModel-->>Client: Return validated value or null
Client->>User: Access .name/.image
User->>User: Use safeCast<T>() on extraData values
User-->>Client: Return validated value or fallback (id/null)
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (11)
🔇 Additional comments (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/stream_chat/test/src/core/models/user_test.dart (1)
406-440
: Comprehensive test coverage for the.image
getter type safety.The test cases thoroughly validate the type-safe
.image
getter behavior:
- Valid string URL from extraData
- Missing key returns null
- Wrong type returns null
- Empty string returns null
However, there's a minor issue in one test case:
- extraData: const {'image': bool}, + extraData: const {'image': true},The current test uses
bool
(a Type) instead of a boolean value, which may not represent the intended test scenario.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
packages/stream_chat/lib/src/core/models/channel_model.dart
(2 hunks)packages/stream_chat/lib/src/core/models/user.dart
(1 hunks)packages/stream_chat/test/src/core/models/channel_test.dart
(2 hunks)packages/stream_chat/test/src/core/models/user_test.dart
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
- GitHub Check: test
- GitHub Check: build (android)
- GitHub Check: build (ios)
- GitHub Check: analyze
- GitHub Check: format
- GitHub Check: analyze_legacy_versions
- GitHub Check: stream_chat_localizations
- GitHub Check: stream_chat_flutter
- GitHub Check: stream_chat
- GitHub Check: stream_chat_flutter_core
- GitHub Check: stream_chat_persistence
🔇 Additional comments (9)
packages/stream_chat/test/src/core/models/user_test.dart (1)
370-404
: Excellent test coverage for the.name
getter type safety.The test cases comprehensively cover all scenarios for the type-safe
.name
getter:
- Valid string from extraData
- Empty string fallback to id
- Missing key fallback to id
- Wrong type fallback to id
These tests align perfectly with the implementation changes in the User model.
packages/stream_chat/lib/src/core/models/user.dart (2)
85-90
: Well-implemented type-safe.name
getter.The implementation correctly adds type safety with:
- Explicit
String
type check- Non-empty validation
- Appropriate fallback to
id
when invalidThis prevents runtime type errors and ensures consistent behavior when extraData contains unexpected values.
96-101
: Excellent type-safe implementation for the.image
getter.The getter follows the same defensive pattern as
.name
:
- Type validation with
is String
- Emptiness check with
isNotEmpty
- Null return for invalid cases
This ensures the getter only returns valid, non-empty image URLs or null, preventing potential issues with empty strings or wrong types.
packages/stream_chat/test/src/core/models/channel_test.dart (3)
194-228
: Thorough test coverage for the.name
getter.The test cases properly validate all scenarios:
- Valid string extraction from extraData
- Null return for missing data
- Null return for wrong type
- Null return for empty string
These tests ensure the type-safe getter behaves correctly across all edge cases.
230-282
: Complete test coverage for boolean getters.disabled
and.hidden
.Both getter test suites follow the same pattern and correctly validate:
- Proper boolean value extraction from extraData
- Null return when key is missing
- Null return when value is not a boolean
The consistent testing approach ensures reliable type safety for boolean properties.
284-319
: Comprehensive test coverage for the.truncatedAt
getter.The tests properly validate the DateTime parsing logic:
- Successful parsing from ISO8601 string in extraData
- Null return for missing data
- Null return for non-string values
- Null return for empty strings
This ensures the getter safely handles DateTime parsing with appropriate fallbacks.
packages/stream_chat/lib/src/core/models/channel_model.dart (3)
121-135
: Excellent type-safe implementation for boolean getters.Both
.disabled
and.hidden
getters follow the same robust pattern:
- Explicit type checking with
is bool
- Null return for invalid types
- Clean, readable implementation
This prevents runtime type errors when extraData contains unexpected values for these boolean properties.
140-146
: Robust type-safe implementation for.truncatedAt
getter.The implementation correctly handles the complexity of DateTime parsing:
- Type validation with
is String
- Emptiness check with
isNotEmpty
- Safe DateTime parsing with appropriate exception handling
- Null fallback for invalid cases
This prevents both type errors and parsing exceptions when extraData contains malformed date strings.
156-161
: Well-designed type-safe.name
getter.The new getter follows the established pattern consistently:
- String type validation
- Non-empty string check
- Null return for invalid cases
This aligns with the User model's
.name
getter pattern, though with different fallback behavior (null vs id), which is appropriate for the different use cases.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2274 +/- ##
==========================================
+ Coverage 63.28% 63.29% +0.01%
==========================================
Files 404 404
Lines 25269 25274 +5
==========================================
+ Hits 15992 15998 +6
+ Misses 9277 9276 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Submit a pull request
Zendesk: 66002
Summary by CodeRabbit