-
Notifications
You must be signed in to change notification settings - Fork 201
Fix Flutter realtime message list parsing #1547
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
Open
mackings
wants to merge
1
commit into
appwrite:master
Choose a base branch
from
mackings:fix-flutter-realtime-message-map-fields
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+197
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
templates/flutter/test/src/realtime_message_test.dart.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:{{language.params.packageName}}/src/realtime_message.dart'; | ||
|
|
||
| void main() { | ||
| group('RealtimeMessage', () { | ||
| final events = ['databases.*.collections.*.documents.*.create']; | ||
| final payload = {'\$id': 'message-id'}; | ||
| final channels = ['databases.default.collections.messages.documents']; | ||
| final timestamp = '2026-02-26T12:00:00.000+00:00'; | ||
| final message = RealtimeMessage( | ||
| events: events, | ||
| payload: payload, | ||
| channels: channels, | ||
| timestamp: timestamp, | ||
| ); | ||
|
|
||
| test('toMap should return a map representation of the message', () { | ||
| final messageMap = message.toMap(); | ||
|
|
||
| expect(messageMap['events'], equals(events)); | ||
| expect(messageMap['payload'], equals(payload)); | ||
| expect(messageMap['channels'], equals(channels)); | ||
| expect(messageMap['timestamp'], equals(timestamp)); | ||
| }); | ||
|
|
||
| test('fromMap should create an instance from lists', () { | ||
| final messageMap = { | ||
| 'events': events, | ||
| 'payload': payload, | ||
| 'channels': channels, | ||
| 'timestamp': timestamp, | ||
| }; | ||
|
|
||
| final result = RealtimeMessage.fromMap(messageMap); | ||
|
|
||
| expect(result.events, equals(events)); | ||
| expect(result.payload, equals(payload)); | ||
| expect(result.channels, equals(channels)); | ||
| expect(result.timestamp, equals(timestamp)); | ||
| }); | ||
|
|
||
| test('fromMap should create an instance from maps', () { | ||
| final messageMap = { | ||
| 'events': {'0': events.first}, | ||
| 'payload': payload, | ||
| 'channels': {'0': channels.first}, | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
| 'timestamp': timestamp, | ||
| }; | ||
|
|
||
| final result = RealtimeMessage.fromMap(messageMap); | ||
|
|
||
| expect(result.events, equals(events)); | ||
| expect(result.payload, equals(payload)); | ||
| expect(result.channels, equals(channels)); | ||
| expect(result.timestamp, equals(timestamp)); | ||
| }); | ||
|
|
||
| test('fromMap should use map values when map keys are integers', () { | ||
| final messageMap = { | ||
| 'events': {0: events.first}, | ||
| 'payload': payload, | ||
| 'channels': {0: channels.first}, | ||
| 'timestamp': timestamp, | ||
| }; | ||
|
|
||
| final result = RealtimeMessage.fromMap(messageMap); | ||
|
|
||
| expect(result.events, equals(events)); | ||
| expect(result.channels, equals(channels)); | ||
| }); | ||
|
|
||
| test('fromMap should use map keys when map values are not strings', () { | ||
| final messageMap = { | ||
| 'events': {events.first: true}, | ||
| 'payload': payload, | ||
| 'channels': {channels.first: true}, | ||
| 'timestamp': timestamp, | ||
| }; | ||
|
|
||
| final result = RealtimeMessage.fromMap(messageMap); | ||
|
|
||
| expect(result.events, equals(events)); | ||
| expect(result.channels, equals(channels)); | ||
| }); | ||
|
|
||
| test('fromMap should use map keys for mixed-value maps', () { | ||
| final messageMap = { | ||
| 'events': { | ||
| events.first: 'someDesc', | ||
| 'databases.*.collections.*.documents.*.update': null, | ||
| }, | ||
| 'payload': payload, | ||
| 'channels': {channels.first: 'someDesc'}, | ||
| 'timestamp': timestamp, | ||
| }; | ||
|
|
||
| final result = RealtimeMessage.fromMap(messageMap); | ||
|
|
||
| expect( | ||
| result.events, | ||
| equals([events.first, 'databases.*.collections.*.documents.*.update']), | ||
| ); | ||
| expect(result.channels, equals(channels)); | ||
| }); | ||
|
|
||
| test( | ||
| 'fromMap should use empty lists when events and channels are null', | ||
| () { | ||
| final messageMap = { | ||
| 'events': null, | ||
| 'payload': payload, | ||
| 'channels': null, | ||
| 'timestamp': timestamp, | ||
| }; | ||
|
|
||
| final result = RealtimeMessage.fromMap(messageMap); | ||
|
|
||
| expect(result.events, isEmpty); | ||
| expect(result.channels, isEmpty); | ||
| }, | ||
| ); | ||
|
|
||
| test( | ||
| 'fromMap should use empty lists when events and channels are absent', | ||
| () { | ||
| final messageMap = {'payload': payload, 'timestamp': timestamp}; | ||
|
|
||
| final result = RealtimeMessage.fromMap(messageMap); | ||
|
|
||
| expect(result.events, isEmpty); | ||
| expect(result.channels, isEmpty); | ||
| }, | ||
| ); | ||
|
|
||
| test('fromMap should throw when list items are not strings', () { | ||
| final messageMap = { | ||
| 'events': [true], | ||
| 'payload': payload, | ||
| 'channels': channels, | ||
| 'timestamp': timestamp, | ||
| }; | ||
|
|
||
| expect( | ||
| () => RealtimeMessage.fromMap(messageMap), | ||
| throwsA(isA<TypeError>()), | ||
| ); | ||
| }); | ||
|
|
||
| test('toJson and fromJson should convert to/from JSON', () { | ||
| final jsonString = message.toJson(); | ||
|
|
||
| final result = RealtimeMessage.fromJson(jsonString); | ||
|
|
||
| expect(result, equals(message)); | ||
| }); | ||
| }); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.