From 390453aa9b59e6b1f849d802ff614e3e5ad91fa5 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 21 Sep 2022 21:08:20 +1200 Subject: [PATCH] Add datetime attribute test --- tests/e2e/Services/GraphQL/GraphQLBase.php | 18 ++++++++--- .../GraphQL/GraphQLDatabaseServerTest.php | 32 +++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/tests/e2e/Services/GraphQL/GraphQLBase.php b/tests/e2e/Services/GraphQL/GraphQLBase.php index 770b1fb965..8775bc48a1 100644 --- a/tests/e2e/Services/GraphQL/GraphQLBase.php +++ b/tests/e2e/Services/GraphQL/GraphQLBase.php @@ -25,6 +25,7 @@ trait GraphQLBase public static string $CREATE_EMAIL_ATTRIBUTE = 'create_email_attribute'; public static string $CREATE_IP_ATTRIBUTE = 'create_ip_attribute'; public static string $CREATE_ENUM_ATTRIBUTE = 'create_enum_attribute'; + public static string $CREATE_DATETIME_ATTRIBUTE = 'create_datetime_attribute'; public static string $GET_ATTRIBUTES = 'get_attributes'; public static string $GET_ATTRIBUTE = 'get_attribute'; public static string $DELETE_ATTRIBUTE = 'delete_attribute'; @@ -334,6 +335,15 @@ trait GraphQLBase array } }'; + case self::$CREATE_DATETIME_ATTRIBUTE: + return 'mutation createDatetimeAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $default: String, $array: Boolean){ + databasesCreateDatetimeAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) { + key + required + default + array + } + }'; case self::$CREATE_INDEX: return 'mutation createIndex($databaseId: String!, $collectionId: String!, $key: String!, $type: String!, $attributes: [String!]!, $orders: [String!]){ databasesCreateIndex(databaseId: $databaseId, collectionId: $collectionId, key: $key, type: $type, attributes: $attributes, orders: $orders) { @@ -421,8 +431,8 @@ trait GraphQLBase } }'; case self::$CREATE_CUSTOM_ENTITY: - return 'mutation createActor($name: String!, $age: Int!, $alive: Boolean!, $salary: Float, $email: String!, $role: String!, $ip: String, $url: String){ - actorsCreate(name: $name, age: $age, alive: $alive, salary: $salary, email: $email, role: $role, ip: $ip, url: $url) { + return 'mutation createActor($name: String!, $age: Int!, $alive: Boolean!, $salary: Float, $email: String!, $role: String!, $dob: String!, $ip: String, $url: String){ + actorsCreate(name: $name, age: $age, alive: $alive, salary: $salary, email: $email, role: $role, dob: $dob, ip: $ip, url: $url) { _id name age @@ -464,8 +474,8 @@ trait GraphQLBase } }'; case self::$UPDATE_CUSTOM_ENTITY: - return 'mutation updateCustomEntity($id: String!, $name: String!, $age: Int!, $alive: Boolean!, $salary: Float, $email: String!, $role: String!, $ip: String, $url: String){ - actorsUpdate(id: $id, name: $name, age: $age, alive: $alive, salary: $salary, email: $email, role: $role, ip: $ip, url: $url) { + return 'mutation updateCustomEntity($id: String!, $name: String, $age: Int, $alive: Boolean, $salary: Float, $email: String, $role: String, $dob: String, $ip: String, $url: String){ + actorsUpdate(id: $id, name: $name, age: $age, alive: $alive, salary: $salary, email: $email, role: $role, dob: $dob, ip: $ip, url: $url) { name age alive diff --git a/tests/e2e/Services/GraphQL/GraphQLDatabaseServerTest.php b/tests/e2e/Services/GraphQL/GraphQLDatabaseServerTest.php index aebc4c7604..9d1ffcb44f 100644 --- a/tests/e2e/Services/GraphQL/GraphQLDatabaseServerTest.php +++ b/tests/e2e/Services/GraphQL/GraphQLDatabaseServerTest.php @@ -271,6 +271,36 @@ class GraphQLDatabaseServerTest extends Scope return $data; } + /** + * @depends testCreateCollection + * @throws Exception + */ + public function testCreateDatetimeAttribute($data): array + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$CREATE_DATETIME_ATTRIBUTE); + $gqlPayload = [ + 'query' => $query, + 'variables' => [ + 'databaseId' => $data['database']['_id'], + 'collectionId' => $data['collection']['_id'], + 'key' => 'dob', + 'required' => true, + ] + ]; + + $attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $gqlPayload); + + $this->assertArrayNotHasKey('errors', $attribute['body']); + $this->assertIsArray($attribute['body']['data']); + $this->assertIsArray($attribute['body']['data']['databasesCreateDatetimeAttribute']); + + return $data; + } + /** * @depends testCreateCollection * @throws Exception @@ -399,6 +429,7 @@ class GraphQLDatabaseServerTest extends Scope 'alive' => true, 'salary' => 9999.9, 'role' => 'crew', + 'dob' => '2000-01-01T00:00:00Z', ], 'permissions' => [ Permission::read(Role::any()), @@ -448,6 +479,7 @@ class GraphQLDatabaseServerTest extends Scope 'salary' => 9999.9, 'email' => 'johndoe@appwrite.io', 'role' => 'crew', + 'dob' => '2000-01-01T00:00:00Z', ] ];