add more user and channel config test

This commit is contained in:
Salvatore Giordano
2021-06-17 10:01:46 +02:00
parent aef63f3722
commit 91907639ad
4 changed files with 25 additions and 24 deletions
@@ -4,7 +4,7 @@ import 'package:stream_chat/src/core/models/command.dart';
part 'channel_config.g.dart';
/// The class that contains the information about the configuration of a channel
@JsonSerializable()
@JsonSerializable(createToJson: false)
class ChannelConfig {
/// Constructor used for json serialization
ChannelConfig({
@@ -87,7 +87,4 @@ class ChannelConfig {
/// True if urls appears as attachments
@JsonKey(defaultValue: false)
final bool urlEnrichment;
/// Serialize to json
Map<String, dynamic> toJson() => _$ChannelConfigToJson(this);
}
@@ -32,22 +32,3 @@ ChannelConfig _$ChannelConfigFromJson(Map<String, dynamic> json) {
urlEnrichment: json['url_enrichment'] as bool? ?? false,
);
}
Map<String, dynamic> _$ChannelConfigToJson(ChannelConfig instance) =>
<String, dynamic>{
'automod': instance.automod,
'commands': instance.commands.map((e) => e.toJson()).toList(),
'connect_events': instance.connectEvents,
'created_at': instance.createdAt.toIso8601String(),
'updated_at': instance.updatedAt.toIso8601String(),
'max_message_length': instance.maxMessageLength,
'message_retention': instance.messageRetention,
'mutes': instance.mutes,
'reactions': instance.reactions,
'read_events': instance.readEvents,
'replies': instance.replies,
'search': instance.search,
'typing_events': instance.typingEvents,
'uploads': instance.uploads,
'url_enrichment': instance.urlEnrichment,
};
+2 -1
View File
@@ -1,4 +1,5 @@
{
"id": "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e",
"role": "test-role"
"role": "test-role",
"name": "John"
}
@@ -8,6 +8,7 @@ void main() {
test('should parse json correctly', () {
final user = User.fromJson(jsonFixture('user.json'));
expect(user.id, 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e');
expect(user.name, 'John');
});
test('should serialize to json correctly', () {
@@ -20,5 +21,26 @@ void main() {
'id': 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e',
});
});
test('copyWith', () {
final user = User.fromJson(jsonFixture('user.json'));
var newUser = user.copyWith();
expect(newUser.id, user.id);
expect(newUser.role, user.role);
expect(newUser.name, user.name);
newUser = user.copyWith(
id: 'test',
role: 'test',
extraData: {
'name': 'test',
},
);
expect(newUser.id, 'test');
expect(newUser.role, 'test');
expect(newUser.name, 'test');
});
});
}