fix tests
This commit is contained in:
@@ -76,8 +76,8 @@ class Message extends Equatable {
|
|||||||
this.i18n,
|
this.i18n,
|
||||||
}) : id = id ?? const Uuid().v4(),
|
}) : id = id ?? const Uuid().v4(),
|
||||||
pinExpires = pinExpires?.toUtc(),
|
pinExpires = pinExpires?.toUtc(),
|
||||||
_createdAt = createdAt,
|
createdAt = createdAt ?? DateTime.now(),
|
||||||
_updatedAt = updatedAt,
|
updatedAt = updatedAt ?? DateTime.now(),
|
||||||
_quotedMessageId = quotedMessageId;
|
_quotedMessageId = quotedMessageId;
|
||||||
|
|
||||||
/// Create a new instance from a json
|
/// Create a new instance from a json
|
||||||
@@ -167,17 +167,13 @@ class Message extends Equatable {
|
|||||||
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
|
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
|
||||||
final String? command;
|
final String? command;
|
||||||
|
|
||||||
final DateTime? _createdAt;
|
|
||||||
|
|
||||||
/// Reserved field indicating when the message was created.
|
/// Reserved field indicating when the message was created.
|
||||||
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
|
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
|
||||||
DateTime get createdAt => _createdAt ?? DateTime.now();
|
final DateTime createdAt;
|
||||||
|
|
||||||
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(includeIfNull: false, toJson: Serializer.readOnly)
|
||||||
DateTime get updatedAt => _updatedAt ?? DateTime.now();
|
final DateTime updatedAt;
|
||||||
|
|
||||||
/// User who sent the message
|
/// User who sent the message
|
||||||
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
|
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
|
||||||
@@ -315,12 +311,12 @@ class Message extends Equatable {
|
|||||||
threadParticipants: threadParticipants ?? this.threadParticipants,
|
threadParticipants: threadParticipants ?? this.threadParticipants,
|
||||||
showInChannel: showInChannel ?? this.showInChannel,
|
showInChannel: showInChannel ?? this.showInChannel,
|
||||||
command: command ?? this.command,
|
command: command ?? this.command,
|
||||||
createdAt: createdAt ?? _createdAt,
|
createdAt: createdAt ?? this.createdAt,
|
||||||
silent: silent ?? this.silent,
|
silent: silent ?? this.silent,
|
||||||
extraData: extraData ?? this.extraData,
|
extraData: extraData ?? this.extraData,
|
||||||
user: user ?? this.user,
|
user: user ?? this.user,
|
||||||
shadowed: shadowed ?? this.shadowed,
|
shadowed: shadowed ?? this.shadowed,
|
||||||
updatedAt: updatedAt ?? _updatedAt,
|
updatedAt: updatedAt ?? this.updatedAt,
|
||||||
deletedAt: deletedAt ?? this.deletedAt,
|
deletedAt: deletedAt ?? this.deletedAt,
|
||||||
status: status ?? this.status,
|
status: status ?? this.status,
|
||||||
pinned: pinned ?? this.pinned,
|
pinned: pinned ?? this.pinned,
|
||||||
|
|||||||
@@ -244,9 +244,13 @@ void main() {
|
|||||||
|
|
||||||
group('`.sendMessage`', () {
|
group('`.sendMessage`', () {
|
||||||
test('should work fine', () async {
|
test('should work fine', () async {
|
||||||
final message = Message(id: 'test-message-id');
|
final message = Message(
|
||||||
|
id: 'test-message-id',
|
||||||
|
user: client.state.currentUser,
|
||||||
|
);
|
||||||
|
|
||||||
final sendMessageResponse = SendMessageResponse()..message = message;
|
final sendMessageResponse = SendMessageResponse()
|
||||||
|
..message = message.copyWith(status: MessageSendingStatus.sent);
|
||||||
|
|
||||||
when(() => client.sendMessage(
|
when(() => client.sendMessage(
|
||||||
any(that: isSameMessageAs(message)),
|
any(that: isSameMessageAs(message)),
|
||||||
@@ -329,6 +333,7 @@ void main() {
|
|||||||
.map((it) =>
|
.map((it) =>
|
||||||
it.copyWith(uploadState: const UploadState.success()))
|
it.copyWith(uploadState: const UploadState.success()))
|
||||||
.toList(growable: false),
|
.toList(growable: false),
|
||||||
|
status: MessageSendingStatus.sent,
|
||||||
));
|
));
|
||||||
|
|
||||||
expectLater(
|
expectLater(
|
||||||
@@ -455,7 +460,10 @@ void main() {
|
|||||||
|
|
||||||
group('`.updateMessage`', () {
|
group('`.updateMessage`', () {
|
||||||
test('should work fine', () async {
|
test('should work fine', () async {
|
||||||
final message = Message(id: 'test-message-id');
|
final message = Message(
|
||||||
|
id: 'test-message-id',
|
||||||
|
status: MessageSendingStatus.sent,
|
||||||
|
);
|
||||||
|
|
||||||
final updateMessageResponse = UpdateMessageResponse()
|
final updateMessageResponse = UpdateMessageResponse()
|
||||||
..message = message;
|
..message = message;
|
||||||
@@ -530,6 +538,7 @@ void main() {
|
|||||||
any(that: isSameMessageAs(message)),
|
any(that: isSameMessageAs(message)),
|
||||||
)).thenAnswer((_) async => UpdateMessageResponse()
|
)).thenAnswer((_) async => UpdateMessageResponse()
|
||||||
..message = message.copyWith(
|
..message = message.copyWith(
|
||||||
|
status: MessageSendingStatus.sent,
|
||||||
attachments: attachments
|
attachments: attachments
|
||||||
.map((it) =>
|
.map((it) =>
|
||||||
it.copyWith(uploadState: const UploadState.success()))
|
it.copyWith(uploadState: const UploadState.success()))
|
||||||
@@ -678,7 +687,7 @@ void main() {
|
|||||||
[
|
[
|
||||||
isSameMessageAs(
|
isSameMessageAs(
|
||||||
updateMessageResponse.message.copyWith(
|
updateMessageResponse.message.copyWith(
|
||||||
status: MessageSendingStatus.sent,
|
status: MessageSendingStatus.sending,
|
||||||
),
|
),
|
||||||
matchText: true,
|
matchText: true,
|
||||||
matchSendingStatus: true,
|
matchSendingStatus: true,
|
||||||
@@ -707,7 +716,10 @@ void main() {
|
|||||||
group('`.deleteMessage`', () {
|
group('`.deleteMessage`', () {
|
||||||
test('should work fine', () async {
|
test('should work fine', () async {
|
||||||
const messageId = 'test-message-id';
|
const messageId = 'test-message-id';
|
||||||
final message = Message(id: messageId);
|
final message = Message(
|
||||||
|
id: messageId,
|
||||||
|
status: MessageSendingStatus.sent,
|
||||||
|
);
|
||||||
|
|
||||||
when(() => client.deleteMessage(messageId))
|
when(() => client.deleteMessage(messageId))
|
||||||
.thenAnswer((_) async => EmptyResponse());
|
.thenAnswer((_) async => EmptyResponse());
|
||||||
@@ -1077,7 +1089,10 @@ void main() {
|
|||||||
group('`.sendReaction`', () {
|
group('`.sendReaction`', () {
|
||||||
test('should work fine', () async {
|
test('should work fine', () async {
|
||||||
const type = 'test-reaction-type';
|
const type = 'test-reaction-type';
|
||||||
final message = Message(id: 'test-message-id');
|
final message = Message(
|
||||||
|
id: 'test-message-id',
|
||||||
|
status: MessageSendingStatus.sent,
|
||||||
|
);
|
||||||
|
|
||||||
final reaction = Reaction(type: type, messageId: message.id);
|
final reaction = Reaction(type: type, messageId: message.id);
|
||||||
|
|
||||||
@@ -1120,7 +1135,10 @@ void main() {
|
|||||||
'should restore previous message if `client.sendReaction` throws',
|
'should restore previous message if `client.sendReaction` throws',
|
||||||
() async {
|
() async {
|
||||||
const type = 'test-reaction-type';
|
const type = 'test-reaction-type';
|
||||||
final message = Message(id: 'test-message-id');
|
final message = Message(
|
||||||
|
id: 'test-message-id',
|
||||||
|
status: MessageSendingStatus.sent,
|
||||||
|
);
|
||||||
|
|
||||||
final reaction = Reaction(type: type, messageId: message.id);
|
final reaction = Reaction(type: type, messageId: message.id);
|
||||||
|
|
||||||
@@ -1181,6 +1199,7 @@ void main() {
|
|||||||
latestReactions: [prevReaction],
|
latestReactions: [prevReaction],
|
||||||
reactionScores: const {prevType: 1},
|
reactionScores: const {prevType: 1},
|
||||||
reactionCounts: const {prevType: 1},
|
reactionCounts: const {prevType: 1},
|
||||||
|
status: MessageSendingStatus.sent,
|
||||||
);
|
);
|
||||||
|
|
||||||
const type = 'test-reaction-type-2';
|
const type = 'test-reaction-type-2';
|
||||||
@@ -1212,7 +1231,7 @@ void main() {
|
|||||||
emitsInOrder([
|
emitsInOrder([
|
||||||
[
|
[
|
||||||
isSameMessageAs(
|
isSameMessageAs(
|
||||||
newMessage.copyWith(status: MessageSendingStatus.sent),
|
newMessage,
|
||||||
matchReactions: true,
|
matchReactions: true,
|
||||||
matchSendingStatus: true,
|
matchSendingStatus: true,
|
||||||
),
|
),
|
||||||
@@ -1255,6 +1274,7 @@ void main() {
|
|||||||
latestReactions: [reaction],
|
latestReactions: [reaction],
|
||||||
reactionScores: const {type: 1},
|
reactionScores: const {type: 1},
|
||||||
reactionCounts: const {type: 1},
|
reactionCounts: const {type: 1},
|
||||||
|
status: MessageSendingStatus.sent,
|
||||||
);
|
);
|
||||||
|
|
||||||
when(() => client.deleteReaction(messageId, type))
|
when(() => client.deleteReaction(messageId, type))
|
||||||
@@ -1302,6 +1322,7 @@ void main() {
|
|||||||
latestReactions: [reaction],
|
latestReactions: [reaction],
|
||||||
reactionScores: const {type: 1},
|
reactionScores: const {type: 1},
|
||||||
reactionCounts: const {type: 1},
|
reactionCounts: const {type: 1},
|
||||||
|
status: MessageSendingStatus.sent,
|
||||||
);
|
);
|
||||||
|
|
||||||
when(() => client.deleteReaction(messageId, type))
|
when(() => client.deleteReaction(messageId, type))
|
||||||
|
|||||||
Reference in New Issue
Block a user