Skip to content
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

WIP: fix storage tests #675

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep getting this error:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh...it's because im matching it wrong in the when()...

}
}

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