-
Notifications
You must be signed in to change notification settings - Fork 188
Flutter SDK: tests for services #673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
a0155a7
tests for services
lohanidamodar 28e6676
working location type methods tests
lohanidamodar fc6efa8
got some more tests working
lohanidamodar 9a5ec5e
fix some white space issues
lohanidamodar 40700c7
account tests working
lohanidamodar b8a91f1
Add inline doc comments to the Dart and Flutter SDKs
stnguyen90 10c0079
fix storage test
lohanidamodar fbeead0
fix and dependencies
lohanidamodar ad4afc0
Add tests for helpers and moels to Flutter and Dart SDKs
stnguyen90 594f60d
Update templates/flutter/test/services/service_test.dart.twig
lohanidamodar 4a7f5ff
Merge pull request #676 from appwrite/feat-flutter-dart-helpers-model…
lohanidamodar 9d37d1e
fix exception and add exception test
lohanidamodar 0c9327a
format test folder as well
lohanidamodar 95c263d
interceptor test
lohanidamodar c51727d
realtime response connected test
lohanidamodar 28b725d
realtime response test
lohanidamodar 31610b9
realtime subscription test
lohanidamodar b6ca936
Move flutter service tests to dart
stnguyen90 3801bf9
update doc
lohanidamodar 63b6808
Merge pull request #671 from appwrite/feat-flutter-dart-docs
lohanidamodar 3e90e77
Merge branch 'feat-flutter-service-test' into feat-flutter-dart-helpe…
stnguyen90 b72943f
Merge pull request #677 from appwrite/feat-flutter-dart-helpers-model…
lohanidamodar 2938bee
fix typo
lohanidamodar 500e29a
upload progress test
lohanidamodar 44821ba
Update templates/dart/test/src/exception_test.dart.twig
lohanidamodar 0abd81d
Merge branch 'feat-flutter-service-test' of https://github.com/appwri…
lohanidamodar bb0826c
fix
lohanidamodar 790c6fd
input file test
lohanidamodar b73f6f7
remove extra space
lohanidamodar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ dev_dependencies: | |
flutter_lints: ^2.0.1 | ||
flutter_test: | ||
sdk: flutter | ||
mockito: ^5.4.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.