From 5ec548cc06725e651fcc6cdef79a58fcd4b80292 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Fri, 18 Nov 2022 14:13:33 +0100 Subject: [PATCH] Fix more failing tests --- .env | 2 +- app/controllers/api/account.php | 1 + src/Appwrite/Usage/Calculators/TimeSeries.php | 1 + tests/e2e/General/UsageTest.php | 24 +++++++++++++++---- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.env b/.env index 405d72cd5f..15a25aa933 100644 --- a/.env +++ b/.env @@ -63,7 +63,7 @@ _APP_MAINTENANCE_RETENTION_EXECUTION=1209600 _APP_MAINTENANCE_RETENTION_ABUSE=86400 _APP_MAINTENANCE_RETENTION_AUDIT=1209600 _APP_MAINTENANCE_RETENTION_SCHEDULES=86400 -_APP_USAGE_TIMESERIES_INTERVAL=15 +_APP_USAGE_TIMESERIES_INTERVAL=20 _APP_MAINTENANCE_RETENTION_USAGE_HOURLY=8640000 _APP_USAGE_STATS=enabled _APP_LOGGING_PROVIDER= diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 115948f710..d973ffd14c 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -279,6 +279,7 @@ App::get('/v1/account/sessions/oauth2/:provider') ->action(function (string $provider, string $success, string $failure, array $scopes, Request $request, Response $response, Document $project) use ($oauthDefaultSuccess, $oauthDefaultFailure) { $protocol = $request->getProtocol(); + $callback = $protocol . '://' . $request->getHostname() . '/v1/account/sessions/oauth2/callback/' . $provider . '/' . $project->getId(); $appId = $project->getAttribute('authProviders', [])[$provider . 'Appid'] ?? ''; $appSecret = $project->getAttribute('authProviders', [])[$provider . 'Secret'] ?? '{}'; diff --git a/src/Appwrite/Usage/Calculators/TimeSeries.php b/src/Appwrite/Usage/Calculators/TimeSeries.php index 2ef3d77cac..6f4fb94a7d 100644 --- a/src/Appwrite/Usage/Calculators/TimeSeries.php +++ b/src/Appwrite/Usage/Calculators/TimeSeries.php @@ -494,6 +494,7 @@ class TimeSeries extends Calculator if (empty($point['projectInternalId'] ?? null)) { continue; } + $this->createOrUpdateMetric( $point['projectInternalId'], $point['time'], diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 4d71edea5a..a38fa133cd 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -97,6 +97,8 @@ class UsageTest extends Scope 'origin' => 'http://localhost', 'x-appwrite-project' => 'console', 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => $projectId, + 'x-appwrite-mode' => 'admin', ]; $res = $this->client->call(Client::METHOD_GET, '/project/usage?range=30d', $headers); @@ -146,11 +148,20 @@ class UsageTest extends Scope for ($i = 0; $i < 10; $i++) { $name = uniqid() . ' bucket'; - $res = $this->client->call(Client::METHOD_POST, '/storage/buckets', $headers, [ + $res = $this->client->call(Client::METHOD_POST, '/storage/buckets', \array_merge($headers, [ + 'content-type' => 'application/json' + ]), [ 'bucketId' => 'unique()', 'name' => $name, - 'permission' => 'bucket' + 'fileSecurity' => false, + 'permissions' => [ + Permission::read(Role::any()), + Permission::create(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], ]); + \var_dump($res['body']); $this->assertEquals($name, $res['body']['name']); $this->assertNotEmpty($res['body']['$id']); $bucketId = $res['body']['$id']; @@ -263,9 +274,11 @@ class UsageTest extends Scope 'origin' => 'http://localhost', 'x-appwrite-project' => 'console', 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => $projectId, + 'x-appwrite-mode' => 'admin', ]; - $res = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/usage?range=30d', $headers); + $res = $this->client->call(Client::METHOD_GET, '/project/usage?range=30d', $headers); $res = $res['body']; $this->assertEquals(9, count($res)); @@ -503,8 +516,11 @@ class UsageTest extends Scope 'origin' => 'http://localhost', 'x-appwrite-project' => 'console', 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => $projectId, + 'x-appwrite-mode' => 'admin', ]; - $res = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/usage?range=30d', $headers); + + $res = $this->client->call(Client::METHOD_GET, '/project/usage?range=30d', $headers); $res = $res['body']; $this->assertEquals(9, count($res));