From 5f0032bb7fa8260203388e364bd6cf3ca97458f0 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 14 Jul 2022 10:52:55 +0100 Subject: [PATCH 01/10] Use 202 when resources are created asyncronously --- app/controllers/api/databases.php | 18 +++++++++--------- app/controllers/api/functions.php | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 989ed660c5..3adddcfc41 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -882,7 +882,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string ->label('sdk.namespace', 'databases') ->label('sdk.method', 'createStringAttribute') ->label('sdk.description', '/docs/references/databases/create-string-attribute.md') - ->label('sdk.response.code', Response::STATUS_CODE_CREATED) + ->label('sdk.response.code', Response::STATUS_CODE_ACCEPTED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_ATTRIBUTE_STRING) ->param('databaseId', '', new UID(), 'Database ID.') @@ -928,7 +928,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/email' ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) ->label('sdk.method', 'createEmailAttribute') ->label('sdk.description', '/docs/references/databases/create-email-attribute.md') - ->label('sdk.response.code', Response::STATUS_CODE_CREATED) + ->label('sdk.response.code', Response::STATUS_CODE_ACCEPTED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_ATTRIBUTE_EMAIL) ->param('databaseId', '', new UID(), 'Database ID.') @@ -968,7 +968,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/enum') ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) ->label('sdk.method', 'createEnumAttribute') ->label('sdk.description', '/docs/references/databases/create-attribute-enum.md') - ->label('sdk.response.code', Response::STATUS_CODE_CREATED) + ->label('sdk.response.code', Response::STATUS_CODE_ACCEPTED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_ATTRIBUTE_ENUM) ->param('databaseId', '', new UID(), 'Database ID.') @@ -1024,7 +1024,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/ip') ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) ->label('sdk.method', 'createIpAttribute') ->label('sdk.description', '/docs/references/databases/create-ip-attribute.md') - ->label('sdk.response.code', Response::STATUS_CODE_CREATED) + ->label('sdk.response.code', Response::STATUS_CODE_ACCEPTED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_ATTRIBUTE_IP) ->param('databaseId', '', new UID(), 'Database ID.') @@ -1064,7 +1064,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/url') ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) ->label('sdk.method', 'createUrlAttribute') ->label('sdk.description', '/docs/references/databases/create-url-attribute.md') - ->label('sdk.response.code', Response::STATUS_CODE_CREATED) + ->label('sdk.response.code', Response::STATUS_CODE_ACCEPTED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_ATTRIBUTE_URL) ->param('databaseId', '', new UID(), 'Database ID.') @@ -1104,7 +1104,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/intege ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) ->label('sdk.method', 'createIntegerAttribute') ->label('sdk.description', '/docs/references/databases/create-integer-attribute.md') - ->label('sdk.response.code', Response::STATUS_CODE_CREATED) + ->label('sdk.response.code', Response::STATUS_CODE_ACCEPTED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_ATTRIBUTE_INTEGER) ->param('databaseId', '', new UID(), 'Database ID.') @@ -1173,7 +1173,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/float' ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) ->label('sdk.method', 'createFloatAttribute') ->label('sdk.description', '/docs/references/databases/create-float-attribute.md') - ->label('sdk.response.code', Response::STATUS_CODE_CREATED) + ->label('sdk.response.code', Response::STATUS_CODE_ACCEPTED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_ATTRIBUTE_FLOAT) ->param('databaseId', '', new UID(), 'Database ID.') @@ -1245,7 +1245,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/boolea ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) ->label('sdk.method', 'createBooleanAttribute') ->label('sdk.description', '/docs/references/databases/create-boolean-attribute.md') - ->label('sdk.response.code', Response::STATUS_CODE_CREATED) + ->label('sdk.response.code', Response::STATUS_CODE_ACCEPTED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_ATTRIBUTE_BOOLEAN) ->param('databaseId', '', new UID(), 'Database ID.') @@ -1491,7 +1491,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') ->label('sdk.namespace', 'databases') ->label('sdk.method', 'createIndex') ->label('sdk.description', '/docs/references/databases/create-index.md') - ->label('sdk.response.code', Response::STATUS_CODE_CREATED) + ->label('sdk.response.code', Response::STATUS_CODE_ACCEPTED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_INDEX) ->param('databaseId', '', new UID(), 'Database ID.') diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 0137ab92a8..7c6f953f56 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -905,7 +905,7 @@ App::post('/v1/functions/:functionId/executions') $event->trigger(); - $response->setStatusCode(Response::STATUS_CODE_CREATED); + $response->setStatusCode(Response::STATUS_CODE_ACCEPTED); return $response->dynamic($execution, Response::MODEL_EXECUTION); } From 35c546782ff6bc079dbd4be2c4cffd7749a75949 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 18 Jul 2022 10:43:51 +0100 Subject: [PATCH 02/10] Change more status codes to 202 --- app/controllers/api/databases.php | 2 +- app/controllers/api/functions.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 3adddcfc41..2180927fa7 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1633,7 +1633,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') ->setPayload($index->getArrayCopy()) ; - $response->setStatusCode(Response::STATUS_CODE_CREATED); + $response->setStatusCode(Response::STATUS_CODE_ACCEPTED); $response->dynamic($index, Response::MODEL_INDEX); }); diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index c38d131aad..ac49636407 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -453,7 +453,7 @@ App::post('/v1/functions/:functionId/deployments') ->label('sdk.description', '/docs/references/functions/create-deployment.md') ->label('sdk.packaging', true) ->label('sdk.request.type', 'multipart/form-data') - ->label('sdk.response.code', Response::STATUS_CODE_CREATED) + ->label('sdk.response.code', Response::STATUS_CODE_ACCEPTED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_DEPLOYMENT) ->param('functionId', '', new UID(), 'Function ID.') @@ -622,7 +622,7 @@ App::post('/v1/functions/:functionId/deployments') ->setParam('functionId', $function->getId()) ->setParam('deploymentId', $deployment->getId()); - $response->setStatusCode(Response::STATUS_CODE_CREATED); + $response->setStatusCode(Response::STATUS_CODE_ACCEPTED); $response->dynamic($deployment, Response::MODEL_DEPLOYMENT); }); From 74a53af3161488f8a737a152193b7a5efad68b62 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 18 Jul 2022 14:22:23 +0100 Subject: [PATCH 03/10] Fix Tests --- app/controllers/api/databases.php | 8 +++ .../e2e/Services/Databases/DatabasesBase.php | 56 +++++++++---------- .../Databases/DatabasesCustomClientTest.php | 2 +- .../Databases/DatabasesCustomServerTest.php | 22 ++++---- .../DatabasesPermissionsMemberTest.php | 4 +- .../Realtime/RealtimeConsoleClientTest.php | 2 +- .../Realtime/RealtimeCustomClientTest.php | 4 +- tests/e2e/Services/Webhooks/WebhooksBase.php | 6 +- 8 files changed, 56 insertions(+), 48 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 2180927fa7..d03c52a152 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -915,6 +915,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string 'array' => $array, ]), $response, $dbForProject, $database, $audits, $events, $usage); + $response->setStatusCode(Response::STATUS_CODE_ACCEPTED); $response->dynamic($attribute, Response::MODEL_ATTRIBUTE_STRING); }); @@ -955,6 +956,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/email' 'format' => APP_DATABASE_ATTRIBUTE_EMAIL, ]), $response, $dbForProject, $database, $audits, $events, $usage); + $response->setStatusCode(Response::STATUS_CODE_ACCEPTED); $response->dynamic($attribute, Response::MODEL_ATTRIBUTE_EMAIL); }); @@ -1011,6 +1013,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/enum') 'formatOptions' => ['elements' => $elements], ]), $response, $dbForProject, $database, $audits, $events, $usage); + $response->setStatusCode(Response::STATUS_CODE_ACCEPTED); $response->dynamic($attribute, Response::MODEL_ATTRIBUTE_ENUM); }); @@ -1051,6 +1054,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/ip') 'format' => APP_DATABASE_ATTRIBUTE_IP, ]), $response, $dbForProject, $database, $audits, $events, $usage); + $response->setStatusCode(Response::STATUS_CODE_ACCEPTED); $response->dynamic($attribute, Response::MODEL_ATTRIBUTE_IP); }); @@ -1091,6 +1095,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/url') 'format' => APP_DATABASE_ATTRIBUTE_URL, ]), $response, $dbForProject, $database, $audits, $events, $usage); + $response->setStatusCode(Response::STATUS_CODE_ACCEPTED); $response->dynamic($attribute, Response::MODEL_ATTRIBUTE_URL); }); @@ -1160,6 +1165,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/intege $attribute->setAttribute('max', \intval($formatOptions['max'])); } + $response->setStatusCode(Response::STATUS_CODE_ACCEPTED); $response->dynamic($attribute, Response::MODEL_ATTRIBUTE_INTEGER); }); @@ -1232,6 +1238,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/float' $attribute->setAttribute('max', \floatval($formatOptions['max'])); } + $response->setStatusCode(Response::STATUS_CODE_ACCEPTED); $response->dynamic($attribute, Response::MODEL_ATTRIBUTE_FLOAT); }); @@ -1271,6 +1278,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/boolea 'array' => $array, ]), $response, $dbForProject, $database, $audits, $events, $usage); + $response->setStatusCode(Response::STATUS_CODE_ACCEPTED); $response->dynamic($attribute, Response::MODEL_ATTRIBUTE_BOOLEAN); }); diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 34a4160fde..c86f7d62e0 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -165,23 +165,23 @@ trait DatabasesBase 'array' => true, ]); - $this->assertEquals($title['headers']['status-code'], 201); + $this->assertEquals($title['headers']['status-code'], 202); $this->assertEquals($title['body']['key'], 'title'); $this->assertEquals($title['body']['type'], 'string'); $this->assertEquals($title['body']['size'], 256); $this->assertEquals($title['body']['required'], true); - $this->assertEquals($releaseYear['headers']['status-code'], 201); + $this->assertEquals($releaseYear['headers']['status-code'], 202); $this->assertEquals($releaseYear['body']['key'], 'releaseYear'); $this->assertEquals($releaseYear['body']['type'], 'integer'); $this->assertEquals($releaseYear['body']['required'], true); - $this->assertEquals($duration['headers']['status-code'], 201); + $this->assertEquals($duration['headers']['status-code'], 202); $this->assertEquals($duration['body']['key'], 'duration'); $this->assertEquals($duration['body']['type'], 'integer'); $this->assertEquals($duration['body']['required'], false); - $this->assertEquals($actors['headers']['status-code'], 201); + $this->assertEquals($actors['headers']['status-code'], 202); $this->assertEquals($actors['body']['key'], 'actors'); $this->assertEquals($actors['body']['type'], 'string'); $this->assertEquals($actors['body']['size'], 256); @@ -318,7 +318,7 @@ trait DatabasesBase 'default' => true, ]); - $this->assertEquals(201, $string['headers']['status-code']); + $this->assertEquals(202, $string['headers']['status-code']); $this->assertEquals('string', $string['body']['key']); $this->assertEquals('string', $string['body']['type']); $this->assertEquals(false, $string['body']['required']); @@ -326,7 +326,7 @@ trait DatabasesBase $this->assertEquals(16, $string['body']['size']); $this->assertEquals('default', $string['body']['default']); - $this->assertEquals(201, $email['headers']['status-code']); + $this->assertEquals(202, $email['headers']['status-code']); $this->assertEquals('email', $email['body']['key']); $this->assertEquals('string', $email['body']['type']); $this->assertEquals(false, $email['body']['required']); @@ -334,7 +334,7 @@ trait DatabasesBase $this->assertEquals('email', $email['body']['format']); $this->assertEquals('default@example.com', $email['body']['default']); - $this->assertEquals(201, $enum['headers']['status-code']); + $this->assertEquals(202, $enum['headers']['status-code']); $this->assertEquals('enum', $enum['body']['key']); $this->assertEquals('string', $enum['body']['type']); $this->assertEquals(false, $enum['body']['required']); @@ -344,7 +344,7 @@ trait DatabasesBase $this->assertIsArray($enum['body']['elements']); $this->assertEquals(['yes', 'no', 'maybe'], $enum['body']['elements']); - $this->assertEquals(201, $ip['headers']['status-code']); + $this->assertEquals(202, $ip['headers']['status-code']); $this->assertEquals('ip', $ip['body']['key']); $this->assertEquals('string', $ip['body']['type']); $this->assertEquals(false, $ip['body']['required']); @@ -352,7 +352,7 @@ trait DatabasesBase $this->assertEquals('ip', $ip['body']['format']); $this->assertEquals('192.0.2.0', $ip['body']['default']); - $this->assertEquals(201, $url['headers']['status-code']); + $this->assertEquals(202, $url['headers']['status-code']); $this->assertEquals('url', $url['body']['key']); $this->assertEquals('string', $url['body']['type']); $this->assertEquals(false, $url['body']['required']); @@ -360,7 +360,7 @@ trait DatabasesBase $this->assertEquals('url', $url['body']['format']); $this->assertEquals('http://example.com', $url['body']['default']); - $this->assertEquals(201, $integer['headers']['status-code']); + $this->assertEquals(202, $integer['headers']['status-code']); $this->assertEquals('integer', $integer['body']['key']); $this->assertEquals('integer', $integer['body']['type']); $this->assertEquals(false, $integer['body']['required']); @@ -369,7 +369,7 @@ trait DatabasesBase $this->assertEquals(5, $integer['body']['max']); $this->assertEquals(3, $integer['body']['default']); - $this->assertEquals(201, $float['headers']['status-code']); + $this->assertEquals(202, $float['headers']['status-code']); $this->assertEquals('float', $float['body']['key']); $this->assertEquals('double', $float['body']['type']); $this->assertEquals(false, $float['body']['required']); @@ -378,7 +378,7 @@ trait DatabasesBase $this->assertEquals(5.5, $float['body']['max']); $this->assertEquals(3.5, $float['body']['default']); - $this->assertEquals(201, $boolean['headers']['status-code']); + $this->assertEquals(202, $boolean['headers']['status-code']); $this->assertEquals('boolean', $boolean['body']['key']); $this->assertEquals('boolean', $boolean['body']['type']); $this->assertEquals(false, $boolean['body']['required']); @@ -705,7 +705,7 @@ trait DatabasesBase 'attributes' => ['title'], ]); - $this->assertEquals(201, $titleIndex['headers']['status-code']); + $this->assertEquals(202, $titleIndex['headers']['status-code']); $this->assertEquals('titleIndex', $titleIndex['body']['key']); $this->assertEquals('fulltext', $titleIndex['body']['type']); $this->assertCount(1, $titleIndex['body']['attributes']); @@ -721,7 +721,7 @@ trait DatabasesBase 'attributes' => ['releaseYear'], ]); - $this->assertEquals(201, $releaseYearIndex['headers']['status-code']); + $this->assertEquals(202, $releaseYearIndex['headers']['status-code']); $this->assertEquals('releaseYear', $releaseYearIndex['body']['key']); $this->assertEquals('key', $releaseYearIndex['body']['type']); $this->assertCount(1, $releaseYearIndex['body']['attributes']); @@ -737,7 +737,7 @@ trait DatabasesBase 'attributes' => ['releaseYear', '$createdAt', '$updatedAt'], ]); - $this->assertEquals(201, $releaseWithDate['headers']['status-code']); + $this->assertEquals(202, $releaseWithDate['headers']['status-code']); $this->assertEquals('releaseYearDated', $releaseWithDate['body']['key']); $this->assertEquals('key', $releaseWithDate['body']['type']); $this->assertCount(3, $releaseWithDate['body']['attributes']); @@ -1689,15 +1689,15 @@ trait DatabasesBase 'default' => 'NORTH' ]); - $this->assertEquals(201, $email['headers']['status-code']); - $this->assertEquals(201, $ip['headers']['status-code']); - $this->assertEquals(201, $url['headers']['status-code']); - $this->assertEquals(201, $range['headers']['status-code']); - $this->assertEquals(201, $floatRange['headers']['status-code']); - $this->assertEquals(201, $probability['headers']['status-code']); - $this->assertEquals(201, $upperBound['headers']['status-code']); - $this->assertEquals(201, $lowerBound['headers']['status-code']); - $this->assertEquals(201, $enum['headers']['status-code']); + $this->assertEquals(202, $email['headers']['status-code']); + $this->assertEquals(202, $ip['headers']['status-code']); + $this->assertEquals(202, $url['headers']['status-code']); + $this->assertEquals(202, $range['headers']['status-code']); + $this->assertEquals(202, $floatRange['headers']['status-code']); + $this->assertEquals(202, $probability['headers']['status-code']); + $this->assertEquals(202, $upperBound['headers']['status-code']); + $this->assertEquals(202, $lowerBound['headers']['status-code']); + $this->assertEquals(202, $enum['headers']['status-code']); $this->assertEquals(400, $invalidRange['headers']['status-code']); $this->assertEquals(400, $defaultArray['headers']['status-code']); $this->assertEquals(400, $defaultRequired['headers']['status-code']); @@ -2144,7 +2144,7 @@ trait DatabasesBase 'required' => true, ]); - $this->assertEquals(201, $attribute['headers']['status-code'], 201); + $this->assertEquals(202, $attribute['headers']['status-code'], 202); $this->assertEquals('attribute', $attribute['body']['key']); // wait for db to add attribute @@ -2160,7 +2160,7 @@ trait DatabasesBase 'attributes' => [$attribute['body']['key']], ]); - $this->assertEquals(201, $index['headers']['status-code']); + $this->assertEquals(202, $index['headers']['status-code']); $this->assertEquals('key_attribute', $index['body']['key']); // wait for db to add attribute @@ -2292,7 +2292,7 @@ trait DatabasesBase 'attributes' => ['title'], ]); - $this->assertEquals($uniqueIndex['headers']['status-code'], 201); + $this->assertEquals($uniqueIndex['headers']['status-code'], 202); sleep(2); @@ -2464,7 +2464,7 @@ trait DatabasesBase 'required' => true, ]); - $this->assertEquals($title['headers']['status-code'], 201); + $this->assertEquals($title['headers']['status-code'], 202); // wait for database worker to create attributes sleep(2); diff --git a/tests/e2e/Services/Databases/DatabasesCustomClientTest.php b/tests/e2e/Services/Databases/DatabasesCustomClientTest.php index 93316cb39a..f37c21cbf2 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomClientTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomClientTest.php @@ -63,7 +63,7 @@ class DatabasesCustomClientTest extends Scope 'size' => 255, 'required' => true, ]); - $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals(202, $response['headers']['status-code']); // Wait for database worker to finish creating attributes sleep(2); diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index cc75a13a80..9f4c649fdf 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -618,8 +618,8 @@ class DatabasesCustomServerTest extends Scope 'required' => true, ]); - $this->assertEquals(201, $attribute1['headers']['status-code']); - $this->assertEquals(201, $attribute2['headers']['status-code']); + $this->assertEquals(202, $attribute1['headers']['status-code']); + $this->assertEquals(202, $attribute2['headers']['status-code']); $this->assertEquals('attribute1', $attribute1['body']['key']); $this->assertEquals('attribute2', $attribute2['body']['key']); @@ -646,8 +646,8 @@ class DatabasesCustomServerTest extends Scope 'attributes' => ['attribute2'], ]); - $this->assertEquals(201, $index1['headers']['status-code']); - $this->assertEquals(201, $index2['headers']['status-code']); + $this->assertEquals(202, $index1['headers']['status-code']); + $this->assertEquals(202, $index2['headers']['status-code']); $this->assertEquals('index1', $index1['body']['key']); $this->assertEquals('index2', $index2['body']['key']); @@ -742,8 +742,8 @@ class DatabasesCustomServerTest extends Scope 'required' => true, ]); - $this->assertEquals(201, $attribute1['headers']['status-code']); - $this->assertEquals(201, $attribute2['headers']['status-code']); + $this->assertEquals(202, $attribute1['headers']['status-code']); + $this->assertEquals(202, $attribute2['headers']['status-code']); $this->assertEquals('attribute1', $attribute1['body']['key']); $this->assertEquals('attribute2', $attribute2['body']['key']); @@ -770,8 +770,8 @@ class DatabasesCustomServerTest extends Scope 'attributes' => ['attribute2'], ]); - $this->assertEquals(201, $index1['headers']['status-code']); - $this->assertEquals(201, $index2['headers']['status-code']); + $this->assertEquals(202, $index1['headers']['status-code']); + $this->assertEquals(202, $index2['headers']['status-code']); $this->assertEquals('index1', $index1['body']['key']); $this->assertEquals('index2', $index2['body']['key']); @@ -980,7 +980,7 @@ class DatabasesCustomServerTest extends Scope 'required' => true, ]); - $this->assertEquals($attribute['headers']['status-code'], 201); + $this->assertEquals($attribute['headers']['status-code'], 202); } sleep(5); @@ -1043,7 +1043,7 @@ class DatabasesCustomServerTest extends Scope 'required' => true, ]); - $this->assertEquals($attribute['headers']['status-code'], 201); + $this->assertEquals($attribute['headers']['status-code'], 202); } sleep(20); @@ -1080,7 +1080,7 @@ class DatabasesCustomServerTest extends Scope 'attributes' => ["attribute{$i}"], ]); - $this->assertEquals(201, $index['headers']['status-code']); + $this->assertEquals(202, $index['headers']['status-code']); $this->assertEquals("key_attribute{$i}", $index['body']['key']); } diff --git a/tests/e2e/Services/Databases/DatabasesPermissionsMemberTest.php b/tests/e2e/Services/Databases/DatabasesPermissionsMemberTest.php index 0c3f3a08a3..c629ae3f66 100644 --- a/tests/e2e/Services/Databases/DatabasesPermissionsMemberTest.php +++ b/tests/e2e/Services/Databases/DatabasesPermissionsMemberTest.php @@ -77,7 +77,7 @@ class DatabasesPermissionsMemberTest extends Scope 'size' => 256, 'required' => true, ]); - $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals(202, $response['headers']['status-code']); $private = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', $this->getServerHeader(), [ 'collectionId' => 'unique()', @@ -95,7 +95,7 @@ class DatabasesPermissionsMemberTest extends Scope 'size' => 256, 'required' => true, ]); - $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals(202, $response['headers']['status-code']); sleep(2); diff --git a/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php b/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php index 8217f46539..1112a230a1 100644 --- a/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php @@ -177,7 +177,7 @@ class RealtimeConsoleClientTest extends Scope $attributeKey = $name['body']['key']; - $this->assertEquals($name['headers']['status-code'], 201); + $this->assertEquals($name['headers']['status-code'], 202); $this->assertEquals($name['body']['key'], 'name'); $this->assertEquals($name['body']['type'], 'string'); $this->assertEquals($name['body']['size'], 256); diff --git a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php index d1091e5354..5753f007f9 100644 --- a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php @@ -661,7 +661,7 @@ class RealtimeCustomClientTest extends Scope 'required' => true, ]); - $this->assertEquals($name['headers']['status-code'], 201); + $this->assertEquals($name['headers']['status-code'], 202); $this->assertEquals($name['body']['key'], 'name'); $this->assertEquals($name['body']['type'], 'string'); $this->assertEquals($name['body']['size'], 256); @@ -871,7 +871,7 @@ class RealtimeCustomClientTest extends Scope 'required' => true, ]); - $this->assertEquals($name['headers']['status-code'], 201); + $this->assertEquals($name['headers']['status-code'], 202); $this->assertEquals($name['body']['key'], 'name'); $this->assertEquals($name['body']['type'], 'string'); $this->assertEquals($name['body']['size'], 256); diff --git a/tests/e2e/Services/Webhooks/WebhooksBase.php b/tests/e2e/Services/Webhooks/WebhooksBase.php index c1647b6e87..1a3f511ea1 100644 --- a/tests/e2e/Services/Webhooks/WebhooksBase.php +++ b/tests/e2e/Services/Webhooks/WebhooksBase.php @@ -115,11 +115,11 @@ trait WebhooksBase $attributeId = $extra['body']['key']; - $this->assertEquals($firstName['headers']['status-code'], 201); + $this->assertEquals($firstName['headers']['status-code'], 202); $this->assertEquals($firstName['body']['key'], 'firstName'); - $this->assertEquals($lastName['headers']['status-code'], 201); + $this->assertEquals($lastName['headers']['status-code'], 202); $this->assertEquals($lastName['body']['key'], 'lastName'); - $this->assertEquals($extra['headers']['status-code'], 201); + $this->assertEquals($extra['headers']['status-code'], 202); $this->assertEquals($extra['body']['key'], 'extra'); // wait for database worker to kick in From 4d729b9d39d99bdc5ac3c2fea72018ea04b231ba Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 20 Jul 2022 13:01:18 +0100 Subject: [PATCH 04/10] Update Tests for Functions --- .../Functions/FunctionsCustomClientTest.php | 12 +++---- .../Functions/FunctionsCustomServerTest.php | 34 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index b2fb7d7d37..7b535f64dc 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -89,7 +89,7 @@ class FunctionsCustomClientTest extends Scope $deploymentId = $deployment['body']['$id'] ?? ''; - $this->assertEquals(201, $deployment['headers']['status-code']); + $this->assertEquals(202, $deployment['headers']['status-code']); // Wait for deployment to be built. sleep(10); @@ -118,7 +118,7 @@ class FunctionsCustomClientTest extends Scope 'async' => true, ]); - $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertEquals(202, $execution['headers']['status-code']); // Cleanup : Delete function $response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $function['body']['$id'], [ @@ -179,7 +179,7 @@ class FunctionsCustomClientTest extends Scope // Wait for deployment to be built. sleep(5); - $this->assertEquals(201, $deployment['headers']['status-code']); + $this->assertEquals(202, $deployment['headers']['status-code']); $function = $this->client->call(Client::METHOD_PATCH, '/functions/' . $functionId . '/deployments/' . $deploymentId, [ 'content-type' => 'application/json', @@ -196,7 +196,7 @@ class FunctionsCustomClientTest extends Scope 'data' => 'foobar', ]); - $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertEquals(202, $execution['headers']['status-code']); $executionId = $execution['body']['$id'] ?? ''; @@ -271,7 +271,7 @@ class FunctionsCustomClientTest extends Scope 'data' => 'foobar', ]); - $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertEquals(202, $execution['headers']['status-code']); sleep(10); @@ -361,7 +361,7 @@ class FunctionsCustomClientTest extends Scope $deploymentId = $deployment['body']['$id'] ?? ''; - $this->assertEquals(201, $deployment['headers']['status-code']); + $this->assertEquals(202, $deployment['headers']['status-code']); // Wait for deployment to be built. sleep(10); diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 444611e07a..1d0a42b536 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -292,7 +292,7 @@ class FunctionsCustomServerTest extends Scope $deploymentId = $deployment['body']['$id'] ?? ''; - $this->assertEquals(201, $deployment['headers']['status-code']); + $this->assertEquals(202, $deployment['headers']['status-code']); $this->assertNotEmpty($deployment['body']['$id']); $this->assertIsInt($deployment['body']['$createdAt']); $this->assertEquals('index.php', $deployment['body']['entrypoint']); @@ -341,7 +341,7 @@ class FunctionsCustomServerTest extends Scope } @fclose($handle); - $this->assertEquals(201, $largeTag['headers']['status-code']); + $this->assertEquals(202, $largeTag['headers']['status-code']); $this->assertNotEmpty($largeTag['body']['$id']); $this->assertIsInt($largeTag['body']['$createdAt']); $this->assertEquals('index.php', $largeTag['body']['entrypoint']); @@ -484,7 +484,7 @@ class FunctionsCustomServerTest extends Scope $executionId = $execution['body']['$id'] ?? ''; - $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertEquals(202, $execution['headers']['status-code']); $this->assertNotEmpty($execution['body']['$id']); $this->assertNotEmpty($execution['body']['functionId']); $this->assertIsInt($execution['body']['$createdAt']); @@ -733,7 +733,7 @@ class FunctionsCustomServerTest extends Scope 'activate' => true, ]); - $this->assertEquals(201, $deployment['headers']['status-code']); + $this->assertEquals(202, $deployment['headers']['status-code']); // Allow build step to run sleep(20); @@ -747,7 +747,7 @@ class FunctionsCustomServerTest extends Scope $executionId = $execution['body']['$id'] ?? ''; - $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertEquals(202, $execution['headers']['status-code']); sleep(10); @@ -818,7 +818,7 @@ class FunctionsCustomServerTest extends Scope ]); $deploymentId = $deployment['body']['$id'] ?? ''; - $this->assertEquals(201, $deployment['headers']['status-code']); + $this->assertEquals(202, $deployment['headers']['status-code']); // Allow build step to run sleep(10); @@ -839,7 +839,7 @@ class FunctionsCustomServerTest extends Scope $executionId = $execution['body']['$id'] ?? ''; - $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertEquals(202, $execution['headers']['status-code']); $executionId = $execution['body']['$id'] ?? ''; @@ -930,7 +930,7 @@ class FunctionsCustomServerTest extends Scope ]); $deploymentId = $deployment['body']['$id'] ?? ''; - $this->assertEquals(201, $deployment['headers']['status-code']); + $this->assertEquals(202, $deployment['headers']['status-code']); // Allow build step to run sleep(10); @@ -944,7 +944,7 @@ class FunctionsCustomServerTest extends Scope $executionId = $execution['body']['$id'] ?? ''; - $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertEquals(202, $execution['headers']['status-code']); $executionId = $execution['body']['$id'] ?? ''; @@ -1035,7 +1035,7 @@ class FunctionsCustomServerTest extends Scope ]); $deploymentId = $deployment['body']['$id'] ?? ''; - $this->assertEquals(201, $deployment['headers']['status-code']); + $this->assertEquals(202, $deployment['headers']['status-code']); // Allow build step to run sleep(30); @@ -1049,7 +1049,7 @@ class FunctionsCustomServerTest extends Scope $executionId = $execution['body']['$id'] ?? ''; - $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertEquals(202, $execution['headers']['status-code']); $executionId = $execution['body']['$id'] ?? ''; @@ -1140,7 +1140,7 @@ class FunctionsCustomServerTest extends Scope ]); $deploymentId = $deployment['body']['$id'] ?? ''; - $this->assertEquals(201, $deployment['headers']['status-code']); + $this->assertEquals(202, $deployment['headers']['status-code']); // Allow build step to run sleep(40); @@ -1154,7 +1154,7 @@ class FunctionsCustomServerTest extends Scope $executionId = $execution['body']['$id'] ?? ''; - $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertEquals(202, $execution['headers']['status-code']); $executionId = $execution['body']['$id'] ?? ''; @@ -1245,7 +1245,7 @@ class FunctionsCustomServerTest extends Scope ]); $deploymentId = $deployment['body']['$id'] ?? ''; - $this->assertEquals(201, $deployment['headers']['status-code']); + $this->assertEquals(202, $deployment['headers']['status-code']); // Allow build step to run sleep(30); @@ -1259,7 +1259,7 @@ class FunctionsCustomServerTest extends Scope $executionId = $execution['body']['$id'] ?? ''; - $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertEquals(202, $execution['headers']['status-code']); $executionId = $execution['body']['$id'] ?? ''; @@ -1350,7 +1350,7 @@ class FunctionsCustomServerTest extends Scope // ]); // $deploymentId = $deployment['body']['$id'] ?? ''; - // $this->assertEquals(201, $deployment['headers']['status-code']); + // $this->assertEquals(202, $deployment['headers']['status-code']); // // Allow (slow) build step to run // sleep(300); @@ -1364,7 +1364,7 @@ class FunctionsCustomServerTest extends Scope // $executionId = $execution['body']['$id'] ?? ''; - // $this->assertEquals(201, $execution['headers']['status-code']); + // $this->assertEquals(202, $execution['headers']['status-code']); // $executionId = $execution['body']['$id'] ?? ''; From ac184a6fe3f8d7e17a6da2f472ffc578eb03d8e9 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 20 Jul 2022 13:43:18 +0100 Subject: [PATCH 05/10] Fix realtime and webhook tests --- tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php | 2 +- tests/e2e/Services/Realtime/RealtimeCustomClientTest.php | 2 +- tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php b/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php index 1112a230a1..63eda8d0d4 100644 --- a/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php @@ -266,7 +266,7 @@ class RealtimeConsoleClientTest extends Scope ], ]); - $this->assertEquals($index['headers']['status-code'], 201); + $this->assertEquals($index['headers']['status-code'], 202); $indexKey = $index['body']['key']; $response = json_decode($client->receive(), true); diff --git a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php index 5753f007f9..8d63a6ade0 100644 --- a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php @@ -1222,7 +1222,7 @@ class RealtimeCustomClientTest extends Scope $deploymentId = $deployment['body']['$id'] ?? ''; - $this->assertEquals($deployment['headers']['status-code'], 201); + $this->assertEquals($deployment['headers']['status-code'], 202); $this->assertNotEmpty($deployment['body']['$id']); // Wait for deployment to be built. diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php index c60e57f6af..fd34c8bcb9 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php @@ -82,7 +82,7 @@ class WebhooksCustomServerTest extends Scope ]); $indexKey = $index['body']['key']; - $this->assertEquals($index['headers']['status-code'], 201); + $this->assertEquals($index['headers']['status-code'], 202); $this->assertEquals($index['body']['key'], 'fullname'); // wait for database worker to create index @@ -505,7 +505,7 @@ class WebhooksCustomServerTest extends Scope $id = $data['functionId'] ?? ''; $deploymentId = $deployment['body']['$id'] ?? ''; - $this->assertEquals($deployment['headers']['status-code'], 201); + $this->assertEquals($deployment['headers']['status-code'], 202); $this->assertNotEmpty($deployment['body']['$id']); $webhook = $this->getLastRequest(); @@ -595,7 +595,7 @@ class WebhooksCustomServerTest extends Scope $executionId = $execution['body']['$id'] ?? ''; - $this->assertEquals($execution['headers']['status-code'], 201); + $this->assertEquals($execution['headers']['status-code'], 202); $this->assertNotEmpty($execution['body']['$id']); $webhook = $this->getLastRequest(); From 3623d41fd3187356d8c3cd0e4030d3a062caae25 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 20 Jul 2022 14:25:05 +0100 Subject: [PATCH 06/10] Update RealtimeCustomClientTest.php --- tests/e2e/Services/Realtime/RealtimeCustomClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php index 8d63a6ade0..d40c81801b 100644 --- a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php @@ -1242,7 +1242,7 @@ class RealtimeCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'] ], $this->getHeaders()), []); - $this->assertEquals($execution['headers']['status-code'], 201); + $this->assertEquals($execution['headers']['status-code'], 202); $this->assertNotEmpty($execution['body']['$id']); $response = json_decode($client->receive(), true); From 2215e4db498fcc9e04ceb1404eec4e826b04e763 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Tue, 9 Aug 2022 17:18:43 +0100 Subject: [PATCH 07/10] Add Parent Database ID to collection and documents --- app/views/console/databases/collection.phtml | 5 +++++ app/views/console/databases/document.phtml | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/app/views/console/databases/collection.phtml b/app/views/console/databases/collection.phtml index 2428e30661..00fa638882 100644 --- a/app/views/console/databases/collection.phtml +++ b/app/views/console/databases/collection.phtml @@ -583,6 +583,11 @@ $logs = $this->getParam('logs', null); + +
+ +
+
  • diff --git a/app/views/console/users/index.phtml b/app/views/console/users/index.phtml index d21ac95af7..7648ac0095 100644 --- a/app/views/console/users/index.phtml +++ b/app/views/console/users/index.phtml @@ -11,7 +11,7 @@ $smtpEnabled = $this->getParam('smtpEnabled', false); Home
    - Users + Authentication From 47129afcfaa26fe012bd89066ee3c366666bceca Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 12 Aug 2022 03:00:29 +0100 Subject: [PATCH 10/10] Remove constants from response models --- src/Appwrite/Utopia/Response/Model/AttributeEmail.php | 4 ++-- src/Appwrite/Utopia/Response/Model/AttributeEnum.php | 4 ++-- src/Appwrite/Utopia/Response/Model/AttributeIP.php | 4 ++-- src/Appwrite/Utopia/Response/Model/AttributeURL.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Model/AttributeEmail.php b/src/Appwrite/Utopia/Response/Model/AttributeEmail.php index dd9a514996..64fd5b42fe 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeEmail.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeEmail.php @@ -27,8 +27,8 @@ class AttributeEmail extends Attribute ->addRule('format', [ 'type' => self::TYPE_STRING, 'description' => 'String format.', - 'default' => APP_DATABASE_ATTRIBUTE_EMAIL, - 'example' => APP_DATABASE_ATTRIBUTE_EMAIL, + 'default' => 'email', + 'example' => 'email', 'array' => false, 'require' => true, ]) diff --git a/src/Appwrite/Utopia/Response/Model/AttributeEnum.php b/src/Appwrite/Utopia/Response/Model/AttributeEnum.php index 2a10cf7fca..2c3875c005 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeEnum.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeEnum.php @@ -35,8 +35,8 @@ class AttributeEnum extends Attribute ->addRule('format', [ 'type' => self::TYPE_STRING, 'description' => 'String format.', - 'default' => APP_DATABASE_ATTRIBUTE_ENUM, - 'example' => APP_DATABASE_ATTRIBUTE_ENUM, + 'default' => 'enum', + 'example' => 'enum', 'array' => false, 'require' => true, ]) diff --git a/src/Appwrite/Utopia/Response/Model/AttributeIP.php b/src/Appwrite/Utopia/Response/Model/AttributeIP.php index 00d9ddcab2..6cd401fe35 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeIP.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeIP.php @@ -27,8 +27,8 @@ class AttributeIP extends Attribute ->addRule('format', [ 'type' => self::TYPE_STRING, 'description' => 'String format.', - 'default' => APP_DATABASE_ATTRIBUTE_IP, - 'example' => APP_DATABASE_ATTRIBUTE_IP, + 'default' => 'ip', + 'example' => 'ip', 'array' => false, 'require' => true, ]) diff --git a/src/Appwrite/Utopia/Response/Model/AttributeURL.php b/src/Appwrite/Utopia/Response/Model/AttributeURL.php index 4a468b6ee1..46641bc283 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeURL.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeURL.php @@ -27,8 +27,8 @@ class AttributeURL extends Attribute ->addRule('format', [ 'type' => self::TYPE_STRING, 'description' => 'String format.', - 'default' => APP_DATABASE_ATTRIBUTE_URL, - 'example' => APP_DATABASE_ATTRIBUTE_URL, + 'default' => 'url', + 'example' => 'url', 'array' => false, 'required' => true, ])