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

Flutter SDK: tests for services #673

Merged
merged 29 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a0155a7
tests for services
lohanidamodar Jun 19, 2023
28e6676
working location type methods tests
lohanidamodar Jun 19, 2023
fc6efa8
got some more tests working
lohanidamodar Jun 19, 2023
9a5ec5e
fix some white space issues
lohanidamodar Jun 19, 2023
40700c7
account tests working
lohanidamodar Jun 19, 2023
b8a91f1
Add inline doc comments to the Dart and Flutter SDKs
stnguyen90 Jun 16, 2023
10c0079
fix storage test
lohanidamodar Jun 20, 2023
fbeead0
fix and dependencies
lohanidamodar Jun 20, 2023
ad4afc0
Add tests for helpers and moels to Flutter and Dart SDKs
stnguyen90 Jun 20, 2023
594f60d
Update templates/flutter/test/services/service_test.dart.twig
lohanidamodar Jun 20, 2023
4a7f5ff
Merge pull request #676 from appwrite/feat-flutter-dart-helpers-model…
lohanidamodar Jun 21, 2023
9d37d1e
fix exception and add exception test
lohanidamodar Jun 21, 2023
0c9327a
format test folder as well
lohanidamodar Jun 21, 2023
95c263d
interceptor test
lohanidamodar Jun 21, 2023
c51727d
realtime response connected test
lohanidamodar Jun 21, 2023
28b725d
realtime response test
lohanidamodar Jun 21, 2023
31610b9
realtime subscription test
lohanidamodar Jun 21, 2023
b6ca936
Move flutter service tests to dart
stnguyen90 Jun 21, 2023
3801bf9
update doc
lohanidamodar Jun 21, 2023
63b6808
Merge pull request #671 from appwrite/feat-flutter-dart-docs
lohanidamodar Jun 21, 2023
3e90e77
Merge branch 'feat-flutter-service-test' into feat-flutter-dart-helpe…
stnguyen90 Jun 21, 2023
b72943f
Merge pull request #677 from appwrite/feat-flutter-dart-helpers-model…
lohanidamodar Jun 21, 2023
2938bee
fix typo
lohanidamodar Jun 21, 2023
500e29a
upload progress test
lohanidamodar Jun 21, 2023
44821ba
Update templates/dart/test/src/exception_test.dart.twig
lohanidamodar Jun 21, 2023
0abd81d
Merge branch 'feat-flutter-service-test' of https://github.com/appwri…
lohanidamodar Jun 21, 2023
bb0826c
fix
lohanidamodar Jun 21, 2023
790c6fd
input file test
lohanidamodar Jun 21, 2023
b73f6f7
remove extra space
lohanidamodar Jun 21, 2023
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
55 changes: 55 additions & 0 deletions src/SDK/Language/Dart.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,61 @@ 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',
'template' => 'dart/test/id_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/permission_test.dart',
'template' => 'dart/test/permission_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/query_test.dart',
'template' => 'dart/test/query_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/role_test.dart',
'template' => 'dart/test/role_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/enums_test.dart',
'template' => 'dart/test/src/enums_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/upload_progress_test.dart',
'template' => 'dart/test/src/upload_progress_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/exception_test.dart',
'template' => 'dart/test/src/exception_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/input_file_test.dart',
'template' => 'dart/test/src/input_file_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/response_test.dart',
'template' => 'dart/test/src/response_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '.travis.yml',
Expand Down
80 changes: 80 additions & 0 deletions src/SDK/Language/Flutter.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,86 @@ public function getFiles(): array
'destination' => '/lib/services/{{service.name | caseDash}}.dart',
'template' => 'flutter/lib/services/service.dart.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',
'template' => 'dart/test/id_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/permission_test.dart',
'template' => 'dart/test/permission_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/query_test.dart',
'template' => 'dart/test/query_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/role_test.dart',
'template' => 'dart/test/role_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/cookie_manager_test.dart',
'template' => 'flutter/test/src/cookie_manager_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/interceptor_test.dart',
'template' => 'flutter/test/src/interceptor_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/realtime_response_test.dart',
'template' => 'flutter/test/src/realtime_response_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/realtime_response_connected_test.dart',
'template' => 'flutter/test/src/realtime_response_connected_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/realtime_subscription_test.dart',
'template' => 'flutter/test/src/realtime_subscription_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/enums_test.dart',
'template' => 'dart/test/src/enums_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/upload_progress_test.dart',
'template' => 'dart/test/src/upload_progress_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/input_file_test.dart',
'template' => 'dart/test/src/input_file_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/exception_test.dart',
'template' => 'dart/test/src/exception_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/response_test.dart',
'template' => 'dart/test/src/response_test.dart.twig',
],
[
'scope' => 'method',
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
Expand Down
1 change: 1 addition & 0 deletions src/Spec/Swagger2.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ public function getDefinitions()
foreach ($sch['properties'] as $name => $def) {
$sch['properties'][$name]['name'] = $name;
$sch['properties'][$name]['description'] = $def['description'];
$sch['properties'][$name]['example'] = $def['x-example'];
$sch['properties'][$name]['required'] = in_array($name, $sch['required']);
if (isset($def['items']['$ref'])) {
//nested model
Expand Down
2 changes: 1 addition & 1 deletion templates/dart/README.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![pub package](https://img.shields.io/pub/v/{{ language.params.packageName }}.svg?style=flat-square)](https://pub.dartlang.org/packages/{{ language.params.packageName }})
![License](https://img.shields.io/github/license/{{ sdk.gitUserName|url_encode }}/{{ sdk.gitRepoName|url_encode }}.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-{{ spec.version|url_encode }}-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-{{spec.version | split('.') | slice(0,2) | join('.') ~ '.x' | url_encode}}-blue.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
{% if sdk.twitterHandle %}
[![Twitter Account](https://img.shields.io/twitter/follow/{{ sdk.twitterHandle }}?color=00acee&label=twitter&style=flat-square)](https://twitter.com/{{ sdk.twitterHandle }})
Expand Down
19 changes: 11 additions & 8 deletions templates/dart/lib/id.dart.twig
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
part of {{ language.params.packageName }};

/// Helper class to generate ID strings for resources.
class ID {
ID._();

static String unique() {
return 'unique()';
}
ID._();

static String custom(String id) {
return id;
}
/// Have Appwrite generate a unique ID for you.
static String unique() {
return 'unique()';
}

/// Uses [id] as the ID for the resource.
static String custom(String id) {
return id;
}
}
1 change: 1 addition & 0 deletions templates/dart/lib/models.dart.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// {{spec.title | caseUcfirst}} Models
library {{ language.params.packageName }}.models;

part 'src/models/model.dart';
Expand Down
5 changes: 5 additions & 0 deletions templates/dart/lib/package.dart.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/// {{spec.title | caseUcfirst}} {{sdk.name}} SDK
///
/// This SDK is compatible with Appwrite server version {{spec.version | split('.') | slice(0,2) | join('.') ~ '.x' }}.
/// For older versions, please check
/// [previous releases](https://github.com/{{sdk.gitUserName}}/{{sdk.gitRepoName}}/releases).
library {{ language.params.packageName }};

import 'dart:async';
Expand Down
45 changes: 29 additions & 16 deletions templates/dart/lib/permission.dart.twig
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
part of {{ language.params.packageName }};

/// Helper class to generate permission strings for resources.
class Permission {
Permission._();
Permission._();

static String read(String role) {
return 'read("$role")';
}
static String write(String role) {
return 'write("$role")';
}
static String create(String role) {
return 'create("$role")';
}
static String update(String role) {
return 'update("$role")';
}
static String delete(String role) {
return 'delete("$role")';
}
/// Read permission for provided [role]
static String read(String role) {
return 'read("$role")';
}

/// Write permission for provided [role]
///
/// This is an alias of update, delete, and possibly create.
/// Don't use write in combination with update, delete, or create.
static String write(String role) {
return 'write("$role")';
}

/// Create permission for provided [role]
static String create(String role) {
return 'create("$role")';
}

/// Update permission for provided [role]
static String update(String role) {
return 'update("$role")';
}

/// Delete permission for provided [role]
static String delete(String role) {
return 'delete("$role")';
}
}
70 changes: 63 additions & 7 deletions templates/dart/lib/query.dart.twig
Original file line number Diff line number Diff line change
@@ -1,61 +1,117 @@
part of {{ language.params.packageName }};

/// Helper class to generate query strings.
class Query {
Query._();

Query._();

/// Filter resources where [attribute] is equal to [value].
///
/// [value] can be a single value or a list. If a list is used
/// the query will return resources where [attribute] is equal
/// to any of the values in the list.
static String equal(String attribute, dynamic value) =>
_addQuery(attribute, 'equal', value);

/// Filter resources where [attribute] is not equal to [value].
///
/// [value] can be a single value or a list. If a list is used
/// the query will return resources where [attribute] is equal
/// to any of the values in the list.
static String notEqual(String attribute, dynamic value) =>
_addQuery(attribute, 'notEqual', value);

/// Filter resources where [attribute] is less than [value].
///
/// [value] can be a single value or a list. If a list is used
/// the query will return resources where [attribute] is equal
/// to any of the values in the list.
static String lessThan(String attribute, dynamic value) =>
_addQuery(attribute, 'lessThan', value);

/// Filter resources where [attribute] is less than or equal to [value].
///
/// [value] can be a single value or a list. If a list is used
/// the query will return resources where [attribute] is equal
/// to any of the values in the list.
static String lessThanEqual(String attribute, dynamic value) =>
_addQuery(attribute, 'lessThanEqual', value);

/// Filter resources where [attribute] is greater than [value].
///
/// [value] can be a single value or a list. If a list is used
/// the query will return resources where [attribute] is equal
/// to any of the values in the list.
static String greaterThan(String attribute, dynamic value) =>
_addQuery(attribute, 'greaterThan', value);

/// Filter resources where [attribute] is greater than or equal to [value].
///
/// [value] can be a single value or a list. If a list is used
/// the query will return resources where [attribute] is equal
/// to any of the values in the list.
static String greaterThanEqual(String attribute, dynamic value) =>
_addQuery(attribute, 'greaterThanEqual', value);

/// Filter resources where by searching [attribute] for [value].
///
/// A fulltext index on [attribute] is required for this query to work.
static String search(String attribute, String value) =>
_addQuery(attribute, 'search', value);

/// Filter resources where [attribute] is null.
static String isNull(String attribute) => 'isNull("$attribute")';

/// Filter resources where [attribute] is not null.
static String isNotNull(String attribute) => 'isNotNull("$attribute")';

/// Filter resources where [attribute] is between [start] and [end] (inclusive).
static String between(String attribute, dynamic start, dynamic end) =>
_addQuery(attribute, 'between', [start, end]);

/// Filter resources where [attribute] starts with [value].
static String startsWith(String attribute, String value) =>
_addQuery(attribute, 'startsWith', value);

/// Filter resources where [attribute] ends with [value].
static String endsWith(String attribute, String value) =>
_addQuery(attribute, 'endsWith', value);

static String select(List<String> attributes) => 'select([${attributes.map((attr) => "\"$attr\"").join(",")}])';
/// Specify which attributes should be returned by the API call.
static String select(List<String> attributes) =>
'select([${attributes.map((attr) => "\"$attr\"").join(",")}])';

/// Sort results by [attribute] ascending.
static String orderAsc(String attribute) => 'orderAsc("$attribute")';

/// Sort results by [attribute] descending.
static String orderDesc(String attribute) => 'orderDesc("$attribute")';

/// Return results before [id].
///
/// Refer to the [Cursor Based Pagination]({{sdk.url}}/docs/pagination#cursor-pagination)
/// docs for more information.
static String cursorBefore(String id) => 'cursorBefore("$id")';

/// Return results after [id].
///
/// Refer to the [Cursor Based Pagination]({{sdk.url}}/docs/pagination#cursor-pagination)
/// docs for more information.
static String cursorAfter(String id) => 'cursorAfter("$id")';

/// Return only [limit] results.
static String limit(int limit) => 'limit($limit)';

/// Return results from [offset].
///
/// Refer to the [Offset Pagination]({{sdk.url}}/docs/pagination#offset-pagination)
/// docs for more information.
static String offset(int offset) => 'offset($offset)';

static String _addQuery(String attribute, String method, dynamic value) => (value
is List)
? '$method("$attribute", [${value.map((item) => parseValues(item)).join(",")}])'
: '$method("$attribute", [${parseValues(value)}])';
? '$method("$attribute", [${value.map((item) => _parseValues(item)).join(",")}])'
: '$method("$attribute", [${_parseValues(value)}])';

static String parseValues(dynamic value) =>
static String _parseValues(dynamic value) =>
(value is String) ? '"$value"' : '$value';
}
}
Loading