fix tests

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
xsahil03x
2023-04-03 20:27:14 +05:30
parent 99dd1dbaab
commit 36d3ca9258
12 changed files with 55 additions and 100 deletions
+7 -7
View File
@@ -65,29 +65,29 @@ scripts:
test:dart: test:dart:
run: melos exec -c 1 --fail-fast -- "flutter test --coverage" run: melos exec -c 1 --fail-fast -- "flutter test --coverage"
description: Run Dart tests for a specific package in this project. description: Run Dart tests for a specific package in this project.
select-package: packageFilters:
flutter: false flutter: false
dir-exists: test dirExists: test
test:flutter: test:flutter:
run: melos exec -c 4 --fail-fast -- "flutter test --coverage" run: melos exec -c 4 --fail-fast -- "flutter test --coverage"
description: Run Flutter tests for a specific package in this project. description: Run Flutter tests for a specific package in this project.
select-package: packageFilters:
flutter: true flutter: true
dir-exists: test dirExists: test
clean:flutter: clean:flutter:
run: melos exec -c 4 --fail-fast -- "flutter clean" run: melos exec -c 4 --fail-fast -- "flutter clean"
description: Run Flutter clean for a specific package in this project. description: Run Flutter clean for a specific package in this project.
select-package: packageFilters:
flutter: true flutter: true
coverage:ignore-file: coverage:ignore-file:
run: | run: |
melos exec -c 5 --fail-fast -- "\$MELOS_ROOT_PATH/.github/workflows/scripts/remove-from-coverage.sh" melos exec -c 5 --fail-fast -- "\$MELOS_ROOT_PATH/.github/workflows/scripts/remove-from-coverage.sh"
description: Removes all the ignored files from the coverage report. description: Removes all the ignored files from the coverage report.
select-package: packageFilters:
dir-exists: coverage dirExists: coverage
docs: docs:
run: | run: |
@@ -146,13 +146,13 @@ class Attachment extends Equatable {
/// Shortcut for file size. /// Shortcut for file size.
/// ///
/// {@macro fileSize} /// {@macro fileSize}
@JsonKey(ignore: true) @JsonKey(includeToJson: false, includeFromJson: false)
int? get fileSize => extraData['file_size'] as int?; int? get fileSize => extraData['file_size'] as int?;
/// Shortcut for file mimeType. /// Shortcut for file mimeType.
/// ///
/// {@macro mimeType} /// {@macro mimeType}
@JsonKey(ignore: true) @JsonKey(includeToJson: false, includeFromJson: false)
String? get mimeType => extraData['mime_type'] as String?; String? get mimeType => extraData['mime_type'] as String?;
/// Known top level fields. /// Known top level fields.
@@ -62,19 +62,19 @@ class ChannelModel {
final String type; final String type;
/// The cid of this channel /// The cid of this channel
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final String cid; final String cid;
/// List of user permissions on this channel /// List of user permissions on this channel
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final List<String>? ownCapabilities; final List<String>? ownCapabilities;
/// The channel configuration data /// The channel configuration data
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final ChannelConfig config; final ChannelConfig config;
/// The user that created this channel /// The user that created this channel
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final User? createdBy; final User? createdBy;
/// True if this channel is frozen /// True if this channel is frozen
@@ -82,23 +82,23 @@ class ChannelModel {
final bool frozen; final bool frozen;
/// The date of the last message /// The date of the last message
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final DateTime? lastMessageAt; final DateTime? lastMessageAt;
/// The date of channel creation /// The date of channel creation
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final DateTime createdAt; final DateTime createdAt;
/// The date of the last channel update /// The date of the last channel update
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final DateTime updatedAt; final DateTime updatedAt;
/// The date of channel deletion /// The date of channel deletion
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final DateTime? deletedAt; final DateTime? deletedAt;
/// The count of this channel members /// The count of this channel members
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final int memberCount; final int memberCount;
/// The number of seconds in a cooldown /// The number of seconds in a cooldown
@@ -106,15 +106,15 @@ class ChannelModel {
final int cooldown; final int cooldown;
/// True if the channel is disabled /// True if the channel is disabled
@JsonKey(ignore: true) @JsonKey(includeToJson: false, includeFromJson: false)
bool? get disabled => extraData['disabled'] as bool?; bool? get disabled => extraData['disabled'] as bool?;
/// True if the channel is hidden /// True if the channel is hidden
@JsonKey(ignore: true) @JsonKey(includeToJson: false, includeFromJson: false)
bool? get hidden => extraData['hidden'] as bool?; bool? get hidden => extraData['hidden'] as bool?;
/// The date of the last time channel got truncated /// The date of the last time channel got truncated
@JsonKey(ignore: true) @JsonKey(includeToJson: false, includeFromJson: false)
DateTime? get truncatedAt { DateTime? get truncatedAt {
final truncatedAt = extraData['truncated_at'] as String?; final truncatedAt = extraData['truncated_at'] as String?;
if (truncatedAt == null) return null; if (truncatedAt == null) return null;
@@ -126,7 +126,7 @@ class ChannelModel {
final Map<String, Object?> extraData; final Map<String, Object?> extraData;
/// The team the channel belongs to /// The team the channel belongs to
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final String? team; final String? team;
/// Known top level fields. /// Known top level fields.
@@ -42,17 +42,7 @@ Map<String, dynamic> _$ChannelModelToJson(ChannelModel instance) =>
<String, dynamic>{ <String, dynamic>{
'id': instance.id, 'id': instance.id,
'type': instance.type, 'type': instance.type,
'cid': readonly(instance.cid),
'own_capabilities': readonly(instance.ownCapabilities),
'config': readonly(instance.config),
'created_by': readonly(instance.createdBy),
'frozen': instance.frozen, 'frozen': instance.frozen,
'last_message_at': readonly(instance.lastMessageAt),
'created_at': readonly(instance.createdAt),
'updated_at': readonly(instance.updatedAt),
'deleted_at': readonly(instance.deletedAt),
'member_count': readonly(instance.memberCount),
'cooldown': instance.cooldown, 'cooldown': instance.cooldown,
'extra_data': instance.extraData, 'extra_data': instance.extraData,
'team': readonly(instance.team),
}; };
@@ -95,14 +95,11 @@ class Message extends Equatable {
final String? text; final String? text;
/// The status of a sending message. /// The status of a sending message.
@JsonKey(ignore: true) @JsonKey(includeFromJson: false, includeToJson: false)
final MessageSendingStatus status; final MessageSendingStatus status;
/// The message type. /// The message type.
@JsonKey( @JsonKey(includeToJson: false)
includeIfNull: false,
toJson: Serializer.readOnly,
)
final String type; final String type;
/// The list of attachments, either provided by the user or generated from a /// The list of attachments, either provided by the user or generated from a
@@ -115,19 +112,19 @@ class Message extends Equatable {
final List<User> mentionedUsers; final List<User> mentionedUsers;
/// A map describing the count of number of every reaction. /// A map describing the count of number of every reaction.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final Map<String, int>? reactionCounts; final Map<String, int>? reactionCounts;
/// A map describing the count of score of every reaction. /// A map describing the count of score of every reaction.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final Map<String, int>? reactionScores; final Map<String, int>? reactionScores;
/// The latest reactions to the message created by any user. /// The latest reactions to the message created by any user.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final List<Reaction>? latestReactions; final List<Reaction>? latestReactions;
/// The reactions added to the message by the current user. /// The reactions added to the message by the current user.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final List<Reaction>? ownReactions; final List<Reaction>? ownReactions;
/// The ID of the parent message, if the message is a thread reply. /// The ID of the parent message, if the message is a thread reply.
@@ -143,11 +140,11 @@ class Message extends Equatable {
String? get quotedMessageId => _quotedMessageId ?? quotedMessage?.id; String? get quotedMessageId => _quotedMessageId ?? quotedMessage?.id;
/// Reserved field indicating the number of replies for this message. /// Reserved field indicating the number of replies for this message.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final int? replyCount; final int? replyCount;
/// Reserved field indicating the thread participants for this message. /// Reserved field indicating the thread participants for this message.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final List<User>? threadParticipants; final List<User>? threadParticipants;
/// Check if this message needs to show in the channel. /// Check if this message needs to show in the channel.
@@ -157,34 +154,31 @@ class Message extends Equatable {
final bool silent; final bool silent;
/// If true the message is shadowed. /// If true the message is shadowed.
@JsonKey( @JsonKey(includeToJson: false)
includeIfNull: false,
toJson: Serializer.readOnly,
)
final bool shadowed; final bool shadowed;
/// A used command name. /// A used command name.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final String? command; final String? command;
final DateTime? _createdAt; final DateTime? _createdAt;
/// Reserved field indicating when the message was deleted. /// Reserved field indicating when the message was deleted.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final DateTime? deletedAt; final DateTime? deletedAt;
/// Reserved field indicating when the message was created. /// Reserved field indicating when the message was created.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
DateTime get createdAt => _createdAt ?? DateTime.now(); DateTime get createdAt => _createdAt ?? DateTime.now();
final DateTime? _updatedAt; final DateTime? _updatedAt;
/// Reserved field indicating when the message was updated last time. /// Reserved field indicating when the message was updated last time.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
DateTime get updatedAt => _updatedAt ?? DateTime.now(); DateTime get updatedAt => _updatedAt ?? DateTime.now();
/// User who sent the message. /// User who sent the message.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final User? user; final User? user;
/// If true the message is pinned. /// If true the message is pinned.
@@ -75,26 +75,13 @@ Map<String, dynamic> _$MessageToJson(Message instance) {
final val = <String, dynamic>{ final val = <String, dynamic>{
'id': instance.id, 'id': instance.id,
'text': instance.text, 'text': instance.text,
'type': readonly(instance.type),
'attachments': instance.attachments.map((e) => e.toJson()).toList(), 'attachments': instance.attachments.map((e) => e.toJson()).toList(),
'mentioned_users': User.toIds(instance.mentionedUsers), 'mentioned_users': User.toIds(instance.mentionedUsers),
'reaction_counts': readonly(instance.reactionCounts),
'reaction_scores': readonly(instance.reactionScores),
'latest_reactions': readonly(instance.latestReactions),
'own_reactions': readonly(instance.ownReactions),
'parent_id': instance.parentId, 'parent_id': instance.parentId,
'quoted_message': readonly(instance.quotedMessage), 'quoted_message': readonly(instance.quotedMessage),
'quoted_message_id': instance.quotedMessageId, 'quoted_message_id': instance.quotedMessageId,
'reply_count': readonly(instance.replyCount),
'thread_participants': readonly(instance.threadParticipants),
'show_in_channel': instance.showInChannel, 'show_in_channel': instance.showInChannel,
'silent': instance.silent, 'silent': instance.silent,
'shadowed': readonly(instance.shadowed),
'command': readonly(instance.command),
'deleted_at': readonly(instance.deletedAt),
'created_at': readonly(instance.createdAt),
'updated_at': readonly(instance.updatedAt),
'user': readonly(instance.user),
'pinned': instance.pinned, 'pinned': instance.pinned,
'pinned_at': readonly(instance.pinnedAt), 'pinned_at': readonly(instance.pinnedAt),
'pin_expires': instance.pinExpires?.toIso8601String(), 'pin_expires': instance.pinExpires?.toIso8601String(),
@@ -33,18 +33,18 @@ class Reaction {
final String type; final String type;
/// The date of the reaction /// The date of the reaction
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final DateTime createdAt; final DateTime createdAt;
/// The user that sent the reaction /// The user that sent the reaction
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final User? user; final User? user;
/// The score of the reaction (ie. number of reactions sent) /// The score of the reaction (ie. number of reactions sent)
final int score; final int score;
/// The userId that sent the reaction /// The userId that sent the reaction
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final String? userId; final String? userId;
/// Reaction custom extraData /// Reaction custom extraData
@@ -23,9 +23,6 @@ Reaction _$ReactionFromJson(Map<String, dynamic> json) => Reaction(
Map<String, dynamic> _$ReactionToJson(Reaction instance) => <String, dynamic>{ Map<String, dynamic> _$ReactionToJson(Reaction instance) => <String, dynamic>{
'message_id': instance.messageId, 'message_id': instance.messageId,
'type': instance.type, 'type': instance.type,
'created_at': readonly(instance.createdAt),
'user': readonly(instance.user),
'score': instance.score, 'score': instance.score,
'user_id': readonly(instance.userId),
'extra_data': instance.extraData, 'extra_data': instance.extraData,
}; };
@@ -79,7 +79,7 @@ class User extends Equatable {
/// Shortcut for user name. /// Shortcut for user name.
/// ///
/// {@macro name} /// {@macro name}
@JsonKey(ignore: true) @JsonKey(includeToJson: false, includeFromJson: false)
String get name { String get name {
if (extraData.containsKey('name') && extraData['name'] != null) { if (extraData.containsKey('name') && extraData['name'] != null) {
final name = extraData['name']! as String; final name = extraData['name']! as String;
@@ -91,48 +91,39 @@ class User extends Equatable {
/// Shortcut for user image. /// Shortcut for user image.
/// ///
/// {@macro image} /// {@macro image}
@JsonKey(ignore: true) @JsonKey(includeToJson: false, includeFromJson: false)
String? get image => extraData['image'] as String?; String? get image => extraData['image'] as String?;
/// User role. /// User role.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final String? role; final String? role;
/// User teams /// User teams
@JsonKey( @JsonKey(includeToJson: false)
includeIfNull: false,
toJson: Serializer.readOnly,
)
final List<String> teams; final List<String> teams;
/// Date of user creation. /// Date of user creation.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final DateTime createdAt; final DateTime createdAt;
/// Date of last user update. /// Date of last user update.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final DateTime updatedAt; final DateTime updatedAt;
/// Date of last user connection. /// Date of last user connection.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final DateTime? lastActive; final DateTime? lastActive;
/// True if user is online. /// True if user is online.
@JsonKey( @JsonKey(includeToJson: false)
includeIfNull: false,
toJson: Serializer.readOnly,
)
final bool online; final bool online;
/// True if user is banned from the chat. /// True if user is banned from the chat.
@JsonKey( @JsonKey(includeToJson: false)
includeIfNull: false,
toJson: Serializer.readOnly,
)
final bool banned; final bool banned;
/// The date at which the ban will expire. /// The date at which the ban will expire.
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeToJson: false)
final DateTime? banExpires; final DateTime? banExpires;
/// The language this user prefers. /// The language this user prefers.
@@ -33,14 +33,6 @@ User _$UserFromJson(Map<String, dynamic> json) => User(
Map<String, dynamic> _$UserToJson(User instance) { Map<String, dynamic> _$UserToJson(User instance) {
final val = <String, dynamic>{ final val = <String, dynamic>{
'id': instance.id, 'id': instance.id,
'role': readonly(instance.role),
'teams': readonly(instance.teams),
'created_at': readonly(instance.createdAt),
'updated_at': readonly(instance.updatedAt),
'last_active': readonly(instance.lastActive),
'online': readonly(instance.online),
'banned': readonly(instance.banned),
'ban_expires': readonly(instance.banExpires),
}; };
void writeNotNull(String key, dynamic value) { void writeNotNull(String key, dynamic value) {
@@ -129,7 +129,11 @@ void main() {
await client.get('path'); await client.get('path');
} on StreamChatNetworkError catch (e) { } on StreamChatNetworkError catch (e) {
expect(e, isA<StreamChatNetworkError>()); expect(e, isA<StreamChatNetworkError>());
expect(e.message, "Dio can't establish new connection after closed."); expect(
e.message,
"The connection errored: Dio can't establish a new connection"
' after it was closed.',
);
} }
}); });
@@ -93,7 +93,7 @@ void main() {
const errorMessage = 'Error! Error! Error!'; const errorMessage = 'Error! Error! Error!';
final error = DioError( final error = DioError(
type: DioErrorType.badResponse, type: DioErrorType.badResponse,
error: errorMessage, message: errorMessage,
requestOptions: RequestOptions(path: ''), requestOptions: RequestOptions(path: ''),
); );
when(() => mockChannel.initialized) when(() => mockChannel.initialized)