Skip to content

Commit

Permalink
account tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar committed Jun 19, 2023
1 parent 9a5ec5e commit 40700c7
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions templates/flutter/test/services/service_test.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:appwrite/appwrite.dart';

class MockClient extends Mock implements Client {
Map<String, String> config = {'project': 'testproject'};

String endPoint = 'https://localhost/v1';
@override
Future<Response> call(
HttpMethod? method, {
Expand All @@ -18,10 +18,19 @@ class MockClient extends Mock implements Client {
Map<String, dynamic> params = const {},
ResponseType? responseType,
}) async {
super.noSuchMethod(Invocation.method(#call, [method]));
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');
}
}

void main() {
Expand All @@ -44,17 +53,23 @@ void main() {
{%~ 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' %}{}{% elseif property.type == 'array' %}[]{% elseif property.type == 'string' %}'{{property.example}}'{% else %}{{property.example}}{% endif %},{%~ endfor ~%}{% set break = true %}{%- else -%}{% set continue = true %}{%- endif -%}{%~ endfor -%}
'{{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 = null;
final data = '';
{%- endif -%}
{% endif %}

{%~ if method.type == 'webAuth' ~%}
when(client.webAuth(
Uri(),
)).thenAnswer((_) async => 'done');
{%~ 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 ~%}
Expand Down

0 comments on commit 40700c7

Please sign in to comment.