Skip to content

Commit 6533513

Browse files
Merge pull request #673 from appwrite/feat-flutter-service-test
2 parents 238f420 + b73f6f7 commit 6533513

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1339
-51
lines changed

src/SDK/Language/Dart.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,61 @@ public function getFiles(): array
401401
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
402402
'template' => 'dart/docs/example.md.twig',
403403
],
404+
[
405+
'scope' => 'service',
406+
'destination' => '/test/services/{{service.name | caseDash}}_test.dart',
407+
'template' => 'dart/test/services/service_test.dart.twig',
408+
],
409+
[
410+
'scope' => 'definition',
411+
'destination' => '/test/src/models/{{definition.name | caseSnake }}_test.dart',
412+
'template' => 'dart/test/src/models/model_test.dart.twig',
413+
],
414+
[
415+
'scope' => 'default',
416+
'destination' => '/test/id_test.dart',
417+
'template' => 'dart/test/id_test.dart.twig',
418+
],
419+
[
420+
'scope' => 'default',
421+
'destination' => '/test/permission_test.dart',
422+
'template' => 'dart/test/permission_test.dart.twig',
423+
],
424+
[
425+
'scope' => 'default',
426+
'destination' => '/test/query_test.dart',
427+
'template' => 'dart/test/query_test.dart.twig',
428+
],
429+
[
430+
'scope' => 'default',
431+
'destination' => '/test/role_test.dart',
432+
'template' => 'dart/test/role_test.dart.twig',
433+
],
434+
[
435+
'scope' => 'default',
436+
'destination' => '/test/src/enums_test.dart',
437+
'template' => 'dart/test/src/enums_test.dart.twig',
438+
],
439+
[
440+
'scope' => 'default',
441+
'destination' => '/test/src/upload_progress_test.dart',
442+
'template' => 'dart/test/src/upload_progress_test.dart.twig',
443+
],
444+
[
445+
'scope' => 'default',
446+
'destination' => '/test/src/exception_test.dart',
447+
'template' => 'dart/test/src/exception_test.dart.twig',
448+
],
449+
[
450+
'scope' => 'default',
451+
'destination' => '/test/src/input_file_test.dart',
452+
'template' => 'dart/test/src/input_file_test.dart.twig',
453+
],
454+
[
455+
'scope' => 'default',
456+
'destination' => '/test/src/response_test.dart',
457+
'template' => 'dart/test/src/response_test.dart.twig',
458+
],
404459
[
405460
'scope' => 'default',
406461
'destination' => '.travis.yml',

src/SDK/Language/Flutter.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,86 @@ public function getFiles(): array
240240
'destination' => '/lib/services/{{service.name | caseDash}}.dart',
241241
'template' => 'flutter/lib/services/service.dart.twig',
242242
],
243+
[
244+
'scope' => 'service',
245+
'destination' => '/test/services/{{service.name | caseDash}}_test.dart',
246+
'template' => 'dart/test/services/service_test.dart.twig',
247+
],
248+
[
249+
'scope' => 'definition',
250+
'destination' => '/test/src/models/{{definition.name | caseSnake }}_test.dart',
251+
'template' => 'dart/test/src/models/model_test.dart.twig',
252+
],
253+
[
254+
'scope' => 'default',
255+
'destination' => '/test/id_test.dart',
256+
'template' => 'dart/test/id_test.dart.twig',
257+
],
258+
[
259+
'scope' => 'default',
260+
'destination' => '/test/permission_test.dart',
261+
'template' => 'dart/test/permission_test.dart.twig',
262+
],
263+
[
264+
'scope' => 'default',
265+
'destination' => '/test/query_test.dart',
266+
'template' => 'dart/test/query_test.dart.twig',
267+
],
268+
[
269+
'scope' => 'default',
270+
'destination' => '/test/role_test.dart',
271+
'template' => 'dart/test/role_test.dart.twig',
272+
],
273+
[
274+
'scope' => 'default',
275+
'destination' => '/test/src/cookie_manager_test.dart',
276+
'template' => 'flutter/test/src/cookie_manager_test.dart.twig',
277+
],
278+
[
279+
'scope' => 'default',
280+
'destination' => '/test/src/interceptor_test.dart',
281+
'template' => 'flutter/test/src/interceptor_test.dart.twig',
282+
],
283+
[
284+
'scope' => 'default',
285+
'destination' => '/test/src/realtime_response_test.dart',
286+
'template' => 'flutter/test/src/realtime_response_test.dart.twig',
287+
],
288+
[
289+
'scope' => 'default',
290+
'destination' => '/test/src/realtime_response_connected_test.dart',
291+
'template' => 'flutter/test/src/realtime_response_connected_test.dart.twig',
292+
],
293+
[
294+
'scope' => 'default',
295+
'destination' => '/test/src/realtime_subscription_test.dart',
296+
'template' => 'flutter/test/src/realtime_subscription_test.dart.twig',
297+
],
298+
[
299+
'scope' => 'default',
300+
'destination' => '/test/src/enums_test.dart',
301+
'template' => 'dart/test/src/enums_test.dart.twig',
302+
],
303+
[
304+
'scope' => 'default',
305+
'destination' => '/test/src/upload_progress_test.dart',
306+
'template' => 'dart/test/src/upload_progress_test.dart.twig',
307+
],
308+
[
309+
'scope' => 'default',
310+
'destination' => '/test/src/input_file_test.dart',
311+
'template' => 'dart/test/src/input_file_test.dart.twig',
312+
],
313+
[
314+
'scope' => 'default',
315+
'destination' => '/test/src/exception_test.dart',
316+
'template' => 'dart/test/src/exception_test.dart.twig',
317+
],
318+
[
319+
'scope' => 'default',
320+
'destination' => '/test/src/response_test.dart',
321+
'template' => 'dart/test/src/response_test.dart.twig',
322+
],
243323
[
244324
'scope' => 'method',
245325
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',

src/Spec/Swagger2.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ public function getDefinitions()
319319
foreach ($sch['properties'] as $name => $def) {
320320
$sch['properties'][$name]['name'] = $name;
321321
$sch['properties'][$name]['description'] = $def['description'];
322+
$sch['properties'][$name]['example'] = $def['x-example'];
322323
$sch['properties'][$name]['required'] = in_array($name, $sch['required']);
323324
if (isset($def['items']['$ref'])) {
324325
//nested model

templates/dart/README.md.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![pub package](https://img.shields.io/pub/v/{{ language.params.packageName }}.svg?style=flat-square)](https://pub.dartlang.org/packages/{{ language.params.packageName }})
44
![License](https://img.shields.io/github/license/{{ sdk.gitUserName|url_encode }}/{{ sdk.gitRepoName|url_encode }}.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-{{ spec.version|url_encode }}-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-{{spec.version | split('.') | slice(0,2) | join('.') ~ '.x' | url_encode}}-blue.svg?style=flat-square)
66
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
77
{% if sdk.twitterHandle %}
88
[![Twitter Account](https://img.shields.io/twitter/follow/{{ sdk.twitterHandle }}?color=00acee&label=twitter&style=flat-square)](https://twitter.com/{{ sdk.twitterHandle }})

templates/dart/lib/id.dart.twig

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
part of {{ language.params.packageName }};
22

3+
/// Helper class to generate ID strings for resources.
34
class ID {
4-
ID._();
5-
6-
static String unique() {
7-
return 'unique()';
8-
}
5+
ID._();
96

10-
static String custom(String id) {
11-
return id;
12-
}
7+
/// Have Appwrite generate a unique ID for you.
8+
static String unique() {
9+
return 'unique()';
10+
}
11+
12+
/// Uses [id] as the ID for the resource.
13+
static String custom(String id) {
14+
return id;
15+
}
1316
}

templates/dart/lib/models.dart.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// {{spec.title | caseUcfirst}} Models
12
library {{ language.params.packageName }}.models;
23

34
part 'src/models/model.dart';

templates/dart/lib/package.dart.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/// {{spec.title | caseUcfirst}} {{sdk.name}} SDK
2+
///
3+
/// This SDK is compatible with Appwrite server version {{spec.version | split('.') | slice(0,2) | join('.') ~ '.x' }}.
4+
/// For older versions, please check
5+
/// [previous releases](https://github.com/{{sdk.gitUserName}}/{{sdk.gitRepoName}}/releases).
16
library {{ language.params.packageName }};
27

38
import 'dart:async';
Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
part of {{ language.params.packageName }};
22

3+
/// Helper class to generate permission strings for resources.
34
class Permission {
4-
Permission._();
5+
Permission._();
56

6-
static String read(String role) {
7-
return 'read("$role")';
8-
}
9-
static String write(String role) {
10-
return 'write("$role")';
11-
}
12-
static String create(String role) {
13-
return 'create("$role")';
14-
}
15-
static String update(String role) {
16-
return 'update("$role")';
17-
}
18-
static String delete(String role) {
19-
return 'delete("$role")';
20-
}
7+
/// Read permission for provided [role]
8+
static String read(String role) {
9+
return 'read("$role")';
10+
}
11+
12+
/// Write permission for provided [role]
13+
///
14+
/// This is an alias of update, delete, and possibly create.
15+
/// Don't use write in combination with update, delete, or create.
16+
static String write(String role) {
17+
return 'write("$role")';
18+
}
19+
20+
/// Create permission for provided [role]
21+
static String create(String role) {
22+
return 'create("$role")';
23+
}
24+
25+
/// Update permission for provided [role]
26+
static String update(String role) {
27+
return 'update("$role")';
28+
}
29+
30+
/// Delete permission for provided [role]
31+
static String delete(String role) {
32+
return 'delete("$role")';
33+
}
2134
}

templates/dart/lib/query.dart.twig

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,117 @@
11
part of {{ language.params.packageName }};
22

3+
/// Helper class to generate query strings.
34
class Query {
4-
Query._();
5-
5+
Query._();
6+
7+
/// Filter resources where [attribute] is equal to [value].
8+
///
9+
/// [value] can be a single value or a list. If a list is used
10+
/// the query will return resources where [attribute] is equal
11+
/// to any of the values in the list.
612
static String equal(String attribute, dynamic value) =>
713
_addQuery(attribute, 'equal', value);
814

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

54110
static String _addQuery(String attribute, String method, dynamic value) => (value
55111
is List)
56-
? '$method("$attribute", [${value.map((item) => parseValues(item)).join(",")}])'
57-
: '$method("$attribute", [${parseValues(value)}])';
112+
? '$method("$attribute", [${value.map((item) => _parseValues(item)).join(",")}])'
113+
: '$method("$attribute", [${_parseValues(value)}])';
58114

59-
static String parseValues(dynamic value) =>
115+
static String _parseValues(dynamic value) =>
60116
(value is String) ? '"$value"' : '$value';
61-
}
117+
}

0 commit comments

Comments
 (0)