Add more tests

This commit is contained in:
Christian Pauly 2020-05-25 09:34:43 +00:00
parent 0854cb81af
commit cbf5069e32
14 changed files with 558 additions and 48 deletions

View file

@ -1,6 +1,7 @@
import '../room.dart';
abstract class MatrixLocalizations {
const MatrixLocalizations();
String get emptyChat;
String get invitedUsersOnly;
@ -121,9 +122,8 @@ extension HistoryVisibilityDisplayString on HistoryVisibility {
return i18n.visibleForAllParticipants;
case HistoryVisibility.world_readable:
return i18n.visibleForEveryone;
default:
return toString().replaceAll('HistoryVisibility.', '');
}
return null;
}
}
@ -134,9 +134,8 @@ extension GuestAccessDisplayString on GuestAccess {
return i18n.guestsCanJoin;
case GuestAccess.forbidden:
return i18n.guestsAreForbidden;
default:
return toString().replaceAll('GuestAccess.', '');
}
return null;
}
}

View file

@ -4,12 +4,6 @@ class OpenIdCredentials {
String matrixServerName;
num expiresIn;
OpenIdCredentials(
{this.accessToken,
this.tokenType,
this.matrixServerName,
this.expiresIn});
OpenIdCredentials.fromJson(Map<String, dynamic> json) {
accessToken = json['access_token'];
tokenType = json['token_type'];

View file

@ -7,14 +7,6 @@ class PublicRoomsResponse {
final int totalRoomCountEstimate;
Client client;
PublicRoomsResponse({
this.publicRooms,
this.nextBatch,
this.prevBatch,
this.totalRoomCountEstimate,
this.client,
});
PublicRoomsResponse.fromJson(Map<String, dynamic> json, Client client)
: nextBatch = json['next_batch'],
prevBatch = json['prev_batch'],
@ -42,18 +34,6 @@ class PublicRoomEntry {
Future<void> join() => client.joinRoomById(roomId);
PublicRoomEntry({
this.aliases,
this.avatarUrl,
this.guestCanJoin,
this.name,
this.numJoinedMembers,
this.roomId,
this.topic,
this.worldReadable,
this.client,
});
PublicRoomEntry.fromJson(Map<String, dynamic> json, Client client)
: aliases =
json.containsKey('aliases') ? json['aliases'].cast<String>() : [],

View file

@ -8,16 +8,6 @@ class Pusher {
String lang;
PusherData data;
Pusher(
{this.pushkey,
this.kind,
this.appId,
this.appDisplayName,
this.deviceDisplayName,
this.profileTag,
this.lang,
this.data});
Pusher.fromJson(Map<String, dynamic> json) {
pushkey = json['pushkey'];
kind = json['kind'];
@ -49,8 +39,6 @@ class PusherData {
String url;
String format;
PusherData({this.url, this.format});
PusherData.fromJson(Map<String, dynamic> json) {
url = json['url'];
format = json['format'];
@ -58,8 +46,8 @@ class PusherData {
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
data['url'] = url;
data['format'] = format;
if (url != null) data['url'] = url;
if (format != null) data['format'] = format;
return data;
}
}

View file

@ -3,8 +3,6 @@ class WellKnownInformations {
MHomeserver mIdentityServer;
Map<String, dynamic> content;
WellKnownInformations({this.mHomeserver, this.mIdentityServer});
WellKnownInformations.fromJson(Map<String, dynamic> json) {
content = json;
mHomeserver = json['m.homeserver'] != null
@ -19,8 +17,6 @@ class WellKnownInformations {
class MHomeserver {
String baseUrl;
MHomeserver({this.baseUrl});
MHomeserver.fromJson(Map<String, dynamic> json) {
baseUrl = json['base_url'];
}

View file

@ -411,6 +411,12 @@ void main() {
expect(openId.tokenType, 'Bearer');
expect(openId.matrixServerName, 'example.com');
expect(openId.expiresIn, 3600);
expect(openId.toJson(), {
'access_token': 'SomeT0kenHere',
'token_type': 'Bearer',
'matrix_server_name': 'example.com',
'expires_in': 3600
});
});
test('createRoom', () async {

View file

@ -0,0 +1,213 @@
/*
* Copyright (c) 2019 Zender & Kurtz GbR.
*
* Authors:
* Christian Pauly <krille@famedly.com>
* Marcel Radzio <mtrnord@famedly.com>
*
* This file is part of famedlysdk.
*
* famedlysdk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* famedlysdk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:famedlysdk/famedlysdk.dart';
class MatrixDefaultLocalizations extends MatrixLocalizations {
const MatrixDefaultLocalizations();
@override
String acceptedTheInvitation(String targetName) =>
'$targetName accepted the invitation';
@override
String activatedEndToEndEncryption(String senderName) =>
'$senderName activated end to end encryption';
@override
String get anyoneCanJoin => 'Anyone can join';
@override
String bannedUser(String senderName, String targetName) =>
'$senderName banned $targetName';
@override
String changedTheChatAvatar(String senderName) =>
'$senderName changed the chat avatar';
@override
String changedTheChatDescriptionTo(String senderName, String content) =>
'$senderName changed the chat description to $content';
@override
String changedTheChatNameTo(String senderName, String content) =>
'$senderName changed the chat name to $content';
@override
String changedTheChatPermissions(String senderName) =>
'$senderName changed the chat permissions';
@override
String changedTheDisplaynameTo(String targetName, String newDisplayname) =>
'$targetName changed the displayname to $newDisplayname';
@override
String changedTheGuestAccessRules(String senderName) =>
'$senderName changed the guest access rules';
@override
String changedTheGuestAccessRulesTo(
String senderName, String localizedString) =>
'$senderName changed the guest access rules to $localizedString';
@override
String changedTheHistoryVisibility(String senderName) =>
'$senderName changed the history visibility';
@override
String changedTheHistoryVisibilityTo(
String senderName, String localizedString) =>
'$senderName changed the history visibility to $localizedString';
@override
String changedTheJoinRules(String senderName) =>
'$senderName changed the join rules';
@override
String changedTheJoinRulesTo(String senderName, String localizedString) =>
'$senderName changed the join rules to $localizedString';
@override
String changedTheProfileAvatar(String targetName) =>
'$targetName changed the profile avatar';
@override
String changedTheRoomAliases(String senderName) =>
'$senderName changed the room aliases';
@override
String changedTheRoomInvitationLink(String senderName) =>
'$senderName changed the room invitation link';
@override
String get channelCorruptedDecryptError =>
'The secure channel has been corrupted';
@override
String couldNotDecryptMessage(String errorText) =>
'Could not decrypt message: $errorText';
@override
String createdTheChat(String senderName) => '$senderName created the chat';
@override
String get emptyChat => 'Empty chat';
@override
String get encryptionNotEnabled => 'Encryption not enabled';
@override
String get fromJoining => 'From joining';
@override
String get fromTheInvitation => 'From the invitation';
@override
String groupWith(String displayname) => 'Group with $displayname';
@override
String get guestsAreForbidden => 'Guests are forbidden';
@override
String get guestsCanJoin => 'Guests can join';
@override
String hasWithdrawnTheInvitationFor(String senderName, String targetName) =>
'$senderName has withdrawn the invitation for $targetName';
@override
String invitedUser(String senderName, String targetName) =>
'$senderName has invited $targetName';
@override
String get invitedUsersOnly => 'Invited users only';
@override
String joinedTheChat(String targetName) => '$targetName joined the chat';
@override
String kicked(String senderName, String targetName) =>
'$senderName kicked $targetName';
@override
String kickedAndBanned(String senderName, String targetName) =>
'$senderName banned $targetName';
@override
String get needPantalaimonWarning => 'Need pantalaimon';
@override
String get noPermission => 'No permission';
@override
String redactedAnEvent(String senderName) => '$senderName redacted an event';
@override
String rejectedTheInvitation(String targetName) =>
'$targetName rejected the invitation';
@override
String removedBy(String calcDisplayname) => 'Removed by $calcDisplayname';
@override
String get roomHasBeenUpgraded => 'Room has been upgraded';
@override
String sentAFile(String senderName) => '$senderName sent a file';
@override
String sentAPicture(String senderName) => '$senderName sent a picture';
@override
String sentASticker(String senderName) => '$senderName sent a sticker';
@override
String sentAVideo(String senderName) => '$senderName sent a video';
@override
String sentAnAudio(String senderName) => '$senderName sent an audio';
@override
String sharedTheLocation(String senderName) =>
'$senderName shared the location';
@override
String unbannedUser(String senderName, String targetName) =>
'$senderName unbanned $targetName';
@override
String get unknownEncryptionAlgorithm => 'Unknown encryption algorithm';
@override
String unknownEvent(String typeKey) => 'Unknown event $typeKey';
@override
String userLeftTheChat(String targetName) => '$targetName left the chat';
@override
String get visibleForAllParticipants => 'Visible for all participants';
@override
String get visibleForEveryone => 'Visible for everyone';
@override
String get you => 'You';
}

View file

@ -0,0 +1,71 @@
/*
* Copyright (c) 2019 Zender & Kurtz GbR.
*
* Authors:
* Christian Pauly <krille@famedly.com>
* Marcel Radzio <mtrnord@famedly.com>
*
* This file is part of famedlysdk.
*
* famedlysdk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* famedlysdk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:famedlysdk/famedlysdk.dart';
import 'package:http/http.dart';
import 'package:test/test.dart';
void main() {
/// All Tests related to device keys
group('Matrix Exception', () {
test('Matrix Exception', () async {
final matrixException = MatrixException(
Response(
'{"flows":[{"stages":["example.type.foo"]}],"params":{"example.type.baz":{"example_key":"foobar"}},"session":"xxxxxxyz","completed":["example.type.foo"]}',
401,
),
);
expect(matrixException.errcode, 'M_FORBIDDEN');
final flows = matrixException.authenticationFlows;
expect(flows.length, 1);
expect(flows.first.stages.length, 1);
expect(flows.first.stages.first, 'example.type.foo');
expect(
matrixException.authenticationParams['example.type.baz'],
{'example_key': 'foobar'},
);
expect(matrixException.completedAuthenticationFlows.length, 1);
expect(matrixException.completedAuthenticationFlows.first,
'example.type.foo');
expect(matrixException.session, 'xxxxxxyz');
});
test('Unknown Exception', () async {
final matrixException = MatrixException(
Response(
'{"errcode":"M_HAHA","error":"HAHA","retry_after_ms":500}',
401,
),
);
expect(matrixException.error, MatrixError.M_UNKNOWN);
expect(matrixException.retryAfterMs, 500);
});
test('Missing Exception', () async {
final matrixException = MatrixException(
Response(
'{"error":"HAHA"}',
401,
),
);
expect(matrixException.error, MatrixError.M_UNKNOWN);
});
});
}

View file

@ -0,0 +1,52 @@
/*
* Copyright (c) 2019 Zender & Kurtz GbR.
*
* Authors:
* Christian Pauly <krille@famedly.com>
* Marcel Radzio <mtrnord@famedly.com>
*
* This file is part of famedlysdk.
*
* famedlysdk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* famedlysdk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:typed_data';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:test/test.dart';
import 'package:olm/olm.dart' as olm;
void main() {
/// All Tests related to device keys
group('Matrix File', () {
test('Decrypt', () async {
final text = 'hello world';
final file = MatrixFile(
path: '/path/to/file.txt',
bytes: Uint8List.fromList(text.codeUnits),
);
var olmEnabled = true;
try {
await olm.init();
olm.Account();
} catch (_) {
olmEnabled = false;
}
if (olmEnabled) {
final encryptedFile = await file.encrypt();
expect(encryptedFile != null, true);
}
});
});
}

View file

@ -45,6 +45,8 @@ void main() {
expect('\$test:example.com'.sigil, '\$');
expect(mxId.localpart, 'test');
expect(mxId.domain, 'example.com');
expect(mxId.equals('@Test:example.com'), true);
expect(mxId.equals('@test:example.org'), false);
});
});
}

View file

@ -0,0 +1,65 @@
/*
* Copyright (c) 2019 Zender & Kurtz GbR.
*
* Authors:
* Christian Pauly <krille@famedly.com>
* Marcel Radzio <mtrnord@famedly.com>
*
* This file is part of famedlysdk.
*
* famedlysdk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* famedlysdk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:famedlysdk/famedlysdk.dart';
import 'package:test/test.dart';
import 'matrix_default_localizations.dart';
void main() {
/// All Tests related to device keys
group('Matrix Localizations', () {
test('Matrix Localizations', () {
expect(
HistoryVisibility.invited
.getLocalizedString(MatrixDefaultLocalizations()),
'From the invitation');
expect(
HistoryVisibility.joined
.getLocalizedString(MatrixDefaultLocalizations()),
'From joining');
expect(
HistoryVisibility.shared
.getLocalizedString(MatrixDefaultLocalizations()),
'Visible for all participants');
expect(
HistoryVisibility.world_readable
.getLocalizedString(MatrixDefaultLocalizations()),
'Visible for everyone');
expect(
GuestAccess.can_join.getLocalizedString(MatrixDefaultLocalizations()),
'Guests can join');
expect(
GuestAccess.forbidden
.getLocalizedString(MatrixDefaultLocalizations()),
'Guests are forbidden');
expect(JoinRules.invite.getLocalizedString(MatrixDefaultLocalizations()),
'Invited users only');
expect(JoinRules.public.getLocalizedString(MatrixDefaultLocalizations()),
'Anyone can join');
expect(JoinRules.private.getLocalizedString(MatrixDefaultLocalizations()),
'private');
expect(JoinRules.knock.getLocalizedString(MatrixDefaultLocalizations()),
'knock');
});
});
}

View file

@ -0,0 +1,59 @@
/*
* Copyright (c) 2019 Zender & Kurtz GbR.
*
* Authors:
* Christian Pauly <krille@famedly.com>
* Marcel Radzio <mtrnord@famedly.com>
*
* This file is part of famedlysdk.
*
* famedlysdk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* famedlysdk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:famedlysdk/famedlysdk.dart';
import 'package:test/test.dart';
import 'fake_matrix_api.dart';
void main() {
/// All Tests related to device keys
group('Public Rooms Response', () {
Client client;
test('Public Rooms Response', () async {
client = Client('testclient', debug: true);
client.httpClient = FakeMatrixApi();
await client.checkServer('https://fakeServer.notExisting');
final responseMap = {
'chunk': [
{
'aliases': ['#murrays:cheese.bar'],
'avatar_url': 'mxc://bleeker.street/CHEDDARandBRIE',
'guest_can_join': false,
'name': 'CHEESE',
'num_joined_members': 37,
'room_id': '1234',
'topic': 'Tasty tasty cheese',
'world_readable': true
}
],
'next_batch': 'p190q',
'prev_batch': 'p1902',
'total_room_count_estimate': 115
};
final publicRoomsResponse =
PublicRoomsResponse.fromJson(responseMap, client);
await publicRoomsResponse.publicRooms.first.join();
});
});
}

45
test/pusher_test.dart Normal file
View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2019 Zender & Kurtz GbR.
*
* Authors:
* Christian Pauly <krille@famedly.com>
* Marcel Radzio <mtrnord@famedly.com>
*
* This file is part of famedlysdk.
*
* famedlysdk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* famedlysdk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:famedlysdk/src/utils/pusher.dart';
import 'package:test/test.dart';
void main() {
/// All Tests related to device keys
group('Pusher', () {
test('Pusher', () {
final rawPusher = {
'pushkey': 'Xp/MzCt8/9DcSNE9cuiaoT5Ac55job3TdLSSmtmYl4A=',
'kind': 'http',
'app_id': 'face.mcapp.appy.prod',
'app_display_name': 'Appy McAppface',
'device_display_name': "Alice's Phone",
'profile_tag': 'xyz',
'lang': 'en-US',
'data': {'url': 'https://example.com/_matrix/push/v1/notify'}
};
final pusher = Pusher.fromJson(rawPusher);
expect(pusher.toJson(), rawPusher);
});
});
}

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2019 Zender & Kurtz GbR.
*
* Authors:
* Christian Pauly <krille@famedly.com>
* Marcel Radzio <mtrnord@famedly.com>
*
* This file is part of famedlysdk.
*
* famedlysdk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* famedlysdk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:famedlysdk/famedlysdk.dart';
import 'package:test/test.dart';
void main() {
/// All Tests related to device keys
group('WellKnownInformations', () {
test('WellKnownInformations', () {
final json = {
'm.homeserver': {'base_url': 'https://matrix.example.com'},
'm.identity_server': {'base_url': 'https://identity.example.com'},
'org.example.custom.property': {
'app_url': 'https://custom.app.example.org'
}
};
WellKnownInformations.fromJson(json);
});
});
}