1
+ {% import ' flutter/base/utils.twig' as utils %}
2
+ import 'package:flutter_test/flutter_test.dart';
3
+ import 'package:mockito/mockito.dart';
4
+ import 'package:appwrite/models.dart' as models;
5
+ import 'package:appwrite/src/enums.dart';
6
+ import 'package:appwrite/src/response.dart';
7
+ import 'dart:typed_data';
8
+
9
+ class MockClient extends Mock implements Client {
10
+ @override
11
+ Future<Response > call(
12
+ HttpMethod? method, {
13
+ String path = '',
14
+ Map<String , String > headers = const {},
15
+ Map<String , dynamic > params = const {},
16
+ ResponseType? responseType,
17
+ }) async {
18
+ super.noSuchMethod(Invocation.method(#call, [method]));
19
+ return super.noSuchMethod(Invocation.method(#call, [method]),
20
+ returnValue: Response());
21
+ }
22
+ }
23
+
24
+ void main() {
25
+ group('{{service .name | caseUcfirst }} test', () {
26
+ late Client client;
27
+ late {{service .name | caseUcfirst }} {{service .name | caseCamel }};
28
+
29
+ setUp(() {
30
+ client = MockClient();
31
+ {{service .name | caseCamel }} = {{service .name | caseUcfirst }}(client);
32
+ });
33
+
34
+ {% for method in service .methods %}
35
+ test('test method {{method .name | caseCamel }}()', () async {
36
+ {% if method .type == ' webAuth' %}
37
+
38
+ {%~ elseif method .type == ' location' ~%}
39
+ final Uint8List data = [];
40
+ {% else %}
41
+ final Map<String , dynamic > data = {
42
+ {# need response model #}
43
+ };
44
+ {% endif %}
45
+
46
+ when(client.call(
47
+ HttpMethod.{{method .method | caseLower }},
48
+ ).then(_) async => Response(data: data));
49
+
50
+ final response = await {{service .name | caseCamel }}.{{method .name | caseCamel }}(
51
+ {% for parameter in method .parameters .all %}
52
+ {% if parameter .required %}
53
+ '{{parameter .name | caseCamel }}':'{{parameter .example }}',
54
+ {% endif %}
55
+ {% endfor %}
56
+ );
57
+ });
58
+
59
+ {% endfor %}
60
+
61
+
62
+ });
63
+ }
0 commit comments