Skip to content

Commit

Permalink
Merge pull request #1781 from famedly/td/exposefakeapi
Browse files Browse the repository at this point in the history
chore: expose fake matrix api
  • Loading branch information
td-famedly authored Apr 30, 2024
2 parents 5cf1e65 + a2e8830 commit 20d6850
Show file tree
Hide file tree
Showing 20 changed files with 20 additions and 33 deletions.
32 changes: 17 additions & 15 deletions test/fake_matrix_api.dart → lib/fake_matrix_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,28 @@ class FakeMatrixApi extends BaseClient {
}

@override
Future<StreamedResponse> send(BaseRequest baseRequest) async {
final bodyStream = baseRequest.finalize();
Future<StreamedResponse> send(BaseRequest request) async {
final bodyStream = request.finalize();
final bodyBytes = await bodyStream.toBytes();
final request = Request(baseRequest.method, baseRequest.url)
..persistentConnection = baseRequest.persistentConnection
..followRedirects = baseRequest.followRedirects
..maxRedirects = baseRequest.maxRedirects
..headers.addAll(baseRequest.headers)
final r = Request(request.method, request.url)
..persistentConnection = request.persistentConnection
..followRedirects = request.followRedirects
..maxRedirects = request.maxRedirects
..headers.addAll(request.headers)
..bodyBytes = bodyBytes
..finalize();

final response = await mockIntercept(request);
final response = await mockIntercept(r);
return StreamedResponse(
ByteStream.fromBytes(response.bodyBytes), response.statusCode,
contentLength: response.contentLength,
request: baseRequest,
headers: response.headers,
isRedirect: response.isRedirect,
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase);
ByteStream.fromBytes(response.bodyBytes),
response.statusCode,
contentLength: response.contentLength,
request: request,
headers: response.headers,
isRedirect: response.isRedirect,
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase,
);
}

