@@ -334,4 +334,110 @@ void main() {
334
334
});
335
335
});
336
336
});
337
+
338
+ group ('addReaction' , () {
339
+ Future <void > checkAddReaction (FakeApiConnection connection, {
340
+ required int messageId,
341
+ required Reaction reaction,
342
+ required String expectedReactionType,
343
+ }) async {
344
+ connection.prepare (json: AddReactionResult ().toJson ());
345
+ final result = await addReaction (connection,
346
+ messageId: messageId,
347
+ reactionType: reaction.reactionType,
348
+ emojiCode: reaction.emojiCode,
349
+ emojiName: reaction.emojiName,
350
+ );
351
+ // (If AddReactionResult grows any fields, check them here.)
352
+ check (result).isA <AddReactionResult >();
353
+ check (connection.lastRequest).isNotNull ().isA< http.Request > ()
354
+ ..method.equals ('POST' )
355
+ ..url.path.equals ('/api/v1/messages/$messageId /reactions' )
356
+ ..bodyFields.deepEquals ({
357
+ 'reaction_type' : expectedReactionType,
358
+ 'emoji_code' : reaction.emojiCode,
359
+ 'emoji_name' : reaction.emojiName,
360
+ });
361
+ }
362
+
363
+ test ('unicode emoji' , () {
364
+ return FakeApiConnection .with_ ((connection) async {
365
+ await checkAddReaction (connection,
366
+ messageId: eg.streamMessage ().id,
367
+ reaction: eg.unicodeEmojiReaction,
368
+ expectedReactionType: 'unicode_emoji' );
369
+ });
370
+ });
371
+
372
+ test ('realm emoji' , () {
373
+ return FakeApiConnection .with_ ((connection) async {
374
+ await checkAddReaction (connection,
375
+ messageId: eg.streamMessage ().id,
376
+ reaction: eg.realmEmoji,
377
+ expectedReactionType: 'realm_emoji' );
378
+ });
379
+ });
380
+
381
+ test ('Zulip extra emoji' , () {
382
+ return FakeApiConnection .with_ ((connection) async {
383
+ await checkAddReaction (connection,
384
+ messageId: eg.streamMessage ().id,
385
+ reaction: eg.zulipExtraEmoji,
386
+ expectedReactionType: 'zulip_extra_emoji' );
387
+ });
388
+ });
389
+ });
390
+
391
+ group ('removeReaction' , () {
392
+ Future <void > checkRemoveReaction (FakeApiConnection connection, {
393
+ required int messageId,
394
+ required Reaction reaction,
395
+ required String expectedReactionType,
396
+ }) async {
397
+ connection.prepare (json: RemoveReactionResult ().toJson ());
398
+ final result = await removeReaction (connection,
399
+ messageId: messageId,
400
+ reactionType: reaction.reactionType,
401
+ emojiCode: reaction.emojiCode,
402
+ emojiName: reaction.emojiName,
403
+ );
404
+ // (If RemoveReactionResult grows any fields, check them here.)
405
+ check (result).isA <RemoveReactionResult >();
406
+ check (connection.lastRequest).isNotNull ().isA< http.Request > ()
407
+ ..method.equals ('DELETE' )
408
+ ..url.path.equals ('/api/v1/messages/$messageId /reactions' )
409
+ ..bodyFields.deepEquals ({
410
+ 'reaction_type' : expectedReactionType,
411
+ 'emoji_code' : reaction.emojiCode,
412
+ 'emoji_name' : reaction.emojiName,
413
+ });
414
+ }
415
+
416
+ test ('unicode emoji' , () {
417
+ return FakeApiConnection .with_ ((connection) async {
418
+ await checkRemoveReaction (connection,
419
+ messageId: eg.streamMessage ().id,
420
+ reaction: eg.unicodeEmojiReaction,
421
+ expectedReactionType: 'unicode_emoji' );
422
+ });
423
+ });
424
+
425
+ test ('realm emoji' , () {
426
+ return FakeApiConnection .with_ ((connection) async {
427
+ await checkRemoveReaction (connection,
428
+ messageId: eg.streamMessage ().id,
429
+ reaction: eg.realmEmoji,
430
+ expectedReactionType: 'realm_emoji' );
431
+ });
432
+ });
433
+
434
+ test ('Zulip extra emoji' , () {
435
+ return FakeApiConnection .with_ ((connection) async {
436
+ await checkRemoveReaction (connection,
437
+ messageId: eg.streamMessage ().id,
438
+ reaction: eg.zulipExtraEmoji,
439
+ expectedReactionType: 'zulip_extra_emoji' );
440
+ });
441
+ });
442
+ });
337
443
}
0 commit comments