Skip to content

Commit

Permalink
Merge pull request #2002 from famedly/krille/tests-for-event-convert
Browse files Browse the repository at this point in the history
chore: Add tests for converting event types
  • Loading branch information
rmoradi88 authored Jan 20, 2025
2 parents a069589 + 1484e67 commit cc9e046
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/src/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ class Event extends MatrixEvent {
if (originalSource != null) {
data['original_source'] = originalSource?.toJson();
}
if (redacts != null) {
data['redacts'] = redacts;
}
data['status'] = status.intValue;
return data;
}
Expand Down
34 changes: 33 additions & 1 deletion test/event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ void main() {
expect(event.redacted, true);
expect(event.redactedBecause?.toJson(), redactedBecause.toJson());
expect(event.content.isEmpty, true);
redactionEventJson.remove('redacts');
expect(event.unsigned?['redacted_because'], redactionEventJson);

await client.dispose();
Expand Down Expand Up @@ -2830,5 +2829,38 @@ void main() {
expect(event.onlyEmotes, false);
expect(event.numberEmotes, 2);
});

test('Check conversion between types', () {
final matrixEvent = MatrixEvent.fromJson(
{
'content': {
'body': 'filename.jpg',
'info': {
'h': 398,
'mimetype': 'image/jpeg',
'size': 31037,
'w': 394,
},
'msgtype': 'm.image',
'url': 'mxc://example.org/JWEIFJgwEIhweiWJE',
},
'event_id': '\$143273582443PhrSn:example.org',
'origin_server_ts': 1432735824653,
'room_id': room.id,
'sender': '@example:example.org',
'type': 'm.room.message',
'unsigned': {'age': 1234},
'redacts': 'abcd',
'prev_content': <String, Object?>{
'foo': 'bar',
},
},
);
final event = Event.fromMatrixEvent(matrixEvent, room);
expect(
event.toJson()..remove('status'),
matrixEvent.toJson(),
);
});
});
}

0 comments on commit cc9e046

Please sign in to comment.