@@ -76,6 +76,14 @@ TTestSenderProcedure=class(TTestTelegramBase)
7676 procedure sendMessage ;
7777 end ;
7878
79+ { TTestReactionUpdates }
80+
81+ TTestReactionUpdates=class (TTestCase)
82+ published
83+ procedure ParseMessageReactionUpdate ;
84+ procedure ParseMessageReactionCountUpdate ;
85+ end ;
86+
7987 { TTestReceiveLongPollingBase }
8088 { Test receiving updates via longpolling from the test bot. Please send test messages to the bot
8189 immediately before running the test! }
@@ -271,6 +279,93 @@ procedure TTestSenderProcedure.sendMessage;
271279 SaveString(AReply, ' ~JSONResponce.json' );
272280end ;
273281
282+ { TTestReactionUpdates }
283+
284+ procedure TTestReactionUpdates.ParseMessageReactionUpdate ;
285+ const
286+ ReactionUpdateJSON =
287+ ' {' +
288+ ' "update_id":1000,' +
289+ ' "message_reaction":{' +
290+ ' "chat":{"id":42,"type":"private","first_name":"Test"},' +
291+ ' "message_id":7,' +
292+ ' "user":{"id":99,"is_bot":false,"first_name":"Bob"},' +
293+ ' "date":1700000000,' +
294+ ' "old_reaction":[{"type":"emoji","emoji":"👍"}],' +
295+ ' "new_reaction":[{"type":"custom_emoji","custom_emoji_id":"abc123"}]' +
296+ ' }' +
297+ ' }' ;
298+ var
299+ UpdateObj: TTelegramUpdateObj;
300+ ReactionUpdate: TTelegramMessageReactionUpdated;
301+ JSONData: TJSONData;
302+ begin
303+ JSONData:=GetJSON(ReactionUpdateJSON);
304+ try
305+ UpdateObj:=TTelegramUpdateObj.Create(JSONData as TJSONObject);
306+ try
307+ AssertEquals(utMessageReaction, UpdateObj.UpdateType);
308+ ReactionUpdate:=UpdateObj.MessageReaction;
309+ AssertNotNull(' MessageReaction should be assigned' , ReactionUpdate);
310+ AssertEquals(42 , ReactionUpdate.Chat.ID);
311+ AssertEquals(7 , ReactionUpdate.MessageID);
312+ AssertNotNull(' MessageReaction user should be assigned' , ReactionUpdate.User);
313+ AssertEquals(99 , ReactionUpdate.User.ID);
314+ AssertEquals(1 , ReactionUpdate.OldReactions.Count);
315+ AssertEquals(' emoji' , ReactionUpdate.OldReactions[0 ].TypeName);
316+ AssertEquals(' 👍' , ReactionUpdate.OldReactions[0 ].Emoji);
317+ AssertEquals(1 , ReactionUpdate.NewReactions.Count);
318+ AssertEquals(' custom_emoji' , ReactionUpdate.NewReactions[0 ].TypeName);
319+ AssertEquals(' abc123' , ReactionUpdate.NewReactions[0 ].CustomEmojiID);
320+ finally
321+ UpdateObj.Free;
322+ end ;
323+ finally
324+ JSONData.Free;
325+ end ;
326+ end ;
327+
328+ procedure TTestReactionUpdates.ParseMessageReactionCountUpdate ;
329+ const
330+ ReactionCountUpdateJSON =
331+ ' {' +
332+ ' "update_id":1001,' +
333+ ' "message_reaction_count":{' +
334+ ' "chat":{"id":123,"type":"supergroup","title":"Test Group"},' +
335+ ' "message_id":10,' +
336+ ' "date":1700000100,' +
337+ ' "reactions":[{' +
338+ ' "type":{"type":"emoji","emoji":"❤️"},' +
339+ ' "total_count":3' +
340+ ' }]' +
341+ ' }' +
342+ ' }' ;
343+ var
344+ UpdateObj: TTelegramUpdateObj;
345+ ReactionCountUpdate: TTelegramMessageReactionCountUpdated;
346+ JSONData: TJSONData;
347+ begin
348+ JSONData:=GetJSON(ReactionCountUpdateJSON);
349+ try
350+ UpdateObj:=TTelegramUpdateObj.Create(JSONData as TJSONObject);
351+ try
352+ AssertEquals(utMessageReactionCount, UpdateObj.UpdateType);
353+ ReactionCountUpdate:=UpdateObj.MessageReactionCount;
354+ AssertNotNull(' MessageReactionCount should be assigned' , ReactionCountUpdate);
355+ AssertEquals(123 , ReactionCountUpdate.Chat.ID);
356+ AssertEquals(10 , ReactionCountUpdate.MessageID);
357+ AssertEquals(1 , ReactionCountUpdate.Reactions.Count);
358+ AssertEquals(3 , ReactionCountUpdate.Reactions[0 ].TotalCount);
359+ AssertEquals(' emoji' , ReactionCountUpdate.Reactions[0 ].ReactionType.TypeName);
360+ AssertEquals(' ❤️' , ReactionCountUpdate.Reactions[0 ].ReactionType.Emoji);
361+ finally
362+ UpdateObj.Free;
363+ end ;
364+ finally
365+ JSONData.Free;
366+ end ;
367+ end ;
368+
274369{ TTestSender }
275370
276371procedure TTestSender.SetUp ;
@@ -597,7 +692,7 @@ procedure TTestSender.getChatAdministators;
597692end ;
598693
599694initialization
600- RegisterTests([TTestSender, TTestSenderProcedure, TTestProxySender, TTestReceiveLongPolling, TTestPayments]);
695+ RegisterTests([TTestSender, TTestSenderProcedure, TTestProxySender, TTestReceiveLongPolling,
696+ TTestPayments, TTestReactionUpdates]);
601697
602698end .
603-
0 commit comments