Skip to content

Commit a53c907

Browse files
Merge pull request #515 from appwrite/feat-tests-for-helper-classes
POC: Test for Helper Classes
2 parents c775ff0 + 046959b commit a53c907

Some content is hidden

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

56 files changed

+901
-150
lines changed

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/android/library/src/main/java/io/appwrite/Query.kt.twig

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,32 @@ class Query {
66

77
fun notEqual(attribute: String, value: Any) = Query.addQuery(attribute, "notEqual", value)
88

9-
fun lesser(attribute: String, value: Any) = Query.addQuery(attribute, "lesser", value)
9+
fun lessThan(attribute: String, value: Any) = Query.addQuery(attribute, "lessThan", value)
1010

11-
fun lesserEqual(attribute: String, value: Any) = Query.addQuery(attribute, "lesserEqual", value)
11+
fun lessThanEqual(attribute: String, value: Any) = Query.addQuery(attribute, "lessThanEqual", value)
1212

13-
fun greater(attribute: String, value: Any) = Query.addQuery(attribute, "greater", value)
13+
fun greaterThan(attribute: String, value: Any) = Query.addQuery(attribute, "greaterThan", value)
1414

15-
fun greaterEqual(attribute: String, value: Any) = Query.addQuery(attribute, "greaterEqual", value)
15+
fun greaterThanEqual(attribute: String, value: Any) = Query.addQuery(attribute, "greaterThanEqual", value)
1616

1717
fun search(attribute: String, value: String) = Query.addQuery(attribute, "search", value)
1818

19-
private fun addQuery(attribute: String, oper: String, value: Any): String {
19+
fun orderAsc(attribute: String) = "orderAsc(\"${attribute}\")"
20+
21+
fun orderDesc(attribute: String) = "orderDesc(\"${attribute}\")"
22+
23+
fun cursorBefore(documentId: String) = "cursorBefore(\"${documentId}\")"
24+
25+
fun cursorAfter(documentId: String) = "cursorAfter(\"${documentId}\")"
26+
27+
fun limit(limit: Int) = "limit(${limit})"
28+
29+
fun offset(offset: Int) = "offset(${offset})"
30+
31+
private fun addQuery(attribute: String, method: String, value: Any): String {
2032
return when (value) {
21-
is List<*> -> "${attribute}.${oper}(${value.map{it -> parseValues(it!!)}.joinToString(",")})"
22-
else -> "${attribute}.${oper}(${Query.parseValues(value)})"
33+
is List<*> -> "${method}(\"${attribute}\", [${value.map{it -> parseValues(it!!)}.joinToString(",")}])"
34+
else -> "${method}(\"${attribute}\", [${Query.parseValues(value)}])"
2335
}
2436
}
2537
private fun parseValues(value: Any): String {

templates/dart/lib/query.dart.twig

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,49 @@ class Query {
77
static notEqual(String attribute, dynamic value) =>
88
_addQuery(attribute, 'notEqual', value);
99

10-
static lesser(String attribute, dynamic value) =>
11-
_addQuery(attribute, 'lesser', value);
10+
static lessThan(String attribute, dynamic value) =>
11+
_addQuery(attribute, 'lessThan', value);
1212

13-
static lesserEqual(String attribute, dynamic value) =>
14-
_addQuery(attribute, 'lesserEqual', value);
13+
static lessThanEqual(String attribute, dynamic value) =>
14+
_addQuery(attribute, 'lessThanEqual', value);
1515

16-
static greater(String attribute, dynamic value) =>
17-
_addQuery(attribute, 'greater', value);
16+
static greaterThan(String attribute, dynamic value) =>
17+
_addQuery(attribute, 'greaterThan', value);
1818

19-
static greaterEqual(String attribute, dynamic value) =>
20-
_addQuery(attribute, 'greaterEqual', value);
19+
static greaterThanEqual(String attribute, dynamic value) =>
20+
_addQuery(attribute, 'greaterThanEqual', value);
2121

2222
static search(String attribute, String value) =>
2323
_addQuery(attribute, 'search', value);
2424

25-
static String _addQuery(String attribute, String oper, dynamic value) => (value
25+
static String _addQuery(String attribute, String method, dynamic value) => (value
2626
is List)
27-
? '$attribute.$oper(${value.map((item) => parseValues(item)).join(",")})'
28-
: '$attribute.$oper(${parseValues(value)})';
27+
? '$method("$attribute", [${value.map((item) => parseValues(item)).join(",")}])'
28+
: '$method("$attribute", [${parseValues(value)}])';
29+
30+
static String orderAsc(String attribute) {
31+
return 'orderAsc("$attribute")';
32+
}
33+
34+
static String orderDesc(String attribute) {
35+
return 'orderDesc("$attribute")';
36+
}
37+
38+
static String cursorBefore(String id) {
39+
return 'cursorBefore("$id")';
40+
}
41+
42+
static String cursorAfter(String id) {
43+
return 'cursorAfter("$id")';
44+
}
45+
46+
static String limit(int limit) {
47+
return 'limit($limit)';
48+
}
49+
50+
static String offset(int offset) {
51+
return 'offset($offset)';
52+
}
2953

3054
static String parseValues(dynamic value) =>
3155
(value is String) ? '"$value"' : '$value';

templates/deno/src/query.ts.twig

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,48 @@ export class Query {
99
static notEqual = (attribute: string, value: QueryTypes): string =>
1010
Query.addQuery(attribute, "notEqual", value);
1111

12-
static lesser = (attribute: string, value: QueryTypes): string =>
13-
Query.addQuery(attribute, "lesser", value);
12+
static lessThan = (attribute: string, value: QueryTypes): string =>
13+
Query.addQuery(attribute, "lessThan", value);
1414

15-
static lesserEqual = (attribute: string, value: QueryTypes): string =>
16-
Query.addQuery(attribute, "lesserEqual", value);
15+
static lessThanEqual = (attribute: string, value: QueryTypes): string =>
16+
Query.addQuery(attribute, "lessThanEqual", value);
1717

18-
static greater = (attribute: string, value: QueryTypes): string =>
19-
Query.addQuery(attribute, "greater", value);
18+
static greaterThan = (attribute: string, value: QueryTypes): string =>
19+
Query.addQuery(attribute, "greaterThan", value);
2020

21-
static greaterEqual = (attribute: string, value: QueryTypes): string =>
22-
Query.addQuery(attribute, "greaterEqual", value);
21+
static greaterThanEqual = (attribute: string, value: QueryTypes): string =>
22+
Query.addQuery(attribute, "greaterThanEqual", value);
2323

2424
static search = (attribute: string, value: string): string =>
2525
Query.addQuery(attribute, "search", value);
2626

27-
private static addQuery = (attribute: string, oper: string, value: QueryTypes): string =>
27+
static orderDesc = (attribute: string): string =>
28+
`orderDesc("${attribute}")`;
29+
30+
static orderAsc = (attribute: string): string =>
31+
`orderAsc("${attribute}")`;
32+
33+
static cursorAfter = (documentId: string): string =>
34+
`cursorAfter("${documentId}")`;
35+
36+
static cursorBefore = (documentId: string): string =>
37+
`cursorBefore("${documentId}")`;
38+
39+
static limit = (value: number): string =>
40+
`limit(${value})`;
41+
42+
static offset = (value: number): string =>
43+
`offset(${value})`;
44+
45+
private static addQuery = (attribute: string, method: string, value: QueryTypes): string =>
2846
value instanceof Array
29-
? `${attribute}.${oper}(${value
47+
? `${method}("${attribute}", [${value
3048
.map((v: QueryTypesSingle) => Query.parseValues(v))
31-
.join(",")})`
32-
: `${attribute}.${oper}(${Query.parseValues(value)})`;
49+
.join(",")}])`
50+
: `${method}("${attribute}", [${Query.parseValues(value)}])`;
3351

3452
private static parseValues = (value: QueryTypes): string =>
3553
typeof value === "string" || value instanceof String
3654
? `"${value}"`
3755
: `${value}`;
38-
}
56+
}

templates/flutter/lib/query.dart.twig

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,49 @@ class Query {
77
static notEqual(String attribute, dynamic value) =>
88
_addQuery(attribute, 'notEqual', value);
99

10-
static lesser(String attribute, dynamic value) =>
11-
_addQuery(attribute, 'lesser', value);
10+
static lessThan(String attribute, dynamic value) =>
11+
_addQuery(attribute, 'lessThan', value);
1212

13-
static lesserEqual(String attribute, dynamic value) =>
14-
_addQuery(attribute, 'lesserEqual', value);
13+
static lessThanEqual(String attribute, dynamic value) =>
14+
_addQuery(attribute, 'lessThanEqual', value);
1515

16-
static greater(String attribute, dynamic value) =>
17-
_addQuery(attribute, 'greater', value);
16+
static greaterThan(String attribute, dynamic value) =>
17+
_addQuery(attribute, 'greaterThan', value);
1818

19-
static greaterEqual(String attribute, dynamic value) =>
20-
_addQuery(attribute, 'greaterEqual', value);
19+
static greaterThanEqual(String attribute, dynamic value) =>
20+
_addQuery(attribute, 'greaterThanEqual', value);
2121

2222
static search(String attribute, String value) =>
2323
_addQuery(attribute, 'search', value);
2424

25-
static String _addQuery(String attribute, String oper, dynamic value) => (value
25+
static String _addQuery(String attribute, String method, dynamic value) => (value
2626
is List)
27-
? '$attribute.$oper(${value.map((item) => parseValues(item)).join(",")})'
28-
: '$attribute.$oper(${parseValues(value)})';
27+
? '$method("$attribute", [${value.map((item) => parseValues(item)).join(",")}])'
28+
: '$method("$attribute", [${parseValues(value)}])';
29+
30+
static String orderAsc(String attribute) {
31+
return 'orderAsc("$attribute")';
32+
}
33+
34+
static String orderDesc(String attribute) {
35+
return 'orderDesc("$attribute")';
36+
}
37+
38+
static String cursorBefore(String id) {
39+
return 'cursorBefore("$id")';
40+
}
41+
42+
static String cursorAfter(String id) {
43+
return 'cursorAfter("$id")';
44+
}
45+
46+
static String limit(int limit) {
47+
return 'limit($limit)';
48+
}
49+
50+
static String offset(int offset) {
51+
return 'offset($offset)';
52+
}
2953

3054
static String parseValues(dynamic value) =>
3155
(value is String) ? '"$value"' : '$value';

templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,32 @@ class Query {
66

77
fun notEqual(attribute: String, value: Any) = Query.addQuery(attribute, "notEqual", value)
88

9-
fun lesser(attribute: String, value: Any) = Query.addQuery(attribute, "lesser", value)
9+
fun lessThan(attribute: String, value: Any) = Query.addQuery(attribute, "lessThan", value)
1010

11-
fun lesserEqual(attribute: String, value: Any) = Query.addQuery(attribute, "lesserEqual", value)
11+
fun lessThanEqual(attribute: String, value: Any) = Query.addQuery(attribute, "lessThanEqual", value)
1212

13-
fun greater(attribute: String, value: Any) = Query.addQuery(attribute, "greater", value)
14-
15-
fun greaterEqual(attribute: String, value: Any) = Query.addQuery(attribute, "greaterEqual", value)
13+
fun greaterThan(attribute: String, value: Any) = Query.addQuery(attribute, "greaterThan", value)
1614

15+
fun greaterThanEqual(attribute: String, value: Any) = Query.addQuery(attribute, "greaterThanEqual", value)
16+
1717
fun search(attribute: String, value: String) = Query.addQuery(attribute, "search", value)
1818

19-
private fun addQuery(attribute: String, oper: String, value: Any): String {
19+
fun orderAsc(attribute: String) = "orderAsc(\"${attribute}\")"
20+
21+
fun orderDesc(attribute: String) = "orderDesc(\"${attribute}\")"
22+
23+
fun cursorBefore(documentId: String) = "cursorBefore(\"${documentId}\")"
24+
25+
fun cursorAfter(documentId: String) = "cursorAfter(\"${documentId}\")"
26+
27+
fun limit(limit: Int) = "limit(${limit})"
28+
29+
fun offset(offset: Int) = "offset(${offset})"
30+
31+
private fun addQuery(attribute: String, method: String, value: Any): String {
2032
return when (value) {
21-
is List<*> -> "${attribute}.${oper}(${value.map{it -> parseValues(it!!)}.joinToString(",")})"
22-
else -> "${attribute}.${oper}(${Query.parseValues(value)})"
33+
is List<*> -> "${method}(\"${attribute}\", [${value.map{it -> parseValues(it!!)}.joinToString(",")}])"
34+
else -> "${method}(\"${attribute}\", [${Query.parseValues(value)}])"
2335
}
2436
}
2537
private fun parseValues(value: Any): String {

templates/node/index.d.ts.twig

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,29 @@ declare module "{{ language.params.npmPackage|caseDash }}" {
147147

148148
static notEqual(attribute: string, value: QueryTypes): string;
149149

150-
static lesser(attribute: string, value: QueryTypes): string;
150+
static lessThan(attribute: string, value: QueryTypes): string;
151151

152-
static lesserEqual(attribute: string, value: QueryTypes): string;
152+
static lessThanEqual(attribute: string, value: QueryTypes): string;
153153

154-
static greater(attribute: string, value: QueryTypes): string;
154+
static greaterThan(attribute: string, value: QueryTypes): string;
155155

156-
static greaterEqual(attribute: string, value: QueryTypes): string;
156+
static greaterThanEqual(attribute: string, value: QueryTypes): string;
157157

158158
static search(attribute: string, value: string): string;
159159

160-
private static addQuery(attribute: string, oper: string, value: QueryTypes): string;
160+
static orderDesc(attribute: string): string;
161+
162+
static orderAsc(attribute: string): string;
163+
164+
static cursorAfter(documentId: string): string;
165+
166+
static cursorBefore(documentId: string): string;
167+
168+
static limit(value: number): string;
169+
170+
static offset = (value: number): string;
171+
172+
private static addQuery(attribute: string, method: string, value: QueryTypes): string;
161173

162174
private static parseValues(value: QueryTypes): string;
163175
}

templates/node/lib/query.js.twig

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,45 @@ class Query {
55
static notEqual = (attribute, value) =>
66
Query.addQuery(attribute, "notEqual", value);
77

8-
static lesser = (attribute, value) =>
9-
Query.addQuery(attribute, "lesser", value);
8+
static lessThan = (attribute, value) =>
9+
Query.addQuery(attribute, "lessThan", value);
1010

11-
static lesserEqual = (attribute, value) =>
12-
Query.addQuery(attribute, "lesserEqual", value);
11+
static lessThanEqual = (attribute, value) =>
12+
Query.addQuery(attribute, "lessThanEqual", value);
1313

14-
static greater = (attribute, value) =>
15-
Query.addQuery(attribute, "greater", value);
14+
static greaterThan = (attribute, value) =>
15+
Query.addQuery(attribute, "greaterThan", value);
1616

17-
static greaterEqual = (attribute, value) =>
18-
Query.addQuery(attribute, "greaterEqual", value);
17+
static greaterThanEqual = (attribute, value) =>
18+
Query.addQuery(attribute, "greaterThanEqual", value);
1919

2020
static search = (attribute, value) =>
2121
Query.addQuery(attribute, "search", value);
2222

23-
static addQuery = (attribute, oper, value) =>
23+
static orderDesc = (attribute) =>
24+
`orderDesc("${attribute}")`;
25+
26+
static orderAsc = (attribute) =>
27+
`orderAsc("${attribute}")`;
28+
29+
static cursorAfter = (documentId) =>
30+
`cursorAfter("${documentId}")`;
31+
32+
static cursorBefore = (documentId) =>
33+
`cursorBefore("${documentId}")`;
34+
35+
static limit = (value) =>
36+
`limit(${value})`;
37+
38+
static offset = (value) =>
39+
`offset(${value})`;
40+
41+
static addQuery = (attribute, method, value) =>
2442
value instanceof Array
25-
? `${attribute}.${oper}(${value
43+
? `${method}("${attribute}", [${value
2644
.map((v) => Query.parseValues(v))
27-
.join(",")})`
28-
: `${attribute}.${oper}(${Query.parseValues(value)})`;
45+
.join(",")}])`
46+
: `${method}("${attribute}", [${Query.parseValues(value)}])`;
2947

3048
static parseValues = (value) =>
3149
typeof value === "string" || value instanceof String

0 commit comments

Comments
 (0)