Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a0155a7
tests for services
lohanidamodar Jun 19, 2023
28e6676
working location type methods tests
lohanidamodar Jun 19, 2023
fc6efa8
got some more tests working
lohanidamodar Jun 19, 2023
9a5ec5e
fix some white space issues
lohanidamodar Jun 19, 2023
40700c7
account tests working
lohanidamodar Jun 19, 2023
b8a91f1
Add inline doc comments to the Dart and Flutter SDKs
stnguyen90 Jun 16, 2023
10c0079
fix storage test
lohanidamodar Jun 20, 2023
fbeead0
fix and dependencies
lohanidamodar Jun 20, 2023
ad4afc0
Add tests for helpers and moels to Flutter and Dart SDKs
stnguyen90 Jun 20, 2023
594f60d
Update templates/flutter/test/services/service_test.dart.twig
lohanidamodar Jun 20, 2023
4a7f5ff
Merge pull request #676 from appwrite/feat-flutter-dart-helpers-model…
lohanidamodar Jun 21, 2023
9d37d1e
fix exception and add exception test
lohanidamodar Jun 21, 2023
0c9327a
format test folder as well
lohanidamodar Jun 21, 2023
95c263d
interceptor test
lohanidamodar Jun 21, 2023
c51727d
realtime response connected test
lohanidamodar Jun 21, 2023
28b725d
realtime response test
lohanidamodar Jun 21, 2023
31610b9
realtime subscription test
lohanidamodar Jun 21, 2023
b6ca936
Move flutter service tests to dart
stnguyen90 Jun 21, 2023
3801bf9
update doc
lohanidamodar Jun 21, 2023
63b6808
Merge pull request #671 from appwrite/feat-flutter-dart-docs
lohanidamodar Jun 21, 2023
3e90e77
Merge branch 'feat-flutter-service-test' into feat-flutter-dart-helpe…
stnguyen90 Jun 21, 2023
b72943f
Merge pull request #677 from appwrite/feat-flutter-dart-helpers-model…
lohanidamodar Jun 21, 2023
2938bee
fix typo
lohanidamodar Jun 21, 2023
500e29a
upload progress test
lohanidamodar Jun 21, 2023
44821ba
Update templates/dart/test/src/exception_test.dart.twig
lohanidamodar Jun 21, 2023
0abd81d
Merge branch 'feat-flutter-service-test' of https://github.com/appwri…
lohanidamodar Jun 21, 2023
bb0826c
fix
lohanidamodar Jun 21, 2023
790c6fd
input file test
lohanidamodar Jun 21, 2023
b73f6f7
remove extra space
lohanidamodar Jun 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/SDK/Language/Flutter.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ public function getFiles(): array
'destination' => '/lib/services/{{service.name | caseDash}}.dart',
'template' => 'flutter/lib/services/service.dart.twig',
],
[
'scope' => 'service',
'destination' => '/test/services/{{service.name | caseDash}}_test.dart',
'template' => 'flutter/test/services/service_test.dart.twig',
],
[
'scope' => 'method',
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
Expand Down
1 change: 1 addition & 0 deletions src/Spec/Swagger2.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ public function getDefinitions()
foreach ($sch['properties'] as $name => $def) {
$sch['properties'][$name]['name'] = $name;
$sch['properties'][$name]['description'] = $def['description'];
$sch['properties'][$name]['example'] = $def['x-example'];
$sch['properties'][$name]['required'] = in_array($name, $sch['required']);
if (isset($def['items']['$ref'])) {
//nested model
Expand Down
1 change: 1 addition & 0 deletions templates/flutter/pubspec.yaml.twig
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ dev_dependencies:
flutter_lints: ^2.0.1
flutter_test:
sdk: flutter
mockito: ^5.4.2
107 changes: 107 additions & 0 deletions templates/flutter/test/services/service_test.dart.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{% import 'flutter/base/utils.twig' as utils %}
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:{{ language.params.packageName }}/models.dart' as models;
import 'package:{{ language.params.packageName }}/src/enums.dart';
import 'package:{{ language.params.packageName }}/src/response.dart';
import 'dart:typed_data';
import 'package:{{ language.params.packageName }}/{{ language.params.packageName }}.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 webAuth(
Uri? url,
{
String? callbackUrlScheme,
}
) 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('{{service.name | caseUcfirst}} test', () {
late MockClient client;
late {{service.name | caseUcfirst}} {{service.name | caseCamel}};

setUp(() {
client = MockClient();
{{service.name | caseCamel}} = {{service.name | caseUcfirst}}(client);
});

{% for method in service.methods %}
test('test method {{method.name | caseCamel}}()', () async {
{%- if method.type == 'webAuth' -%}
{%~ elseif method.type == 'location' -%}
final Uint8List data = Uint8List.fromList([]);
{%- else -%}

{%~ if method.responseModel and method.responseModel != 'any' ~%}
final Map<String, dynamic> data = {
{%- for definition in spec.definitions ~%}{%~ if definition.name == method.responseModel -%}{%~ for property in definition.properties | filter((param) => param.required) ~%}
'{{property.name | escapeKeyword | escapeDollarSign}}': {% if property.type == 'object' %}<String, dynamic>{}{% elseif property.type == 'array' %}[]{% elseif property.type == 'string' %}'{{property.example}}'{% elseif property.type == 'boolean' %}true{% else %}{{property.example}}{% endif %},{%~ endfor ~%}{% set break = true %}{%- else -%}{% set continue = true %}{%- endif -%}{%~ endfor -%}

};
{%~ else ~%}
final data = '';
{%- endif -%}
{% endif %}

{%~ if method.type == 'webAuth' ~%}
when(client.webAuth(
Uri(),
)).thenAnswer((_) async => 'done');
{%~ elseif 'multipart/form-data' in method.consumes ~%}
when(client.chunkedUpload(
path: argThat(isNotNull),
params: argThat(isNotNull),
paramName: argThat(isNotNull),
idParamName: argThat(isNotNull),
headers: argThat(isNotNull),
)).thenAnswer((_) async => Response(data: data));
{%~ else ~%}
when(client.call(
HttpMethod.{{method.method | caseLower}},
)).thenAnswer((_) async => Response(data: data));
{%~ endif ~%}

final response = await {{service.name | caseCamel}}.{{method.name | caseCamel}}({%~ for parameter in method.parameters.all | filter((param) => param.required) ~%}
{{parameter.name | escapeKeyword | caseCamel}}: {% if parameter.type == 'object' %}{}{% elseif parameter.type == 'file' %}InputFile.fromPath(path: './image.png'){% else %}'{{parameter.example}}'{%~ endif ~%},{%~ endfor ~%}
);

{%- if method.type == 'location' ~%}
expect(response, isA<Uint8List>());
{%~ endif ~%}{%~ if method.responseModel and method.responseModel != 'any' ~%}
expect(response, isA<models.{{method.responseModel | caseUcfirst | overrideIdentifier}}>());
{%~ endif ~%}
});

{% endfor %}
});
}