mirror of
https://github.com/appwrite/sdk-for-dart.git
synced 2026-06-06 19:27:59 +00:00
86 lines
2.3 KiB
Dart
86 lines
2.3 KiB
Dart
import 'package:test/test.dart';
|
|
import 'package:mockito/mockito.dart';
|
|
import 'package:dart_appwrite/models.dart' as models;
|
|
import 'package:dart_appwrite/enums.dart' as enums;
|
|
import 'package:dart_appwrite/src/enums.dart';
|
|
import 'package:dart_appwrite/src/response.dart';
|
|
import 'dart:typed_data';
|
|
import 'package:dart_appwrite/dart_appwrite.dart';
|
|
|
|
class MockClient extends Mock implements Client {
|
|
Map<String, String> config = {'project': 'testproject'};
|
|
String endPoint = 'https://localhost/v1';
|
|
@override
|
|
Future<Response> call(
|
|
HttpMethod? method, {
|
|
String path = '',
|
|
Map<String, String> headers = const {},
|
|
Map<String, dynamic> params = const {},
|
|
ResponseType? responseType,
|
|
}) async {
|
|
return super.noSuchMethod(Invocation.method(#call, [method]),
|
|
returnValue: Response());
|
|
}
|
|
|
|
@override
|
|
Future<String?> webAuth(Uri url) async {
|
|
return super
|
|
.noSuchMethod(Invocation.method(#webAuth, [url]), returnValue: 'done');
|
|
}
|
|
|
|
@override
|
|
Future<Response> chunkedUpload({
|
|
String? path,
|
|
Map<String, dynamic>? params,
|
|
String? paramName,
|
|
String? idParamName,
|
|
Map<String, String>? headers,
|
|
Function(UploadProgress)? onProgress,
|
|
}) async {
|
|
return super.noSuchMethod(
|
|
Invocation.method(
|
|
#chunkedUpload, [path, params, paramName, idParamName, headers]),
|
|
returnValue: Response(data: {}));
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
group('Usage test', () {
|
|
late MockClient client;
|
|
late Usage usage;
|
|
|
|
setUp(() {
|
|
client = MockClient();
|
|
usage = Usage(client);
|
|
});
|
|
|
|
test('test method listEvents()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'total': 5,
|
|
'events': [],
|
|
};
|
|
|
|
when(client.call(
|
|
HttpMethod.get,
|
|
)).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await usage.listEvents();
|
|
expect(response, isA<models.UsageEventList>());
|
|
});
|
|
|
|
test('test method listGauges()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'total': 5,
|
|
'gauges': [],
|
|
};
|
|
|
|
when(client.call(
|
|
HttpMethod.get,
|
|
)).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await usage.listGauges();
|
|
expect(response, isA<models.UsageGaugeList>());
|
|
});
|
|
});
|
|
}
|