diff --git a/templates/flutter/pubspec.yaml.twig b/templates/flutter/pubspec.yaml.twig index 0bcb43298..d8a836150 100644 --- a/templates/flutter/pubspec.yaml.twig +++ b/templates/flutter/pubspec.yaml.twig @@ -32,3 +32,4 @@ dev_dependencies: flutter_lints: ^2.0.1 flutter_test: sdk: flutter + mockito: ^5.4.2 \ No newline at end of file diff --git a/templates/flutter/test/services/service_test.dart.twig b/templates/flutter/test/services/service_test.dart.twig index 764ef8ca9..c44e0cb14 100644 --- a/templates/flutter/test/services/service_test.dart.twig +++ b/templates/flutter/test/services/service_test.dart.twig @@ -5,6 +5,7 @@ import 'package:appwrite/models.dart' as models; import 'package:appwrite/src/enums.dart'; import 'package:appwrite/src/response.dart'; import 'dart:typed_data'; +import 'dart:convert'; import 'package:appwrite/appwrite.dart'; class MockClient extends Mock implements Client { @@ -31,6 +32,18 @@ class MockClient extends Mock implements Client { ) async { return super.noSuchMethod(Invocation.method(#webAuth, [url]), returnValue: 'done'); } + + @override + Future chunkedUpload({ + required String path, + required Map params, + required String paramName, + required String idParamName, + required Map headers, + Function(UploadProgress)? onProgress, + }) async { + return super.noSuchMethod(Invocation.method(#chunkedUpload, [path, params, paramName, idParamName, headers]), returnValue: Response()); + } } void main() { @@ -65,6 +78,14 @@ void main() { when(client.webAuth( Uri(), )).thenAnswer((_) async => 'done'); + {%~ elseif method.type == 'upload' ~%} + when(client.chunkedUpload( + path: '', + params: data, + paramName: 'file', + idParamName: 'fileId', + headers: {}, + )).thenAnswer((_) async => Response(data: data)); {%~ else ~%} when(client.call( HttpMethod.{{method.method | caseLower}}, @@ -72,7 +93,7 @@ void main() { {%~ endif ~%} final response = await {{service.name | caseCamel}}.{{method.name | caseCamel}}({%~ for parameter in method.parameters.all | filter((param) => param.required) ~%} - {{parameter.name | caseCamel}}: {% if parameter.type == 'object' %}{}{% else %}'{{parameter.example}}'{%~ endif ~%},{%~ endfor ~%} + {{parameter.name | caseCamel}}: {% if parameter.type == 'object' %}{}{% elseif parameter.type == 'array' %}[]{% elseif parameter.type == 'file' %}InputFile.fromBytes(bytes: utf8.encode('bytes'), filename: 'file.txt'){% else %}'{{parameter.example}}'{%~ endif ~%},{%~ endfor ~%} ); {%- if method.type == 'location' ~%}