1940 lines
		
	
	
		
			68 KiB
		
	
	
	
		
			Dart
		
	
	
	
			
		
		
	
	
			1940 lines
		
	
	
		
			68 KiB
		
	
	
	
		
			Dart
		
	
	
	
| /* MIT License
 | |
| *
 | |
| * Copyright (C) 2019, 2020, 2021 Famedly GmbH
 | |
| *
 | |
| * Permission is hereby granted, free of charge, to any person obtaining a copy
 | |
| * of this software and associated documentation files (the "Software"), to deal
 | |
| * in the Software without restriction, including without limitation the rights
 | |
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | |
| * copies of the Software, and to permit persons to whom the Software is
 | |
| * furnished to do so, subject to the following conditions:
 | |
| *
 | |
| * The above copyright notice and this permission notice shall be included in all
 | |
| * copies or substantial portions of the Software.
 | |
| *
 | |
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | |
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | |
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | |
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | |
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | |
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 | |
| * SOFTWARE.
 | |
| */
 | |
| 
 | |
| import 'dart:typed_data';
 | |
| 
 | |
| import 'package:matrix_api_lite/fake_matrix_api.dart';
 | |
| import 'package:matrix_api_lite/matrix_api_lite.dart';
 | |
| import 'package:test/test.dart';
 | |
| 
 | |
| void main() {
 | |
|   /// All Tests related to device keys
 | |
|   group('Matrix API', () {
 | |
|     test('Logger', () async {
 | |
|       Logs().level = Level.verbose;
 | |
|       Logs().v('Test log');
 | |
|       Logs().d('Test log');
 | |
|       Logs().w('Test log');
 | |
|       Logs().e('Test log');
 | |
|       Logs().wtf('Test log');
 | |
|       Logs().v('Test log', Exception('There has been a verbose'));
 | |
|       Logs().d('Test log', Exception('Test'));
 | |
|       Logs().w('Test log', Exception('Very bad error'));
 | |
|       Logs().e('Test log', Exception('Test'), StackTrace.current);
 | |
|       Logs().wtf('Test log', Exception('Test'), StackTrace.current);
 | |
|     });
 | |
|     Logs().level = Level.error;
 | |
|     final matrixApi = MatrixApi(
 | |
|       httpClient: FakeMatrixApi(),
 | |
|     );
 | |
|     test('MatrixException test', () async {
 | |
|       final exception = MatrixException.fromJson({
 | |
|         'flows': [
 | |
|           {
 | |
|             'stages': ['example.type.foo']
 | |
|           }
 | |
|         ],
 | |
|         'params': {
 | |
|           'example.type.baz': {'example_key': 'foobar'}
 | |
|         },
 | |
|         'session': 'xxxxxxyz',
 | |
|         'completed': ['example.type.foo']
 | |
|       });
 | |
|       expect(exception.authenticationFlows!.first.stages.first,
 | |
|           'example.type.foo');
 | |
|       expect(exception.authenticationParams!['example.type.baz'],
 | |
|           {'example_key': 'foobar'});
 | |
|       expect(exception.session, 'xxxxxxyz');
 | |
|       expect(exception.completedAuthenticationFlows, ['example.type.foo']);
 | |
|       expect(exception.requireAdditionalAuthentication, true);
 | |
|       expect(exception.retryAfterMs, null);
 | |
|       expect(exception.error, MatrixError.M_UNKNOWN);
 | |
|       expect(exception.errcode, 'M_FORBIDDEN');
 | |
|       expect(exception.errorMessage, 'Require additional authentication');
 | |
|     });
 | |
|     test('triggerNotFoundError', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       bool error;
 | |
|       error = false;
 | |
|       try {
 | |
|         await matrixApi.request(RequestType.GET, '/fake/path');
 | |
|       } catch (_) {
 | |
|         error = true;
 | |
|       }
 | |
|       expect(error, true);
 | |
|       error = false;
 | |
|       try {
 | |
|         await matrixApi.request(RequestType.POST, '/fake/path');
 | |
|       } catch (_) {
 | |
|         error = true;
 | |
|       }
 | |
|       expect(error, true);
 | |
|       error = false;
 | |
|       try {
 | |
|         await matrixApi.request(RequestType.PUT, '/fake/path');
 | |
|       } catch (_) {
 | |
|         error = true;
 | |
|       }
 | |
|       expect(error, true);
 | |
|       error = false;
 | |
|       try {
 | |
|         await matrixApi.request(RequestType.DELETE, '/fake/path');
 | |
|       } catch (_) {
 | |
|         error = true;
 | |
|       }
 | |
|       expect(error, true);
 | |
|       error = false;
 | |
|       try {
 | |
|         await matrixApi.request(RequestType.GET, '/path/to/auth/error/');
 | |
|       } catch (exception) {
 | |
|         expect(exception is MatrixException, true);
 | |
|         expect((exception as MatrixException).errcode, 'M_FORBIDDEN');
 | |
|         expect(exception.error, MatrixError.M_FORBIDDEN);
 | |
|         expect(exception.errorMessage, 'Blabla');
 | |
|         expect(exception.requireAdditionalAuthentication, false);
 | |
|         expect(exception.toString(), 'M_FORBIDDEN: Blabla');
 | |
|         error = true;
 | |
|       }
 | |
|       expect(error, true);
 | |
|       matrixApi.homeserver = null;
 | |
|     });
 | |
|     test('getSupportedVersions', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       final supportedVersions = await matrixApi.getVersions();
 | |
|       expect(supportedVersions.versions.contains('r0.5.0'), true);
 | |
|       expect(supportedVersions.unstableFeatures!['m.lazy_load_members'], true);
 | |
|       expect(FakeMatrixApi.api['GET'],
 | |
|           supportedVersions.toJson());
 | |
|       matrixApi.homeserver = null;
 | |
|     });
 | |
|     test('getWellKnownInformation', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       final wellKnownInformation = await matrixApi.getWellknown();
 | |
|       expect(wellKnownInformation.mHomeserver.baseUrl,
 | |
|           Uri.parse('https://fakeserver.notexisting'));
 | |
|       expect(wellKnownInformation.toJson(), {
 | |
|         'm.homeserver': {'base_url': 'https://fakeserver.notexisting'},
 | |
|         'm.identity_server': {
 | |
|           'base_url': 'https://identity.fakeserver.notexisting'
 | |
|         },
 | |
|         'org.example.custom.property': {
 | |
|           'app_url': 'https://custom.app.fakeserver.notexisting'
 | |
|         }
 | |
|       });
 | |
|     });
 | |
|     test('getLoginTypes', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       final loginTypes = await matrixApi.getLoginFlows();
 | |
|       expect(loginTypes?.first.type, 'm.login.password');
 | |
|       expect(FakeMatrixApi.api['GET'],
 | |
|           {'flows': loginTypes?.map((x) => x.toJson()).toList()});
 | |
|       matrixApi.homeserver = null;
 | |
|     });
 | |
|     test('login', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       final loginResponse = await matrixApi.login(
 | |
|         LoginType.mLoginPassword,
 | |
|         identifier: AuthenticationUserIdentifier(user: 'username'),
 | |
|       );
 | |
|       expect(FakeMatrixApi.api['POST'],
 | |
|           loginResponse.toJson());
 | |
|       matrixApi.homeserver = null;
 | |
|     });
 | |
