Resolved merge conflicts
This commit is contained in:
@@ -1368,6 +1368,189 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
group('`.sendReaction in thread`', () {
|
||||
test('should work fine', () async {
|
||||
const type = 'test-reaction-type';
|
||||
final message = Message(
|
||||
id: 'test-message-id',
|
||||
parentId: 'test-parent-id', // is thread message
|
||||
);
|
||||
|
||||
final reaction = Reaction(type: type, messageId: message.id);
|
||||
|
||||
when(() => client.sendReaction(message.id, type)).thenAnswer(
|
||||
(_) async => SendReactionResponse()
|
||||
..message = message
|
||||
..reaction = reaction,
|
||||
);
|
||||
|
||||
expectLater(
|
||||
channel.state?.threadsStream
|
||||
// skipping first seed message list -> [] messages
|
||||
.skip(1)
|
||||
.map((event) => event['test-parent-id']),
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
reactionCounts: {type: 1},
|
||||
reactionScores: {type: 1},
|
||||
latestReactions: [reaction],
|
||||
ownReactions: [reaction],
|
||||
),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchParentId: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
);
|
||||
|
||||
final res = await channel.sendReaction(message, type);
|
||||
|
||||
expect(res, isNotNull);
|
||||
expect(res.reaction.type, type);
|
||||
expect(res.reaction.messageId, message.id);
|
||||
|
||||
verify(() => client.sendReaction(message.id, type)).called(1);
|
||||
});
|
||||
|
||||
test(
|
||||
'''should restore previous thread message if `client.sendReaction` throws''',
|
||||
() async {
|
||||
const type = 'test-reaction-type';
|
||||
final message = Message(
|
||||
id: 'test-message-id',
|
||||
parentId: 'test-parent-id', // is thread message
|
||||
);
|
||||
|
||||
final reaction = Reaction(type: type, messageId: message.id);
|
||||
|
||||
when(() => client.sendReaction(message.id, type))
|
||||
.thenThrow(StreamChatNetworkError(ChatErrorCode.inputError));
|
||||
|
||||
expectLater(
|
||||
// skipping first seed message list -> [] messages
|
||||
channel.state?.threadsStream
|
||||
.skip(1)
|
||||
.map((event) => event['test-parent-id']),
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
reactionCounts: {type: 1},
|
||||
reactionScores: {type: 1},
|
||||
latestReactions: [reaction],
|
||||
ownReactions: [reaction],
|
||||
),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchParentId: true,
|
||||
),
|
||||
],
|
||||
[
|
||||
isSameMessageAs(
|
||||
message,
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchParentId: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
);
|
||||
|
||||
try {
|
||||
await channel.sendReaction(message, type);
|
||||
} catch (e) {
|
||||
expect(e, isA<StreamChatNetworkError>());
|
||||
}
|
||||
|
||||
verify(() => client.sendReaction(message.id, type)).called(1);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'''should override previous thread reaction if present and `enforceUnique` is true''',
|
||||
() async {
|
||||
const userId = 'test-user-id';
|
||||
const messageId = 'test-message-id';
|
||||
const parentId = 'test-parent-id';
|
||||
const prevType = 'test-reaction-type';
|
||||
final prevReaction = Reaction(
|
||||
type: prevType,
|
||||
messageId: messageId,
|
||||
userId: userId,
|
||||
);
|
||||
final message = Message(
|
||||
id: messageId,
|
||||
parentId: parentId,
|
||||
ownReactions: [prevReaction],
|
||||
latestReactions: [prevReaction],
|
||||
reactionScores: const {prevType: 1},
|
||||
reactionCounts: const {prevType: 1},
|
||||
);
|
||||
|
||||
const type = 'test-reaction-type-2';
|
||||
final newReaction = Reaction(
|
||||
type: type,
|
||||
messageId: messageId,
|
||||
userId: userId,
|
||||
);
|
||||
final newMessage = message.copyWith(
|
||||
ownReactions: [newReaction],
|
||||
latestReactions: [newReaction],
|
||||
);
|
||||
|
||||
const enforceUnique = true;
|
||||
|
||||
when(() => client.sendReaction(
|
||||
messageId,
|
||||
type,
|
||||
enforceUnique: enforceUnique,
|
||||
)).thenAnswer(
|
||||
(_) async => SendReactionResponse()
|
||||
..message = newMessage
|
||||
..reaction = newReaction,
|
||||
);
|
||||
|
||||
expectLater(
|
||||
// skipping first seed message list -> [] messages
|
||||
channel.state?.threadsStream
|
||||
.skip(1)
|
||||
.map((event) => event['test-parent-id']),
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
newMessage.copyWith(status: MessageSendingStatus.sent),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchParentId: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
);
|
||||
|
||||
final res = await channel.sendReaction(
|
||||
message,
|
||||
type,
|
||||
enforceUnique: enforceUnique,
|
||||
);
|
||||
|
||||
expect(res, isNotNull);
|
||||
expect(res.reaction.type, type);
|
||||
expect(res.reaction.messageId, messageId);
|
||||
|
||||
verify(() => client.sendReaction(
|
||||
messageId,
|
||||
type,
|
||||
enforceUnique: enforceUnique,
|
||||
)).called(1);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('`.deleteReaction`', () {
|
||||
test('should work fine', () async {
|
||||
const userId = 'test-user-id';
|
||||
@@ -1472,6 +1655,121 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
group('`.deleteReaction in thread`', () {
|
||||
test('should work fine', () async {
|
||||
const userId = 'test-user-id';
|
||||
const messageId = 'test-message-id';
|
||||
const parentId = 'test-parent-id';
|
||||
const type = 'test-reaction-type';
|
||||
final reaction = Reaction(
|
||||
type: type,
|
||||
messageId: messageId,
|
||||
userId: userId,
|
||||
);
|
||||
final message = Message(
|
||||
id: messageId,
|
||||
parentId: parentId, // is thread
|
||||
ownReactions: [reaction],
|
||||
latestReactions: [reaction],
|
||||
reactionScores: const {type: 1},
|
||||
reactionCounts: const {type: 1},
|
||||
);
|
||||
|
||||
when(() => client.deleteReaction(messageId, type))
|
||||
.thenAnswer((_) async => EmptyResponse());
|
||||
|
||||
expectLater(
|
||||
// skipping first seed message list -> [] messages
|
||||
channel.state?.threadsStream
|
||||
.skip(1)
|
||||
.map((event) => event['test-parent-id']),
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
latestReactions: [],
|
||||
ownReactions: [],
|
||||
),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchParentId: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
);
|
||||
|
||||
final res = await channel.deleteReaction(message, reaction);
|
||||
|
||||
expect(res, isNotNull);
|
||||
|
||||
verify(() => client.deleteReaction(messageId, type)).called(1);
|
||||
});
|
||||
|
||||
test(
|
||||
'should restore prev message state if `client.deleteReaction` throws',
|
||||
() async {
|
||||
const userId = 'test-user-id';
|
||||
const messageId = 'test-message-id';
|
||||
const parentId = 'test-parent-id';
|
||||
const type = 'test-reaction-type';
|
||||
final reaction = Reaction(
|
||||
type: type,
|
||||
messageId: messageId,
|
||||
userId: userId,
|
||||
);
|
||||
final message = Message(
|
||||
id: messageId,
|
||||
parentId: parentId,
|
||||
ownReactions: [reaction],
|
||||
latestReactions: [reaction],
|
||||
reactionScores: const {type: 1},
|
||||
reactionCounts: const {type: 1},
|
||||
);
|
||||
|
||||
when(() => client.deleteReaction(messageId, type))
|
||||
.thenThrow(StreamChatNetworkError(ChatErrorCode.inputError));
|
||||
|
||||
expectLater(
|
||||
// skipping first seed message list -> [] messages
|
||||
channel.state?.threadsStream
|
||||
.skip(1)
|
||||
.map((event) => event['test-parent-id']),
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
latestReactions: [],
|
||||
ownReactions: [],
|
||||
),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchParentId: true,
|
||||
),
|
||||
],
|
||||
[
|
||||
isSameMessageAs(
|
||||
message,
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchParentId: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
);
|
||||
|
||||
try {
|
||||
await channel.deleteReaction(message, reaction);
|
||||
} catch (e) {
|
||||
expect(e, isA<StreamChatNetworkError>());
|
||||
}
|
||||
|
||||
verify(() => client.deleteReaction(messageId, type)).called(1);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('`.update`', () async {
|
||||
const channelData = {
|
||||
'name': 'Stream Team',
|
||||
|
||||
Reference in New Issue
Block a user