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

Move flutter service tests to dart #677

Merged
Merged
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
10 changes: 10 additions & 0 deletions src/SDK/Language/Dart.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ public function getFiles(): array
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
'template' => 'dart/docs/example.md.twig',
],
[
'scope' => 'service',
'destination' => '/test/services/{{service.name | caseDash}}_test.dart',
'template' => 'dart/test/services/service_test.dart.twig',
],
[
'scope' => 'definition',
'destination' => '/test/src/models/{{definition.name | caseSnake }}_test.dart',
'template' => 'dart/test/src/models/model_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/id_test.dart',
Expand Down
2 changes: 1 addition & 1 deletion src/SDK/Language/Flutter.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function getFiles(): array
[
'scope' => 'service',
'destination' => '/test/services/{{service.name | caseDash}}_test.dart',
'template' => 'flutter/test/services/service_test.dart.twig',
'template' => 'dart/test/services/service_test.dart.twig',
],
[
'scope' => 'definition',
Expand Down
1 change: 1 addition & 0 deletions templates/dart/pubspec.yaml.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ dependencies:
dev_dependencies:
lints: ^2.0.1
test: ^1.22.0
mockito: ^5.4.2
4 changes: 4 additions & 0 deletions templates/dart/test/id_test.dart.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'package:{{ language.params.packageName }}/{{ language.params.packageName }}.dart';
{% if 'dart' in language.params.packageName %}
import 'package:test/test.dart';
{% else %}
import 'package:flutter_test/flutter_test.dart';
{% endif %}

void main() {
group('unique()', () {
Expand Down
4 changes: 4 additions & 0 deletions templates/dart/test/permission_test.dart.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'package:{{ language.params.packageName }}/{{ language.params.packageName }}.dart';
{% if 'dart' in language.params.packageName %}
import 'package:test/test.dart';
{% else %}
import 'package:flutter_test/flutter_test.dart';
{% endif %}

void main() {
group('read()', () {
Expand Down
4 changes: 4 additions & 0 deletions templates/dart/test/query_test.dart.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'package:{{ language.params.packageName }}/{{ language.params.packageName }}.dart';
{% if 'dart' in language.params.packageName %}
import 'package:test/test.dart';
{% else %}
import 'package:flutter_test/flutter_test.dart';
{% endif %}

class BasicFilterQueryTest {
final String description;
Expand Down
4 changes: 4 additions & 0 deletions templates/dart/test/role_test.dart.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'package:{{ language.params.packageName }}/{{ language.params.packageName }}.dart';
{% if 'dart' in language.params.packageName %}
import 'package:test/test.dart';
{% else %}
import 'package:flutter_test/flutter_test.dart';
{% endif %}

void main() {
group('any()', () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{% import 'flutter/base/utils.twig' as utils %}
{% if 'dart' in language.params.packageName %}
import 'package:test/test.dart';
{% else %}
import 'package:flutter_test/flutter_test.dart';
{% endif %}
import 'package:mockito/mockito.dart';
import 'package:{{ language.params.packageName }}/models.dart' as models;
import 'package:{{ language.params.packageName }}/src/enums.dart';
Expand Down Expand Up @@ -65,7 +69,7 @@ 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' %}<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 -%}
'{{property.name | escapeDollarSign}}': {% if property.type == 'object' %}<String, dynamic>{}{% elseif property.type == 'array' %}[]{% elseif property.type == 'string' %}'{{property.example | escapeDollarSign}}'{% elseif property.type == 'boolean' %}true{% else %}{{property.example}}{% endif %},{%~ endfor ~%}{% set break = true %}{%- else -%}{% set continue = true %}{%- endif -%}{%~ endfor -%}

};
{%~ else ~%}
Expand All @@ -92,7 +96,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 | escapeKeyword | caseCamel}}: {% if parameter.type == 'object' %}{}{% elseif parameter.type == 'array' %}[]{% elseif parameter.type == 'file' %}InputFile.fromPath(path: './image.png'){% else %}'{{parameter.example}}'{%~ endif ~%},{%~ endfor ~%}
{{parameter.name | escapeKeyword | caseCamel}}: {% if parameter.type == 'object' %}{}{% elseif parameter.type == 'array' %}[]{% elseif parameter.type == 'file' %}InputFile.fromPath(path: './image.png'){% elseif parameter.type == 'boolean' %}true{% elseif parameter.type == 'string' %}'{% if parameter.example is not empty %}{{parameter.example | escapeDollarSign}}{% endif %}'{% elseif parameter.type == 'integer' and parameter['x-example'] is empty %}1{% elseif parameter.type == 'number' and parameter['x-example'] is empty %}1.0{% else %}{{parameter.example}}{%~ endif ~%},{%~ endfor ~%}
);

{%- if method.type == 'location' ~%}
Expand Down
4 changes: 4 additions & 0 deletions templates/dart/test/src/enums_test.dart.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'package:{{ language.params.packageName }}/src/enums.dart';
{% if 'dart' in language.params.packageName %}
import 'package:test/test.dart';
{% else %}
import 'package:flutter_test/flutter_test.dart';
{% endif %}

void main() {
group('name()', () {
Expand Down
4 changes: 4 additions & 0 deletions templates/dart/test/src/models/model_test.dart.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% macro sub_schema(property) %}{% if property.sub_schema %}{% if property.type == 'array' %}List<{{property.sub_schema | caseUcfirst | overrideIdentifier}}>{% else %}{{property.sub_schema | caseUcfirst | overrideIdentifier }}{% endif %}{% else %}{% if property.type == 'object' and property.additionalProperties %}Map<String, dynamic>{% else %}{{property | typeName}}{% endif %}{% endif %}{% endmacro %}
import 'package:{{ language.params.packageName }}/models.dart';
{% if 'dart' in language.params.packageName %}
import 'package:test/test.dart';
{% else %}
import 'package:flutter_test/flutter_test.dart';
{% endif %}

void main() {
group('{{ definition.name | caseUcfirst | overrideIdentifier }}', () {
Expand Down
4 changes: 4 additions & 0 deletions templates/dart/test/src/response_test.dart.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'package:{{ language.params.packageName }}/src/response.dart';
{% if 'dart' in language.params.packageName %}
import 'package:test/test.dart';
{% else %}
import 'package:flutter_test/flutter_test.dart';
{% endif %}

void main() {
group('toString()', () {
Expand Down