Skip to content

Commit

Permalink
Merge pull request #762 from appwrite/feat-fix-queries-tests
Browse files Browse the repository at this point in the history
Fix queries test
  • Loading branch information
lohanidamodar authored Jan 23, 2024
2 parents d2430f2 + c7ffa64 commit 8564591
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package {{ sdk.namespace | caseDot }}

import com.google.gson.Gson

class Query(
val method: String
val method: String,
val attribute: String? = null,
val values: List<Any>? = null,
) {
Expand Down Expand Up @@ -52,9 +54,9 @@ class Query(

fun or(queries: List<Query>) = Query("or", null, queries)

private fun parseValue(value: Any): Any {
private fun parseValue(value: Any): List<Any> {
return when (value) {
is List<*> -> value
is List<*> -> value as List<Any>
else -> listOf(value)
}
}
Expand Down
1 change: 1 addition & 0 deletions templates/dart/lib/package.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ library {{ language.params.packageName }};

import 'dart:async';
import 'dart:typed_data';
import 'dart:convert';

import 'src/enums.dart';
import 'src/service.dart';
Expand Down
1 change: 0 additions & 1 deletion templates/dart/lib/query.dart.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
part of {{ language.params.packageName }};

import 'dart:convert';

/// Helper class to generate query strings.
class Query {
Expand Down
2 changes: 2 additions & 0 deletions templates/flutter/lib/package.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ library {{ language.params.packageName }};

import 'dart:async';
import 'dart:typed_data';
import 'dart:convert';

import 'src/enums.dart';
import 'src/service.dart';
import 'src/input_file.dart';
Expand Down
46 changes: 23 additions & 23 deletions tests/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,29 @@ abstract class Base extends TestCase
];

protected const QUERY_HELPER_RESPONSES = [
'{ "method": "equal", "attribute": "released", "values": [true]}',
'{ "method": "equal", "attribute": "title", "values": ["Spiderman", "Dr. Strange"]}',
'{ "method": "notEqual", "attribute": "title", "values": ["Spiderman"]}',
'{ "method": "lessThan", "attribute": "releasedYear", "values": [1990]}',
'{ "method": "greaterThan", "attribute": "releasedYear", "values": [1990]}',
'{ "method": "search", "attribute": "name", "values": ["john"]}',
'{ "method": "isNull", "attribute": "name"}',
'{ "method": "isNotNull", "attribute": "name"}',
'{ "method": "between", "attribute": "age", "values": [50, 100]}',
'{ "method": "between", "attribute": "age", "values": [50.5, 100.5]}',
'{ "method": "between", "attribute": "name", "values": ["Anna", "Brad"]}',
'{ "method": "startsWith", "attribute": "name", "values": ["Ann"]}',
'{ "method": "endsWith", "attribute": "name", "values": ["nne"]}',
'{ "method": "select", "values": [["name", "age"]]}',
'{ "method": "orderAsc", "attribute": "title"}',
'{ "method": "orderDesc", "attribute": "title"}',
'{ "method": "cursorAfter", "values": ["my_movie_id"]}',
'{ "method": "cursorBefore", "values": ["my_movie_id"]}',
'{ "method": "limit", "values": [50]}',
'{ "method": "offset", "values": [20]}',
'{ "method": "contains", "attribute": "title", "values": ["Spider"] }',
'{ "method": "contains", "attribute": "labels", "values": ["first"] }',
'{ "method": "or", "values": [{ "method": "equal", "attribute": "released", "values": [true] }, { "method": "lessThan", "attribute": "releasedYear", "values": [1990] }] }',
'{"method":"equal","attribute":"released","values":[true]}',
'{"method":"equal","attribute":"title","values":["Spiderman","Dr. Strange"]}',
'{"method":"notEqual","attribute":"title","values":["Spiderman"]}',
'{"method":"lessThan","attribute":"releasedYear","values":[1990]}',
'{"method":"greaterThan","attribute":"releasedYear","values":[1990]}',
'{"method":"search","attribute":"name","values":["john"]}',
'{"method":"isNull","attribute":"name"}',
'{"method":"isNotNull","attribute":"name"}',
'{"method":"between","attribute":"age","values":[50,100]}',
'{"method":"between","attribute":"age","values":[50.5,100.5]}',
'{"method":"between","attribute":"name","values":["Anna","Brad"]}',
'{"method":"startsWith","attribute":"name","values":["Ann"]}',
'{"method":"endsWith","attribute":"name","values":["nne"]}',
'{"method":"select","values":["name","age"]}',
'{"method":"orderAsc","attribute":"title"}',
'{"method":"orderDesc","attribute":"title"}',
'{"method":"cursorAfter","values":["my_movie_id"]}',
'{"method":"cursorBefore","values":["my_movie_id"]}',
'{"method":"limit","values":[50]}',
'{"method":"offset","values":[20]}',
'{"method":"contains","attribute":"title","values":["Spider"]}',
'{"method":"contains","attribute":"labels","values":["first"]}',
'{"method":"or","values":[{"method":"equal","attribute":"released","values":[true]},{"method":"lessThan","attribute":"releasedYear","values":[1990]}]}',
];

protected const PERMISSION_HELPER_RESPONSES = [
Expand Down
6 changes: 3 additions & 3 deletions tests/languages/android/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ class ServiceTest {
writeToFile(Query.cursorBefore("my_movie_id").toString())
writeToFile(Query.limit(50).toString())
writeToFile(Query.offset(20).toString())
writeToFile(Query.contains("title", ["Spider"]).toString())
writeToFile(Query.contains("labels", ["first"]).toString())
writeToFile(Query.or(listOf(Query.equal("released", listOf(true)), Query.lessThan("releasedYear", 1990)))
writeToFile(Query.contains("title", listOf("Spider")).toString())
writeToFile(Query.contains("labels", listOf("first")).toString())
writeToFile(Query.or(listOf(Query.equal("released", listOf(true)), Query.lessThan("releasedYear", 1990))).toString())

// Permission & Roles helper tests
writeToFile(Permission.read(Role.any()))
Expand Down
6 changes: 6 additions & 0 deletions tests/languages/dart/tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ void main() async {
print(Query.cursorBefore("my_movie_id"));
print(Query.limit(50));
print(Query.offset(20));
print(Query.contains("title", "Spider"));
print(Query.contains("labels", "first"));
print(Query.or([
Query.equal("released", true),
Query.lessThan("releasedYear", 1990)
]));

// Permission & Role helper tests
print(Permission.read(Role.any()));
Expand Down
6 changes: 6 additions & 0 deletions tests/languages/flutter/tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ void main() async {
print(Query.cursorBefore("my_movie_id"));
print(Query.limit(50));
print(Query.offset(20));
print(Query.contains("title", "Spider"));
print(Query.contains("labels", "first"));
print(Query.or([
Query.equal("released", true),
Query.lessThan("releasedYear", 1990)
]));

// Permission & Role helper tests
print(Permission.read(Role.any()));
Expand Down

0 comments on commit 8564591

Please sign in to comment.