Skip to content

Commit a0155a7

Browse files
committed
tests for services
1 parent ed12c55 commit a0155a7

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

src/SDK/Language/Flutter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ public function getFiles(): array
240240
'destination' => '/lib/services/{{service.name | caseDash}}.dart',
241241
'template' => 'flutter/lib/services/service.dart.twig',
242242
],
243+
[
244+
'scope' => 'service',
245+
'destination' => '/test/services/{{service.name | caseDash}}_test.dart',
246+
'template' => 'flutter/test/services/service_test.dart.twig',
247+
],
243248
[
244249
'scope' => 'method',
245250
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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

Comments
 (0)