|     test('logout', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       await matrixApi.logout();
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('logoutAll', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       await matrixApi.logoutAll();
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('register', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       final registerResponse =
 | |
|           await matrixApi.register(kind: AccountKind.guest, username: 'test');
 | |
|       expect(FakeMatrixApi.api['POST'],
 | |
|           registerResponse.toJson());
 | |
|       matrixApi.homeserver = null;
 | |
|     });
 | |
|     test('requestEmailToken', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       final response = await matrixApi.requestEmailToken(
 | |
|         'alice@example.com',
 | |
|         '1234',
 | |
|         1,
 | |
|         nextLink: 'https://example.com',
 | |
|         idServer: 'https://example.com',
 | |
|         idAccessToken: '1234',
 | |
|       );
 | |
|       expect(
 | |
|           FakeMatrixApi
 | |
|               .api['POST'],
 | |
|           response.toJson());
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestMsisdnToken', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       final response = await matrixApi.requestMsisdnToken(
 | |
|         'en',
 | |
|         '1234',
 | |
|         '1234',
 | |
|         1,
 | |
|         nextLink: 'https://example.com',
 | |
|         idServer: 'https://example.com',
 | |
|         idAccessToken: '1234',
 | |
|       );
 | |
|       expect(
 | |
|           FakeMatrixApi
 | |
|               .api['POST'],
 | |
|           response.toJson());
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('changePassword', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       await matrixApi.changePassword(
 | |
|         '1234',
 | |
|         auth: AuthenticationData.fromJson({
 | |
|           'type': 'example.type.foo',
 | |
|           'session': 'xxxxx',
 | |
|           'example_credential': 'verypoorsharedsecret'
 | |
|         }),
 | |
|       );
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('resetPasswordUsingEmail', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       await matrixApi.resetPasswordUsingEmail(
 | |
|         'alice@example.com',
 | |
|         '1234',
 | |
|         1,
 | |
|         nextLink: 'https://example.com',
 | |
|         idServer: 'https://example.com',
 | |
|         idAccessToken: '1234',
 | |
|       );
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('resetPasswordUsingMsisdn', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       await matrixApi.resetPasswordUsingMsisdn(
 | |
|         'en',
 | |
|         '1234',
 | |
|         '1234',
 | |
|         1,
 | |
|         nextLink: 'https://example.com',
 | |
|         idServer: 'https://example.com',
 | |
|         idAccessToken: '1234',
 | |
|       );
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('deactivateAccount', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       final response = await matrixApi.deactivateAccount(
 | |
|         idServer: 'https://example.com',
 | |
|         auth: AuthenticationData.fromJson({
 | |
|           'type': 'example.type.foo',
 | |
|           'session': 'xxxxx',
 | |
|           'example_credential': 'verypoorsharedsecret'
 | |
|         }),
 | |
|       );
 | |
|       expect(response, IdServerUnbindResult.success);
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('usernameAvailable', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       final loginResponse =
 | |
|           await matrixApi.checkUsernameAvailability('testuser');
 | |
|       expect(loginResponse, true);
 | |
|       matrixApi.homeserver = null;
 | |
|     });
 | |
|     test('getThirdPartyIdentifiers', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       final response = await matrixApi.getAccount3PIDs();
 | |
|       expect(FakeMatrixApi.api['GET'],
 | |
|           {'threepids': response?.map((t) => t.toJson()).toList()});
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('addThirdPartyIdentifier', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       await matrixApi.add3PID('1234', '1234',
 | |
|           auth: AuthenticationData.fromJson({'type': 'm.login.dummy'}));
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('bindThirdPartyIdentifier', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       await matrixApi.bind3PID(
 | |
|         '1234',
 | |
|         '1234',
 | |
|         'https://example.com',
 | |
|         '1234',
 | |
|       );
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('deleteThirdPartyIdentifier', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       final response = await matrixApi.delete3pidFromAccount(
 | |
|         'alice@example.com',
 | |
|         ThirdPartyIdentifierMedium.email,
 | |
|         idServer: 'https://example.com',
 | |
|       );
 | |
|       expect(response, IdServerUnbindResult.success);
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('unbindThirdPartyIdentifier', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       final response = await matrixApi.unbind3pidFromAccount(
 | |
|         'alice@example.com',
 | |
|         ThirdPartyIdentifierMedium.email,
 | |
|         idServer: 'https://example.com',
 | |
|       );
 | |
|       expect(response, IdServerUnbindResult.success);
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestEmailValidationToken', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       await matrixApi.requestEmailValidationToken(
 | |
|         'alice@example.com',
 | |
|         '1234',
 | |
|         1,
 | |
|         nextLink: 'https://example.com',
 | |
|         idServer: 'https://example.com',
 | |
|         idAccessToken: '1234',
 | |
|       );
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestMsisdnValidationToken', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       await matrixApi.requestMsisdnValidationToken(
 | |
|         'en',
 | |
|         '1234',
 | |
|         '1234',
 | |
|         1,
 | |
|         nextLink: 'https://example.com',
 | |
|         idServer: 'https://example.com',
 | |
|         idAccessToken: '1234',
 | |
|       );
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestMsisdnValidationToken', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       final response = await matrixApi.getTokenOwner();
 | |
|       expect(response.userId, 'alice@example.com');
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('getCapabilities', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       final response = await matrixApi.getCapabilities();
 | |
|       expect(FakeMatrixApi.api['GET'],
 | |
|           {'capabilities': response.toJson()});
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('uploadFilter', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       final response =
 | |
|           await matrixApi.defineFilter('alice@example.com', Filter());
 | |
|       expect(response, '1234');
 | |
|       final filter = Filter(
 | |
|         room: RoomFilter(
 | |
|           notRooms: ['!1234'],
 | |
|           rooms: ['!1234'],
 | |
|           ephemeral: StateFilter(
 | |
|             limit: 10,
 | |
|             senders: ['@alice:example.com'],
 | |
|             types: ['type1'],
 | |
|             notTypes: ['type2'],
 | |
|             notRooms: ['!1234'],
 | |
|             notSenders: ['@bob:example.com'],
 | |
|             lazyLoadMembers: true,
 | |
|             includeRedundantMembers: false,
 | |
|             containsUrl: true,
 | |
|           ),
 | |
|           includeLeave: true,
 | |
|           state: StateFilter(),
 | |
|           timeline: StateFilter(),
 | |
|           accountData: StateFilter(limit: 10, types: ['type1']),
 | |
|         ),
 | |
|         presence: StateFilter(
 | |
|           limit: 10,
 | |
|           senders: ['@alice:example.com'],
 | |
|           types: ['type1'],
 | |
|           notRooms: ['!1234'],
 | |
|           notSenders: ['@bob:example.com'],
 | |
|         ),
 | |
|         eventFormat: EventFormat.client,
 | |
|         eventFields: ['type', 'content', 'sender'],
 | |
|         accountData: EventFilter(
 | |
|           types: ['m.accountdatatest'],
 | |
|           notSenders: ['@alice:example.com'],
 | |
|         ),
 | |
|       );
 | |
|       expect(filter.toJson(), {
 | |
|         'room': {
 | |
|           'not_rooms': ['!1234'],
 | |
|           'rooms': ['!1234'],
 | |
|           'ephemeral': {
 | |
|             'limit': 10,
 | |
|             'senders': ['@alice:example.com'],
 | |
|             'types': ['type1'],
 | |
|             'not_rooms': ['!1234'],
 | |
|             'not_senders': ['@bob:example.com'],
 | |
|             'not_types': ['type2'],
 | |
|             'lazy_load_members': true,
 | |
|             'include_redundant_members': false,
 | |
|             'contains_url': true,
 | |
|           },
 | |
|           'account_data': {
 | |
|             'limit': 10,
 | |
|             'types': ['type1'],
 | |
|           },
 | |
|           'include_leave': true,
 | |
|           'state': {},
 | |
|           'timeline': {},
 | |
|         },
 | |
|         'presence': {
 | |
|           'limit': 10,
 | |
|           'senders': ['@alice:example.com'],
 | |
|           'types': ['type1'],
 | |
|           'not_rooms': ['!1234'],
 | |
|           'not_senders': ['@bob:example.com']
 | |
|         },
 | |
|         'event_format': 'client',
 | |
|         'event_fields': ['type', 'content', 'sender'],
 | |
|         'account_data': {
 | |
|           'types': ['m.accountdatatest'],
 | |
|           'not_senders': ['@alice:example.com']
 | |
|         },
 | |
|       });
 | |
|       await matrixApi.defineFilter(
 | |
|         'alice@example.com',
 | |
|         filter,
 | |
|       );
 | |
|       final filterMap = {
 | |
|         'room': {
 | |
|           'state': {
 | |
|             'types': ['m.room.*'],
 | |
|             'not_rooms': ['!726s6s6q:example.com']
 | |
|           },
 | |
|           'timeline': {
 | |
|             'limit': 10,
 | |
|             'types': ['m.room.message'],
 | |
|             'not_rooms': ['!726s6s6q:example.com'],
 | |
|             'not_senders': ['@spam:example.com']
 | |
|           },
 | |
|           'ephemeral': {
 | |
|             'types': ['m.receipt', 'm.typing'],
 | |
|             'not_rooms': ['!726s6s6q:example.com'],
 | |
|             'not_senders': ['@spam:example.com']
 | |
|           }
 | |
|         },
 | |
|         'presence': {
 | |
|           'types': ['m.presence'],
 | |
|           'not_senders': ['@alice:example.com']
 | |
|         },
 | |
|         'account_data': {
 | |
|           'types': ['m.accountdatatest'],
 | |
|           'not_senders': ['@alice:example.com']
 | |
|         },
 | |
|         'event_format': 'client',
 | |
|         'event_fields': ['type', 'content', 'sender']
 | |
|       };
 | |
|       expect(filterMap, Filter.fromJson(filterMap).toJson());
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('downloadFilter', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       await matrixApi.getFilter('alice@example.com', '1234');
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('sync', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       final response = await matrixApi.sync(
 | |
|         filter: '{}',
 | |
|         since: '1234',
 | |
|         fullState: false,
 | |
|         setPresence: PresenceType.unavailable,
 | |
|         timeout: 15,
 | |
|       );
 | |
|       expect(
 | |
|           FakeMatrixApi.api['GET'] as Map?,
 | |
|           response.toJson());
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestEvent', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final event =
 | |
|           await matrixApi.getOneRoomEvent('!localpart:server.abc', '1234');
 | |
|       expect(event.eventId, '143273582443PhrSn:example.org');
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestStateContent', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.requestStateContent(
 | |
|         '!localpart:server.abc',
 | |
|         'm.room.member',
 | |
|         '@getme:example.com',
 | |
|       );
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestStates', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final states = await matrixApi.getRoomState('!localpart:server.abc');
 | |
|       expect(states.length, 4);
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestMembers', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final states = await matrixApi.getMembersByRoom(
 | |
|         '!localpart:server.abc',
 | |
|         at: '1234',
 | |
|         membership: Membership.join,
 | |
|         notMembership: Membership.leave,
 | |
|       );
 | |
|       expect(states?.length, 1);
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestJoinedMembers', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final states = await matrixApi.getJoinedMembersByRoom(
 | |
|         '!localpart:server.abc',
 | |
|       );
 | |
|       expect(states?.length, 1);
 | |
|       expect(states?['@bar:example.com']?.toJson(), {
 | |
|         'display_name': 'Bar',
 | |
|         'avatar_url': 'mxc://riot.ovh/printErCATzZijQsSDWorRaK'
 | |
|       });
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestMessages', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final timelineHistoryResponse = await matrixApi.getRoomEvents(
 | |
|         '!localpart:server.abc',
 | |
|         '1234',
 | |
|         Direction.b,
 | |
|         limit: 10,
 | |
|         filter: '{"lazy_load_members":true}',
 | |
|         to: '1234',
 | |
|       );
 | |
| 
 | |
|       expect(
 | |
|           FakeMatrixApi.api['GET'] as Map?,
 | |
|           timelineHistoryResponse.toJson());
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('sendState', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final eventId = await matrixApi.setRoomStateWithKey(
 | |
|           '!localpart:server.abc', 'm.room.avatar', '', {'url': 'mxc://1234'});
 | |
| 
 | |
|       expect(eventId, 'YUwRidLecu:example.com');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('sendMessage', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final eventId = await matrixApi.sendMessage(
 | |
|         '!localpart:server.abc',
 | |
|         'm.room.message',
 | |
|         '1234',
 | |
|         {'body': 'hello world', 'msgtype': 'm.text'},
 | |
|       );
 | |
| 
 | |
|       expect(eventId, 'YUwRidLecu:example.com');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('redact', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final eventId = await matrixApi.redactEvent(
 | |
|         '!localpart:server.abc',
 | |
|         '1234',
 | |
|         '1234',
 | |
|         reason: 'hello world',
 | |
|       );
 | |
| 
 | |
|       expect(eventId, 'YUwRidLecu:example.com');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('createRoom', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final roomId = await matrixApi.createRoom(
 | |
|         visibility: Visibility.public,
 | |
|         roomAliasName: '#testroom:example.com',
 | |
|         name: 'testroom',
 | |
|         topic: 'just for testing',
 | |
|         invite: ['@bob:example.com'],
 | |
|         invite3pid: [],
 | |
|         roomVersion: '2',
 | |
|         creationContent: {},
 | |
|         initialState: [],
 | |
|         preset: CreateRoomPreset.publicChat,
 | |
|         isDirect: false,
 | |
|         powerLevelContentOverride: {},
 | |
|       );
 | |
| 
 | |
|       expect(roomId, '!1234:fakeServer.notExisting');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('createRoomAlias', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.setRoomAlias(
 | |
|         '#testalias:example.com',
 | |
|         '!1234:example.com',
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestRoomAliasInformation', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final roomAliasInformation = await matrixApi.getRoomIdByAlias(
 | |
|         '#testalias:example.com',
 | |
|       );
 | |
| 
 | |
|       expect(
 | |
|           FakeMatrixApi.api['GET'],
 | |
|           roomAliasInformation.toJson());
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('removeRoomAlias', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.deleteRoomAlias('#testalias:example.com');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestRoomAliases', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final list = await matrixApi.getLocalAliases('!localpart:example.com');
 | |
|       expect(list.length, 3);
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestJoinedRooms', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final list = await matrixApi.getJoinedRooms();
 | |
|       expect(list.length, 1);
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('inviteUser', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.inviteUser('!localpart:example.com', '@bob:example.com');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('joinRoom', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final roomId = '!localpart:example.com';
 | |
|       final response = await matrixApi.joinRoomById(
 | |
|         roomId,
 | |
|         thirdPartySigned: ThirdPartySigned(
 | |
|           sender: '@bob:example.com',
 | |
|           mxid: '@alice:example.com',
 | |
|           token: '1234',
 | |
|           signatures: {
 | |
|             'example.org': {'ed25519:0': 'some9signature'}
 | |
|           },
 | |
|         ),
 | |
|       );
 | |
|       expect(response, roomId);
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('joinRoomOrAlias', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final roomId = '!localpart:example.com';
 | |
|       final response = await matrixApi.joinRoom(
 | |
|         roomId,
 | |
|         serverName: ['example.com', 'example.abc'],
 | |
|         thirdPartySigned: ThirdPartySigned(
 | |
|           sender: '@bob:example.com',
 | |
|           mxid: '@alice:example.com',
 | |
|           token: '1234',
 | |
|           signatures: {
 | |
|             'example.org': {'ed25519:0': 'some9signature'}
 | |
|           },
 | |
|         ),
 | |
|       );
 | |
|       expect(response, roomId);
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('leave', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.leaveRoom('!localpart:example.com');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('forget', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.forgetRoom('!localpart:example.com');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('kickFromRoom', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.kick(
 | |
|         '!localpart:example.com',
 | |
|         '@bob:example.com',
 | |
|         reason: 'test',
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('banFromRoom', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.ban(
 | |
|         '!localpart:example.com',
 | |
|         '@bob:example.com',
 | |
|         reason: 'test',
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('unbanInRoom', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.unban(
 | |
|         '!localpart:example.com',
 | |
|         '@bob:example.com',
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestRoomVisibility', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final visibility = await matrixApi
 | |
|           .getRoomVisibilityOnDirectory('!localpart:example.com');
 | |
|       expect(visibility, Visibility.public);
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('setRoomVisibility', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.setRoomVisibilityOnDirectory(
 | |
|           '!localpart:example.com', Visibility.private);
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestPublicRooms', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.getPublicRooms(
 | |
|         limit: 10,
 | |
|         since: '1234',
 | |
|         server: 'example.com',
 | |
|       );
 | |
| 
 | |
|       expect(
 | |
|           FakeMatrixApi.api['GET'],
 | |
|           response.toJson());
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('searchPublicRooms', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.queryPublicRooms(
 | |
|         limit: 10,
 | |
|         since: '1234',
 | |
|         server: 'example.com',
 | |
|         filter: PublicRoomQueryFilter(
 | |
|           genericSearchTerm: 'test',
 | |
|         ),
 | |
|         includeAllNetworks: false,
 | |
|         thirdPartyInstanceId: 'id',
 | |
|       );
 | |
| 
 | |
|       expect(
 | |
|           FakeMatrixApi
 | |
|               .api['POST'],
 | |
|           response.toJson());
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('searchUser', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.searchUserDirectory(
 | |
|         'test',
 | |
|         limit: 10,
 | |
|       );
 | |
| 
 | |
|       expect(FakeMatrixApi.api['POST'],
 | |
|           response.toJson());
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('setDisplayname', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.setDisplayName('@alice:example.com', 'Alice M');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestDisplayname', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.getDisplayName('@alice:example.com');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('setAvatarUrl', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.setAvatarUrl(
 | |
|         '@alice:example.com',
 | |
|         Uri.parse('mxc://test'),
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestAvatarUrl', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.getAvatarUrl('@alice:example.com');
 | |
|       expect(response, Uri.parse('mxc://test'));
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestProfile', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.getUserProfile('@alice:example.com');
 | |
|       expect(
 | |
|           FakeMatrixApi
 | |
|               .api['GET'],
 | |
|           response.toJson());
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestTurnServerCredentials', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.getTurnServer();
 | |
|       expect(FakeMatrixApi.api['GET'],
 | |
|           response.toJson());
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('sendTypingNotification', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.setTyping(
 | |
|         '@alice:example.com',
 | |
|         '!localpart:example.com',
 | |
|         true,
 | |
|         timeout: 10,
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('sendReceiptMarker', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.postReceipt(
 | |
|         '!localpart:example.com',
 | |
|         ReceiptType.mRead,
 | |
|         '\$1234:example.com',
 | |
|         {},
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('sendReadMarker', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.setReadMarker(
 | |
|         '!localpart:example.com',
 | |
|         '\$1234:example.com',
 | |
|         mRead: '\$1234:example.com',
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('sendPresence', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.setPresence(
 | |
|         '@alice:example.com',
 | |
|         PresenceType.offline,
 | |
|         statusMsg: 'test',
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestPresence', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.getPresence(
 | |
|         '@alice:example.com',
 | |
|       );
 | |
|       expect(
 | |
|           FakeMatrixApi.api['GET'],
 | |
|           response.toJson());
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('upload', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
|       final response =
 | |
|           await matrixApi.uploadContent(Uint8List(0), filename: 'file.jpeg');
 | |
|       expect(response, 'mxc://example.com/AQwafuaFswefuhsfAFAgsw');
 | |
|       var throwsException = false;
 | |
|       try {
 | |
|         await matrixApi.uploadContent(Uint8List(0), filename: 'file.jpg');
 | |
|       } catch (_) {
 | |
|         throwsException = true;
 | |
|       }
 | |
|       expect(throwsException, true);
 | |
|       matrixApi.homeserver = null;
 | |
|     });
 | |
|     test('requestOpenGraphDataForUrl', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final openGraphData = await matrixApi.getUrlPreview(
 | |
|         Uri.parse('https://matrix.org'),
 | |
|         ts: 10,
 | |
|       );
 | |
|       expect(
 | |
|           FakeMatrixApi.api['GET'],
 | |
|           openGraphData.toJson());
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('getConfig', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.getConfig();
 | |
|       expect(response.mUploadSize, 50000000);
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('sendToDevice', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.sendToDevice('m.test', '1234', {
 | |
|         '@alice:example.com': {
 | |
|           'TLLBEANAAG': {'example_content_key': 'value'}
 | |
|         }
 | |
|       });
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestDevices', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final devices = await matrixApi.getDevices();
 | |
|       expect(FakeMatrixApi.api['GET']['devices'],
 | |
|           devices?.map((i) => i.toJson()).toList());
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestDevice', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.getDevice('QBUAZIFURK');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('setDeviceMetadata', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.updateDevice('QBUAZIFURK', displayName: 'test');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('deleteDevice', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.deleteDevice('QBUAZIFURK');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('deleteDevices', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.deleteDevices(['QBUAZIFURK']);
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('uploadDeviceKeys', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.uploadKeys(
 | |
|         deviceKeys: MatrixDeviceKeys(
 | |
|           '@alice:example.com',
 | |
|           'ABCD',
 | |
|           ['caesar-chiffre'],
 | |
|           {},
 | |
|           {},
 | |
|           unsigned: {},
 | |
|         ),
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestDeviceKeys', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.queryKeys(
 | |
|         {
 | |
|           '@alice:example.com': [],
 | |
|         },
 | |
|         timeout: 10,
 | |
|         token: '1234',
 | |
|       );
 | |
|       expect(
 | |
|           response.deviceKeys!['@alice:example.com']!['JLAFKJWSCS']!
 | |
|               .deviceDisplayName,
 | |
|           'Alices mobile phone');
 | |
|       expect(
 | |
|           FakeMatrixApi
 | |
|               .api['POST'],
 | |
|           response.toJson());
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestOneTimeKeys', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.claimKeys(
 | |
|         {
 | |
|           '@alice:example.com': {'JLAFKJWSCS': 'signed_curve25519'}
 | |
|         },
 | |
|         timeout: 10,
 | |
|       );
 | |
|       expect(
 | |
|           FakeMatrixApi.api['POST'],
 | |
|           response.toJson());
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestDeviceListsUpdate', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.getKeysChanges('1234', '1234');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('uploadDeviceSigningKeys', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final masterKey = MatrixCrossSigningKey.fromJson({
 | |
|         'user_id': '@test:fakeServer.notExisting',
 | |
|         'usage': ['master'],
 | |
|         'keys': {
 | |
|           'ed25519:82mAXjsmbTbrE6zyShpR869jnrANO75H8nYY0nDLoJ8':
 | |
|               '82mAXjsmbTbrE6zyShpR869jnrANO75H8nYY0nDLoJ8',
 | |
|         },
 | |
|         'signatures': {},
 | |
|       });
 | |
|       final selfSigningKey = MatrixCrossSigningKey.fromJson({
 | |
|         'user_id': '@test:fakeServer.notExisting',
 | |
|         'usage': ['self_signing'],
 | |
|         'keys': {
 | |
|           'ed25519:F9ypFzgbISXCzxQhhSnXMkc1vq12Luna3Nw5rqViOJY':
 | |
|               'F9ypFzgbISXCzxQhhSnXMkc1vq12Luna3Nw5rqViOJY',
 | |
|         },
 | |
|         'signatures': {},
 | |
|       });
 | |
|       final userSigningKey = MatrixCrossSigningKey.fromJson({
 | |
|         'user_id': '@test:fakeServer.notExisting',
 | |
|         'usage': ['user_signing'],
 | |
|         'keys': {
 | |
|           'ed25519:0PiwulzJ/RU86LlzSSZ8St80HUMN3dqjKa/orIJoA0g':
 | |
|               '0PiwulzJ/RU86LlzSSZ8St80HUMN3dqjKa/orIJoA0g',
 | |
|         },
 | |
|         'signatures': {},
 | |
|       });
 | |
|       await matrixApi.uploadDeviceSigningKeys(
 | |
|           masterKey: masterKey,
 | |
|           selfSigningKey: selfSigningKey,
 | |
|           userSigningKey: userSigningKey);
 | |
|     });
 | |
|     test('uploadKeySignatures', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final key1 = MatrixDeviceKeys.fromJson({
 | |
|         'user_id': '@alice:example.com',
 | |
|         'device_id': 'JLAFKJWSCS',
 | |
|         'algorithms': [
 | |
|           AlgorithmTypes.olmV1Curve25519AesSha2,
 | |
|           AlgorithmTypes.megolmV1AesSha2
 | |
|         ],
 | |
|         'keys': {
 | |
|           'curve25519:JLAFKJWSCS':
 | |
|               '3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI',
 | |
|           'ed25519:JLAFKJWSCS': 'lEuiRJBit0IG6nUf5pUzWTUEsRVVe/HJkoKuEww9ULI'
 | |
|         },
 | |
|         'signatures': {
 | |
|           '@alice:example.com': {
 | |
|             'ed25519:JLAFKJWSCS':
 | |
|                 'dSO80A01XiigH3uBiDVx/EjzaoycHcjq9lfQX0uWsqxl2giMIiSPR8a4d291W1ihKJL/a+myXS367WT6NAIcBA'
 | |
|           }
 | |
|         },
 | |
|         'unsigned': {'device_display_name': 'Alices mobile phone'},
 | |
|       });
 | |
|       final key2 = MatrixDeviceKeys.fromJson({
 | |
|         'user_id': '@alice:example.com',
 | |
|         'device_id': 'JLAFKJWSCS',
 | |
|         'algorithms': [
 | |
|           AlgorithmTypes.olmV1Curve25519AesSha2,
 | |
|           AlgorithmTypes.megolmV1AesSha2
 | |
|         ],
 | |
|         'keys': {
 | |
|           'curve25519:JLAFKJWSCS':
 | |
|               '3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI',
 | |
|           'ed25519:JLAFKJWSCS': 'lEuiRJBit0IG6nUf5pUzWTUEsRVVe/HJkoKuEww9ULI'
 | |
|         },
 | |
|         'signatures': {
 | |
|           '@alice:example.com': {'ed25519:OTHERDEVICE': 'OTHERSIG'}
 | |
|         },
 | |
|         'unsigned': {'device_display_name': 'Alices mobile phone'},
 | |
|       });
 | |
|       final ret = await matrixApi.uploadKeySignatures([key1, key2]);
 | |
|       expect(
 | |
|         FakeMatrixApi.api['POST'],
 | |
|         ret.toJson(),
 | |
|       );
 | |
|     });
 | |
|     test('requestPushers', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.getPushers();
 | |
|       expect(
 | |
|         FakeMatrixApi.api['GET'],
 | |
|         {'pushers': response?.map((i) => i.toJson()).toList()},
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('setPusher', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.postPusher(
 | |
|         Pusher(
 | |
|           pushkey: '1234',
 | |
|           appId: 'app.id',
 | |
|           appDisplayName: 'appDisplayName',
 | |
|           deviceDisplayName: 'deviceDisplayName',
 | |
|           lang: 'en',
 | |
|           data: PusherData(
 | |
|               format: 'event_id_only', url: Uri.parse('https://matrix.org')),
 | |
|           profileTag: 'tag',
 | |
|           kind: 'http',
 | |
|         ),
 | |
|         append: true,
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestNotifications', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.getNotifications(
 | |
|         from: '1234',
 | |
|         limit: 10,
 | |
|         only: '1234',
 | |
|       );
 | |
|       expect(
 | |
|         FakeMatrixApi.api['GET'],
 | |
|         response.toJson(),
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestPushRules', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.getPushRules();
 | |
|       expect(
 | |
|         FakeMatrixApi.api['GET'],
 | |
|         {'global': response.toJson()},
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestPushRule', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response =
 | |
|           await matrixApi.getPushRule('global', PushRuleKind.content, 'nocake');
 | |
|       expect(
 | |
|         FakeMatrixApi
 | |
|             .api['GET'],
 | |
|         response.toJson(),
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('deletePushRule', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.deletePushRule('global', PushRuleKind.content, 'nocake');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('setPushRule', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.setPushRule(
 | |
|         'global',
 | |
|         PushRuleKind.content,
 | |
|         'nocake',
 | |
|         [PushRuleAction.notify],
 | |
|         before: '1',
 | |
|         after: '2',
 | |
|         conditions: [
 | |
|           PushCondition(
 | |
|             kind: 'event_match',
 | |
|             key: 'key',
 | |
|             pattern: 'pattern',
 | |
|             is$: '+',
 | |
|           )
 | |
|         ],
 | |
|         pattern: 'pattern',
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestPushRuleEnabled', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final enabled = await matrixApi.isPushRuleEnabled(
 | |
|           'global', PushRuleKind.content, 'nocake');
 | |
|       expect(enabled, true);
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('enablePushRule', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.setPushRuleEnabled(
 | |
|         'global',
 | |
|         PushRuleKind.content,
 | |
|         'nocake',
 | |
|         true,
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestPushRuleActions', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final actions = await matrixApi.getPushRuleActions(
 | |
|           'global', PushRuleKind.content, 'nocake');
 | |
|       expect(actions.first, PushRuleAction.notify);
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('setPushRuleActions', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.setPushRuleActions(
 | |
|         'global',
 | |
|         PushRuleKind.content,
 | |
|         'nocake',
 | |
|         [PushRuleAction.dontNotify],
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('globalSearch', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.search(Categories());
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('globalSearch', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response =
 | |
|           await matrixApi.getEvents(from: '1234', roomId: '!1234', timeout: 10);
 | |
|       expect(
 | |
|         FakeMatrixApi.api['GET'],
 | |
|         response.toJson(),
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestRoomTags', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.getRoomTags(
 | |
|           '@alice:example.com', '!localpart:example.com');
 | |
|       expect(
 | |
|         FakeMatrixApi.api['GET'],
 | |
|         {'tags': response?.map((k, v) => MapEntry(k, v.toJson()))},
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('addRoomTag', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.setRoomTag(
 | |
|         '@alice:example.com',
 | |
|         '!localpart:example.com',
 | |
|         'testtag',
 | |
|         order: 0.5,
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('addRoomTag', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.deleteRoomTag(
 | |
|         '@alice:example.com',
 | |
|         '!localpart:example.com',
 | |
|         'testtag',
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('setAccountData', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.setAccountData(
 | |
|         '@alice:example.com',
 | |
|         'test.account.data',
 | |
|         {'foo': 'bar'},
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestAccountData', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.getAccountData(
 | |
|         '@alice:example.com',
 | |
|         'test.account.data',
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('setRoomAccountData', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.setAccountDataPerRoom(
 | |
|         '@alice:example.com',
 | |
|         '1234',
 | |
|         'test.account.data',
 | |
|         {'foo': 'bar'},
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestRoomAccountData', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.getAccountDataPerRoom(
 | |
|         '@alice:example.com',
 | |
|         '1234',
 | |
|         'test.account.data',
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestWhoIsInfo', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.getWhoIs('@alice:example.com');
 | |
|       expect(
 | |
|         FakeMatrixApi
 | |
|             .api['GET'],
 | |
|         response.toJson(),
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestEventContext', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.getEventContext('1234', '1234',
 | |
|           limit: 10, filter: '{}');
 | |
|       expect(
 | |
|         FakeMatrixApi.api['GET'],
 | |
|         response.toJson(),
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('reportEvent', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.reportContent(
 | |
|         '1234',
 | |
|         '1234',
 | |
|         reason: 'test',
 | |
|         score: -100,
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestSupportedProtocols', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.requestSupportedProtocols();
 | |
|       expect(
 | |
|         FakeMatrixApi.api['GET'],
 | |
|         response.map((k, v) => MapEntry(k, v.toJson())),
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestSupportedProtocol', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.requestSupportedProtocol('irc');
 | |
|       expect(
 | |
|         FakeMatrixApi.api['GET'],
 | |
|         response.toJson(),
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestThirdPartyLocations', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.requestThirdPartyLocations('irc');
 | |
|       expect(
 | |
|         FakeMatrixApi.api['GET'],
 | |
|         response.map((i) => i.toJson()).toList(),
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestThirdPartyUsers', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.requestThirdPartyUsers('irc');
 | |
|       expect(
 | |
|         FakeMatrixApi.api['GET'],
 | |
|         response.map((i) => i.toJson()).toList(),
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestThirdPartyLocationsByAlias', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response =
 | |
|           await matrixApi.requestThirdPartyLocationsByAlias('1234');
 | |
|       expect(
 | |
|         FakeMatrixApi
 | |
|             .api['GET'],
 | |
|         response.map((i) => i.toJson()).toList(),
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestThirdPartyUsersByUserId', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.requestThirdPartyUsersByUserId('1234');
 | |
|       expect(
 | |
|         FakeMatrixApi.api['GET'],
 | |
|         response.map((i) => i.toJson()).toList(),
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('requestOpenIdCredentials', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final response = await matrixApi.requestOpenIdToken('1234', {});
 | |
|       expect(
 | |
|         FakeMatrixApi
 | |
|             .api['POST'],
 | |
|         response.toJson(),
 | |
|       );
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('upgradeRoom', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.upgradeRoom('1234', '2');
 | |
| 
 | |
|       matrixApi.homeserver = matrixApi.accessToken = null;
 | |
|     });
 | |
|     test('postRoomKeysVersion', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final algorithm = BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2;
 | |
|       final authData = <String, dynamic>{
 | |
|         'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM',
 | |
|         'signatures': {},
 | |
|       };
 | |
|       final ret = await matrixApi.postRoomKeysVersion(algorithm, authData);
 | |
|       expect(
 | |
|           FakeMatrixApi.api['POST']['version'],
 | |
|           ret);
 | |
|     });
 | |
|     test('getRoomKeysVersionCurrent', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final ret = await matrixApi.getRoomKeysVersionCurrent();
 | |
|       expect(
 | |
|           FakeMatrixApi.api['GET'],
 | |
|           ret.toJson());
 | |
|     });
 | |
|     test('putRoomKeysVersion', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final algorithm = BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2;
 | |
|       final authData = <String, dynamic>{
 | |
|         'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM',
 | |
|         'signatures': {},
 | |
|       };
 | |
|       await matrixApi.putRoomKeysVersion('5', algorithm, authData);
 | |
|     });
 | |
|     test('deleteRoomKeysBackup', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       await matrixApi.deleteRoomKeysBackup('5');
 | |
|     });
 | |
|     test('postRoomKeysKeyRoomIdSessionId', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final roomId = '!726s6s6q:example.com';
 | |
|       final sessionId = 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU';
 | |
|       final session = KeyBackupData.fromJson({
 | |
|         'first_message_index': 0,
 | |
|         'forwarded_count': 0,
 | |
|         'is_verified': true,
 | |
|         'session_data': {
 | |
|           'ephemeral': 'fwRxYh+seqLykz5mQCLypJ4/59URdcFJ2s69OU1dGRc',
 | |
|           'ciphertext':
 | |
|               '19jkQYlbgdP+VL9DH3qY/Dvpk6onJZgf+6frZFl1TinPCm9OMK9AZZLuM1haS9XLAUK1YsREgjBqfl6T+Tq8JlJ5ONZGg2Wttt24sGYc0iTMZJ8rXcNDeKMZhM96ETyjufJSeYoXLqifiVLDw9rrVBmNStF7PskYp040em+0OZ4pF85Cwsdf7l9V7MMynzh9BoXqVUCBiwT03PNYH9AEmNUxXX+6ZwCpe/saONv8MgGt5uGXMZIK29phA3D8jD6uV/WOHsB8NjHNq9FrfSEAsl+dAcS4uiYie4BKSSeQN+zGAQqu1MMW4OAdxGOuf8WpIINx7n+7cKQfxlmc/Cgg5+MmIm2H0oDwQ+Xu7aSxp1OCUzbxQRdjz6+tnbYmZBuH0Ov2RbEvC5tDb261LRqKXpub0llg5fqKHl01D0ahv4OAQgRs5oU+4mq+H2QGTwIFGFqP9tCRo0I+aICawpxYOfoLJpFW6KvEPnM2Lr3sl6Nq2fmkz6RL5F7nUtzxN8OKazLQpv8DOYzXbi7+ayEsqS0/EINetq7RfCqgjrEUgfNWYuFXWqvUT8lnxLdNu+8cyrJqh1UquFjXWTw1kWcJ0pkokVeBtK9YysCnF1UYh/Iv3rl2ZoYSSLNtuvMSYlYHggZ8xV8bz9S3X2/NwBycBiWIy5Ou/OuSX7trIKgkkmda0xjBWEM1a2acVuqu2OFbMn2zFxm2a3YwKP//OlIgMg',
 | |
|           'mac': 'QzKV/fgAs4U',
 | |
|         },
 | |
|       });
 | |
|       final ret = await matrixApi.postRoomKeysKeyRoomIdSessionId(
 | |
|           roomId, sessionId, '5', session);
 | |
|       expect(
 | |
|           FakeMatrixApi.api['PUT'],
 | |
|           ret.toJson());
 | |
|     });
 | |
|     test('getRoomKeysSingleKey', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final roomId = '!726s6s6q:example.com';
 | |
|       final sessionId = 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU';
 | |
|       final ret = await matrixApi.getRoomKeysSingleKey(roomId, sessionId, '5');
 | |
|       expect(
 | |
|           FakeMatrixApi.api['GET'],
 | |
|           ret.toJson());
 | |
|     });
 | |
|     test('deleteRoomKeysSingleKey', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final roomId = '!726s6s6q:example.com';
 | |
|       final sessionId = 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU';
 | |
|       final ret =
 | |
|           await matrixApi.deleteRoomKeysSingleKey(roomId, sessionId, '5');
 | |
|       expect(
 | |
|           FakeMatrixApi.api['DELETE'],
 | |
|           ret.toJson());
 | |
|     });
 | |
|     test('postRoomKeysKeyRoomId', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final roomId = '!726s6s6q:example.com';
 | |
|       final sessionId = 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU';
 | |
|       final session = RoomKeyBackup.fromJson({
 | |
|         'sessions': {
 | |
|           sessionId: {
 | |
|             'first_message_index': 0,
 | |
|             'forwarded_count': 0,
 | |
|             'is_verified': true,
 | |
|             'session_data': {
 | |
|               'ephemeral': 'fwRxYh+seqLykz5mQCLypJ4/59URdcFJ2s69OU1dGRc',
 | |
|               'ciphertext':
 | |
|                   '19jkQYlbgdP+VL9DH3qY/Dvpk6onJZgf+6frZFl1TinPCm9OMK9AZZLuM1haS9XLAUK1YsREgjBqfl6T+Tq8JlJ5ONZGg2Wttt24sGYc0iTMZJ8rXcNDeKMZhM96ETyjufJSeYoXLqifiVLDw9rrVBmNStF7PskYp040em+0OZ4pF85Cwsdf7l9V7MMynzh9BoXqVUCBiwT03PNYH9AEmNUxXX+6ZwCpe/saONv8MgGt5uGXMZIK29phA3D8jD6uV/WOHsB8NjHNq9FrfSEAsl+dAcS4uiYie4BKSSeQN+zGAQqu1MMW4OAdxGOuf8WpIINx7n+7cKQfxlmc/Cgg5+MmIm2H0oDwQ+Xu7aSxp1OCUzbxQRdjz6+tnbYmZBuH0Ov2RbEvC5tDb261LRqKXpub0llg5fqKHl01D0ahv4OAQgRs5oU+4mq+H2QGTwIFGFqP9tCRo0I+aICawpxYOfoLJpFW6KvEPnM2Lr3sl6Nq2fmkz6RL5F7nUtzxN8OKazLQpv8DOYzXbi7+ayEsqS0/EINetq7RfCqgjrEUgfNWYuFXWqvUT8lnxLdNu+8cyrJqh1UquFjXWTw1kWcJ0pkokVeBtK9YysCnF1UYh/Iv3rl2ZoYSSLNtuvMSYlYHggZ8xV8bz9S3X2/NwBycBiWIy5Ou/OuSX7trIKgkkmda0xjBWEM1a2acVuqu2OFbMn2zFxm2a3YwKP//OlIgMg',
 | |
|               'mac': 'QzKV/fgAs4U',
 | |
|             },
 | |
|           },
 | |
|         },
 | |
|       });
 | |
|       final ret = await matrixApi.postRoomKeysKeyRoomId(roomId, '5', session);
 | |
|       expect(
 | |
|           FakeMatrixApi.api['PUT'],
 | |
|           ret.toJson());
 | |
|     });
 | |
|     test('getRoomKeysRoom', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final roomId = '!726s6s6q:example.com';
 | |
|       final ret = await matrixApi.getRoomKeysRoom(roomId, '5');
 | |
|       expect(
 | |
|           FakeMatrixApi.api['GET'],
 | |
|           ret.toJson());
 | |
|     });
 | |
|     test('deleteRoomKeysRoom', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final roomId = '!726s6s6q:example.com';
 | |
|       final ret = await matrixApi.deleteRoomKeysRoom(roomId, '5');
 | |
|       expect(
 | |
|           FakeMatrixApi.api['DELETE'],
 | |
|           ret.toJson());
 | |
|     });
 | |
|     test('postRoomKeysKey', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final roomId = '!726s6s6q:example.com';
 | |
|       final sessionId = 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU';
 | |
|       final session = RoomKeys.fromJson({
 | |
|         'rooms': {
 | |
|           roomId: {
 | |
|             'sessions': {
 | |
|               sessionId: {
 | |
|                 'first_message_index': 0,
 | |
|                 'forwarded_count': 0,
 | |
|                 'is_verified': true,
 | |
|                 'session_data': {
 | |
|                   'ephemeral': 'fwRxYh+seqLykz5mQCLypJ4/59URdcFJ2s69OU1dGRc',
 | |
|                   'ciphertext':
 | |
|                       '19jkQYlbgdP+VL9DH3qY/Dvpk6onJZgf+6frZFl1TinPCm9OMK9AZZLuM1haS9XLAUK1YsREgjBqfl6T+Tq8JlJ5ONZGg2Wttt24sGYc0iTMZJ8rXcNDeKMZhM96ETyjufJSeYoXLqifiVLDw9rrVBmNStF7PskYp040em+0OZ4pF85Cwsdf7l9V7MMynzh9BoXqVUCBiwT03PNYH9AEmNUxXX+6ZwCpe/saONv8MgGt5uGXMZIK29phA3D8jD6uV/WOHsB8NjHNq9FrfSEAsl+dAcS4uiYie4BKSSeQN+zGAQqu1MMW4OAdxGOuf8WpIINx7n+7cKQfxlmc/Cgg5+MmIm2H0oDwQ+Xu7aSxp1OCUzbxQRdjz6+tnbYmZBuH0Ov2RbEvC5tDb261LRqKXpub0llg5fqKHl01D0ahv4OAQgRs5oU+4mq+H2QGTwIFGFqP9tCRo0I+aICawpxYOfoLJpFW6KvEPnM2Lr3sl6Nq2fmkz6RL5F7nUtzxN8OKazLQpv8DOYzXbi7+ayEsqS0/EINetq7RfCqgjrEUgfNWYuFXWqvUT8lnxLdNu+8cyrJqh1UquFjXWTw1kWcJ0pkokVeBtK9YysCnF1UYh/Iv3rl2ZoYSSLNtuvMSYlYHggZ8xV8bz9S3X2/NwBycBiWIy5Ou/OuSX7trIKgkkmda0xjBWEM1a2acVuqu2OFbMn2zFxm2a3YwKP//OlIgMg',
 | |
|                   'mac': 'QzKV/fgAs4U',
 | |
|                 },
 | |
|               },
 | |
|             },
 | |
|           },
 | |
|         },
 | |
|       });
 | |
|       final ret = await matrixApi.postRoomKeysKey('5', session);
 | |
|       expect(
 | |
|           FakeMatrixApi
 | |
|               .api['PUT'],
 | |
|           ret.toJson());
 | |
|     });
 | |
|     test('getRoomKeys', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final ret = await matrixApi.getRoomKeys('5');
 | |
|       expect(
 | |
|           FakeMatrixApi
 | |
|               .api['GET'],
 | |
|           ret.toJson());
 | |
|     });
 | |
|     test('deleteRoomKeys', () async {
 | |
|       matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
 | |
|       matrixApi.accessToken = '1234';
 | |
| 
 | |
|       final ret = await matrixApi.deleteRoomKeys('5');
 | |
|       expect(
 | |
|           FakeMatrixApi
 | |
|               .api['DELETE'],
 | |
|           ret.toJson());
 | |
|     });
 | |
|     test('AuthenticationData', () {
 | |
|       final json = {'session': '1234', 'type': 'm.login.dummy'};
 | |
|       expect(AuthenticationData.fromJson(json).toJson(), json);
 | |
|       expect(
 | |
|           AuthenticationData(session: '1234', type: 'm.login.dummy').toJson(),
 | |
|           json);
 | |
|     });
 | |
|     test('AuthenticationRecaptcha', () {
 | |
|       final json = {
 | |
|         'session': '1234',
 | |
|         'type': 'm.login.recaptcha',
 | |
|         'response': 'a',
 | |
|       };
 | |
|       expect(AuthenticationRecaptcha.fromJson(json).toJson(), json);
 | |
|       expect(AuthenticationRecaptcha(session: '1234', response: 'a').toJson(),
 | |
|           json);
 | |
|     });
 | |
|     test('AuthenticationToken', () {
 | |
|       final json = {
 | |
|         'session': '1234',
 | |
|         'type': 'm.login.token',
 | |
|         'token': 'a',
 | |
|         'txn_id': '1'
 | |
|       };
 | |
|       expect(AuthenticationToken.fromJson(json).toJson(), json);
 | |
|       expect(
 | |
|           AuthenticationToken(session: '1234', token: 'a', txnId: '1').toJson(),
 | |
|           json);
 | |
|     });
 | |
|     test('AuthenticationThreePidCreds', () {
 | |
|       final json = {
 | |
|         'type': 'm.login.email.identity',
 | |
|         'threepidCreds': [
 | |
|           {
 | |
|             'sid': '1',
 | |
|             'client_secret': 'a',
 | |
|             'id_server': 'matrix.org',
 | |
|             'id_access_token': 'a',
 | |
|           },
 | |
|         ],
 | |
|         'threepid_creds': [
 | |
|           {
 | |
|             'sid': '1',
 | |
|             'client_secret': 'a',
 | |
|             'id_server': 'matrix.org',
 | |
|             'id_access_token': 'a',
 | |
|           },
 | |
|         ],
 | |
|         'session': '1',
 | |
|       };
 | |
|       expect(AuthenticationThreePidCreds.fromJson(json).toJson(), json);
 | |
|       expect(
 | |
|           AuthenticationThreePidCreds(
 | |
|               session: '1',
 | |
|               type: AuthenticationTypes.emailIdentity,
 | |
|               threepidCreds: [
 | |
|                 ThreepidCreds(
 | |
|                   sid: '1',
 | |
|                   clientSecret: 'a',
 | |
|                   idServer: 'matrix.org',
 | |
|                   idAccessToken: 'a',
 | |
|                 ),
 | |
|               ]).toJson(),
 | |
|           json);
 | |
|     });
 | |
|     test('AuthenticationIdentifier', () {
 | |
|       final json = {'type': 'm.id.user'};
 | |
|       expect(AuthenticationIdentifier.fromJson(json).toJson(), json);
 | |
|       expect(AuthenticationIdentifier(type: 'm.id.user').toJson(), json);
 | |
|     });
 | |
|     test('AuthenticationPassword', () {
 | |
|       final json = {
 | |
|         'type': 'm.login.password',
 | |
|         'identifier': {'type': 'm.id.user', 'user': 'a'},
 | |
|         'password': 'a',
 | |
|         'session': '1',
 | |
|       };
 | |
|       expect(AuthenticationPassword.fromJson(json).toJson(), json);
 | |
|       expect(
 | |
|           AuthenticationPassword(
 | |
|             session: '1',
 | |
|             password: 'a',
 | |
|             identifier: AuthenticationUserIdentifier(user: 'a'),
 | |
|           ).toJson(),
 | |
|           json);
 | |
|       json['identifier'] = {
 | |
|         'type': 'm.id.thirdparty',
 | |
|         'medium': 'a',
 | |
|         'address': 'a',
 | |
|       };
 | |
|       expect(AuthenticationPassword.fromJson(json).toJson(), json);
 | |
|       expect(
 | |
|           AuthenticationPassword(
 | |
|             session: '1',
 | |
|             password: 'a',
 | |
|             identifier:
 | |
|                 AuthenticationThirdPartyIdentifier(medium: 'a', address: 'a'),
 | |
|           ).toJson(),
 | |
|           json);
 | |
|       json['identifier'] = {
 | |
|         'type': 'm.id.phone',
 | |
|         'country': 'a',
 | |
|         'phone': 'a',
 | |
|       };
 | |
|       expect(AuthenticationPassword.fromJson(json).toJson(), json);
 | |
|       expect(
 | |
|           AuthenticationPassword(
 | |
|             session: '1',
 | |
|             password: 'a',
 | |
|             identifier: AuthenticationPhoneIdentifier(country: 'a', phone: 'a'),
 | |
|           ).toJson(),
 | |
|           json);
 | |
|     });
 | |
|   });
 | |
| }
 |