FakeMatrixApi() {
Expand Down
2 changes: 2 additions & 0 deletions lib/matrix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ library matrix;

export 'matrix_api_lite.dart';

export 'fake_matrix_api.dart' show FakeMatrixApi;

export 'src/client.dart';
export 'src/database/database_api.dart';
export 'src/database/hive_database.dart';
Expand Down
1 change: 0 additions & 1 deletion test/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import 'package:matrix/matrix.dart';
import 'package:matrix/src/utils/client_init_exception.dart';
import 'fake_client.dart';
import 'fake_database.dart';
import 'fake_matrix_api.dart';

void main() {
late Client matrix;
Expand Down
1 change: 0 additions & 1 deletion test/commands_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'package:test/test.dart';

import 'package:matrix/matrix.dart';
import 'fake_client.dart';
import 'fake_matrix_api.dart';

void main() {
group('Commands', tags: 'olm', () {
Expand Down
1 change: 0 additions & 1 deletion test/device_keys_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import 'package:test/test.dart';

import 'package:matrix/matrix.dart';
import './fake_client.dart';
import './fake_matrix_api.dart';

void main() {
/// All Tests related to device keys
Expand Down
1 change: 0 additions & 1 deletion test/encryption/cross_signing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'package:test/test.dart';

import 'package:matrix/matrix.dart';
import '../fake_client.dart';
import '../fake_matrix_api.dart';

void main() {
group('Cross Signing', tags: 'olm', () {
Expand Down
1 change: 0 additions & 1 deletion test/encryption/encrypt_decrypt_to_device_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import 'package:test/test.dart';
import 'package:matrix/matrix.dart';
import '../fake_client.dart';
import '../fake_database.dart';
import '../fake_matrix_api.dart';

void main() {
// key @othertest:fakeServer.notExisting
Expand Down
1 change: 0 additions & 1 deletion test/encryption/key_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'package:test/test.dart';

import 'package:matrix/matrix.dart';
import '../fake_client.dart';
import '../fake_matrix_api.dart';

void main() {
group('Key Manager', tags: 'olm', () {
Expand Down
1 change: 0 additions & 1 deletion test/encryption/key_request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'package:test/test.dart';

import 'package:matrix/matrix.dart';
import '../fake_client.dart';
import '../fake_matrix_api.dart';

Map<String, dynamic> jsonDecode(dynamic payload) {
if (payload is String) {
Expand Down
1 change: 0 additions & 1 deletion test/encryption/key_verification_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import 'package:matrix/encryption.dart';
import 'package:matrix/matrix.dart';
import '../fake_client.dart';
import '../fake_database.dart';
import '../fake_matrix_api.dart';

EventUpdate getLastSentEvent(KeyVerification req) {
final entry = FakeMatrixApi.calledEndpoints.entries
Expand Down
1 change: 0 additions & 1 deletion test/encryption/olm_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import 'package:test/test.dart';
import 'package:matrix/encryption/utils/json_signature_check_extension.dart';
import 'package:matrix/matrix.dart';
import '../fake_client.dart';
import '../fake_matrix_api.dart';

void main() {
group('Olm Manager', tags: 'olm', () {
Expand Down
1 change: 0 additions & 1 deletion test/encryption/online_key_backup_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'package:test/test.dart';

import 'package:matrix/matrix.dart';
import '../fake_client.dart';
import '../fake_matrix_api.dart';

void main() {
group('Online Key Backup', tags: 'olm', () {
Expand Down
1 change: 0 additions & 1 deletion test/encryption/ssss_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import 'package:test/test.dart';
import 'package:matrix/encryption.dart';
import 'package:matrix/matrix.dart';
import '../fake_client.dart';
import '../fake_matrix_api.dart';

Uint8List secureRandomBytes(int len) {
final rng = Random.secure();
Expand Down
1 change: 0 additions & 1 deletion test/event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import 'package:matrix/encryption.dart';
import 'package:matrix/matrix.dart';
import 'package:matrix/src/models/timeline_chunk.dart';
import 'fake_client.dart';
import 'fake_matrix_api.dart';

void main() {
/// All Tests related to the Event
Expand Down
1 change: 0 additions & 1 deletion test/fake_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import 'package:matrix/matrix.dart';
import 'fake_database.dart';
import 'fake_matrix_api.dart';

const ssssPassphrase = 'nae7ahDiequ7ohniufah3ieS2je1thohX4xeeka7aixohsho9O';
const ssssKey = 'EsT9 RzbW VhPW yqNp cC7j ViiW 5TZB LuY4 ryyv 9guN Ysmr WDPH';
Expand Down
2 changes: 1 addition & 1 deletion test/msc_extensions/msc_3814_dehydrated_devices_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

import 'package:test/test.dart';

import 'package:matrix/fake_matrix_api.dart';
import 'package:matrix/msc_extensions/msc_3814_dehydrated_devices/api.dart';
import '../fake_client.dart';
import '../fake_matrix_api.dart';

void main() {
/// All Tests related to device keys
Expand Down
1 change: 0 additions & 1 deletion test/mxc_uri_extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import 'package:test/test.dart';

import 'package:matrix/matrix.dart';
import 'fake_matrix_api.dart';

void main() {
/// All Tests related to the MxContent
Expand Down
1 change: 0 additions & 1 deletion test/room_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import 'package:test/test.dart';

import 'package:matrix/matrix.dart';
import 'fake_client.dart';
import 'fake_matrix_api.dart';

Future<void> updateLastEvent(Event event) {
if (event.room.client.getRoomById(event.room.id) == null) {
Expand Down
1 change: 0 additions & 1 deletion test/timeline_context_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'package:test/test.dart';
import 'package:matrix/matrix.dart';
import 'package:matrix/src/models/timeline_chunk.dart';
import 'fake_client.dart';
import 'fake_matrix_api.dart';

void main() {
group('Timeline context', tags: 'olm', () {
Expand Down
1 change: 0 additions & 1 deletion test/user_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import 'package:test/test.dart';

import 'package:matrix/matrix.dart';
import 'fake_matrix_api.dart';

void main() {
/// All Tests related to the Event
Expand Down

0 comments on commit 20d6850

Please sign in to comment.