Skip to content

Commit

Permalink
fix: answer_id being null (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lexedia authored Jul 11, 2024
1 parent 8afc76d commit 0824294
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/src/http/managers/message_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class MessageManager extends Manager<Message> {

PollAnswerCount parsePollAnswerCount(Map<String, Object?> raw) {
return PollAnswerCount(
answerId: raw['answer_id'] as int,
answerId: raw['id'] as int,
count: raw['count'] as int,
me: raw['me_voted'] as bool,
);
Expand Down
41 changes: 40 additions & 1 deletion test/unit/http/managers/message_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,31 @@ final sampleMessage = {
"name": "example sticker",
"format_type": 1,
}
]
],
"poll": {
"allow_multiselect": false,
"answers": [
{
"answer_id": 1,
"poll_media": {"text": "oof"},
}
],
"expiry": "2024-07-12T22:00:25.095257+00:00",
"layout_type": 1,
"question": {
"text": "Why are you so dumb?",
},
"results": {
"is_finalized": false,
"answer_counts": [
{
"count": 1,
"id": 1,
"me_voted": true,
}
]
}
}
};

void checkMessage(Message message) {
Expand Down Expand Up @@ -68,6 +92,21 @@ void checkMessage(Message message) {
expect(message.position, isNull);
expect(message.roleSubscriptionData, isNull);
expect(message.stickers, hasLength(1));
expect(message.poll, isNotNull);
expect(message.poll!.allowsMultiselect, equals(false));
expect(message.poll!.answers, hasLength(1));
expect(message.poll!.answers.single.id, equals(1));
expect(message.poll!.answers.single.pollMedia.text, equals('oof'));
expect(message.poll!.endsAt, equals(DateTime.utc(2024, 07, 12, 22, 00, 25, 095, 257)));
expect(message.poll!.layoutType, equals(PollLayoutType.defaultLayout));
expect(message.poll!.question.text, equals('Why are you so dumb?'));
expect(message.poll!.results, isNotNull);
expect(message.poll!.results!.isFinalized, isFalse);
expect(message.poll!.results!.answerCounts, hasLength(1));
expect(message.poll!.results!.answerCounts.single.count, equals(1));
expect(message.poll!.results!.answerCounts.single.answerId, equals(1));
expect(message.poll!.results!.answerCounts.single.me, isTrue);
expect(message.poll!.results!.answerCounts.single.count, equals(1));
}

final sampleCrosspostedMessage = {
Expand Down

0 comments on commit 0824294

Please sign in to comment.