[LLC] Fix reactions tests
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
@@ -329,11 +329,9 @@ class Channel {
|
|||||||
_client.decode(res.data, SendReactionResponse.fromJson);
|
_client.decode(res.data, SendReactionResponse.fromJson);
|
||||||
state?.addMessage(reactionResp.message);
|
state?.addMessage(reactionResp.message);
|
||||||
return reactionResp;
|
return reactionResp;
|
||||||
} catch (error) {
|
} catch (_) {
|
||||||
if (error is DioError && error.type != DioErrorType.RESPONSE) {
|
// Reset the message if the update fails
|
||||||
// Reset the message if the update fails
|
state?.addMessage(message);
|
||||||
state?.addMessage(message);
|
|
||||||
}
|
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,14 +339,16 @@ class Channel {
|
|||||||
/// Delete a reaction from this channel
|
/// Delete a reaction from this channel
|
||||||
Future<EmptyResponse> deleteReaction(
|
Future<EmptyResponse> deleteReaction(
|
||||||
Message message, Reaction reaction) async {
|
Message message, Reaction reaction) async {
|
||||||
_checkInitialized();
|
|
||||||
|
|
||||||
final type = reaction.type;
|
final type = reaction.type;
|
||||||
|
|
||||||
final reactionCounts = {...message.reactionCounts}
|
final reactionCounts = {...message.reactionCounts};
|
||||||
..update(type, (value) => value - 1);
|
if (reactionCounts.containsKey(type)) {
|
||||||
final reactionScores = {...message.reactionScores}
|
reactionCounts.update(type, (value) => value - 1);
|
||||||
..update(type, (value) => value - 1);
|
}
|
||||||
|
final reactionScores = {...message.reactionScores};
|
||||||
|
if (reactionScores.containsKey(type)) {
|
||||||
|
reactionScores.update(type, (value) => value - 1);
|
||||||
|
}
|
||||||
|
|
||||||
final removeWhere = (Reaction r) =>
|
final removeWhere = (Reaction r) =>
|
||||||
r.userId == reaction.userId &&
|
r.userId == reaction.userId &&
|
||||||
@@ -368,11 +368,9 @@ class Channel {
|
|||||||
final res = await client
|
final res = await client
|
||||||
.delete('/messages/${message.id}/reaction/${reaction.type}');
|
.delete('/messages/${message.id}/reaction/${reaction.type}');
|
||||||
return _client.decode(res.data, EmptyResponse.fromJson);
|
return _client.decode(res.data, EmptyResponse.fromJson);
|
||||||
} catch (error) {
|
} catch (_) {
|
||||||
if (error is DioError && error.type != DioErrorType.RESPONSE) {
|
// Reset the message if the update fails
|
||||||
// Reset the message if the update fails
|
state?.addMessage(message);
|
||||||
state?.addMessage(message);
|
|
||||||
}
|
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -396,6 +396,10 @@ void main() {
|
|||||||
await channelClient.sendReaction(
|
await channelClient.sendReaction(
|
||||||
Message(
|
Message(
|
||||||
id: 'messageid',
|
id: 'messageid',
|
||||||
|
reactionCounts: const <String, int>{},
|
||||||
|
reactionScores: const <String, int>{},
|
||||||
|
latestReactions: const <Reaction>[],
|
||||||
|
ownReactions: const <Reaction>[],
|
||||||
),
|
),
|
||||||
reactionType,
|
reactionType,
|
||||||
);
|
);
|
||||||
@@ -421,20 +425,17 @@ void main() {
|
|||||||
);
|
);
|
||||||
final channelClient = client.channel('messaging', id: 'testid');
|
final channelClient = client.channel('messaging', id: 'testid');
|
||||||
|
|
||||||
when(mockDio.post<String>(
|
|
||||||
any,
|
|
||||||
data: anyNamed('data'),
|
|
||||||
)).thenAnswer((_) async => Response(
|
|
||||||
data: '{}',
|
|
||||||
statusCode: 200,
|
|
||||||
));
|
|
||||||
await channelClient.watch();
|
|
||||||
|
|
||||||
when(mockDio.delete<String>('/messages/messageid/reaction/test'))
|
when(mockDio.delete<String>('/messages/messageid/reaction/test'))
|
||||||
.thenAnswer((_) async => Response(data: '{}', statusCode: 200));
|
.thenAnswer((_) async => Response(data: '{}', statusCode: 200));
|
||||||
|
|
||||||
await channelClient.deleteReaction(
|
await channelClient.deleteReaction(
|
||||||
Message(id: 'messageid'),
|
Message(
|
||||||
|
id: 'messageid',
|
||||||
|
reactionCounts: const <String, int>{},
|
||||||
|
reactionScores: const <String, int>{},
|
||||||
|
latestReactions: const <Reaction>[],
|
||||||
|
ownReactions: const <Reaction>[],
|
||||||
|
),
|
||||||
Reaction(type: 'test'),
|
Reaction(type: 'test'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user