Skip to content

Commit

Permalink
WIP: fix storage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stnguyen90 committed Jun 20, 2023
1 parent 40700c7 commit 05a5fea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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
23 changes: 22 additions & 1 deletion templates/flutter/test/services/service_test.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -31,6 +32,18 @@ class MockClient extends Mock implements Client {
) async {
return super.noSuchMethod(Invocation.method(#webAuth, [url]), returnValue: 'done');
}

@override
Future<Response> chunkedUpload({
required String path,
required Map<String, dynamic> params,
required String paramName,
required String idParamName,
required Map<String, String> headers,
Function(UploadProgress)? onProgress,
}) async {
return super.noSuchMethod(Invocation.method(#chunkedUpload, [path, params, paramName, idParamName, headers]), returnValue: Response());
}
}

void main() {
Expand Down Expand Up @@ -65,14 +78,22 @@ 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}},
)).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 | 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' ~%}
Expand Down

0 comments on commit 05a5fea

Please sign in to comment.