From 19928bd7dc4e4c57528a24571105fbc3b1674a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 25 Feb 2025 15:13:59 +0100 Subject: [PATCH] Add delete worker tests for rules --- tests/e2e/Services/Proxy/ProxyBase.php | 24 ++++++- .../Services/Proxy/ProxyCustomServerTest.php | 64 ++++++++++++++++++- 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/tests/e2e/Services/Proxy/ProxyBase.php b/tests/e2e/Services/Proxy/ProxyBase.php index 7cc1290eb3..3a701f8795 100644 --- a/tests/e2e/Services/Proxy/ProxyBase.php +++ b/tests/e2e/Services/Proxy/ProxyBase.php @@ -146,6 +146,26 @@ trait ProxyBase $this->assertEquals(204, $rule['headers']['status-code'], 'Failed to cleanup rule: ' . \json_encode($rule)); } + protected function cleanupSite(string $siteId): void + { + $site = $this->client->call(Client::METHOD_DELETE, '/sites/' . $siteId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $this->assertEquals(204, $site['headers']['status-code'], 'Failed to cleanup site: ' . \json_encode($site)); + } + + protected function cleanupFunction(string $functionId): void + { + $function = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $this->assertEquals(204, $function['headers']['status-code'], 'Failed to cleanup function: ' . \json_encode($function)); + } + protected function setupSite(): mixed { // Site @@ -191,7 +211,7 @@ trait ProxyBase $this->assertEquals($deploymentId, $site['body']['deploymentId'], 'Deployment is not activated, deployment: ' . json_encode($site['body'], JSON_PRETTY_PRINT)); }, 100000, 500); - return $siteId; + return ['siteId' => $siteId, 'deploymentId' => $deploymentId]; } protected function setupFunction(): mixed @@ -236,7 +256,7 @@ trait ProxyBase $this->assertEquals($deploymentId, $function['body']['deployment'], 'Deployment is not activated, deployment: ' . json_encode($function['body'], JSON_PRETTY_PRINT)); }, 100000, 500); - return $functionId; + return ['functionId' => $functionId, 'deploymentId' => $deploymentId]; } private function packageSite(string $site): CURLFile diff --git a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php index c235dfbc27..9b3c2720d7 100644 --- a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php +++ b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php @@ -138,8 +138,12 @@ class ProxyCustomServerTest extends Scope $response = $proxyClient->call(Client::METHOD_GET, '/ping'); $this->assertEquals(404, $response['headers']['status-code']); - $functionId = $this->setupFunction(); + $setup = $this->setupFunction(); + $functionId = $setup['functionId']; + $deploymentId = $setup['deploymentId']; + $this->assertNotEmpty($functionId); + $this->assertNotEmpty($deploymentId); $ruleId = $this->setupFunctionRule($domain, $functionId); $this->assertNotEmpty($ruleId); @@ -149,6 +153,32 @@ class ProxyCustomServerTest extends Scope $this->assertEquals($functionId, $response['body']['APPWRITE_FUNCTION_ID']); $this->cleanupRule($ruleId); + + $this->cleanupFunction($functionId); + + $this->assertEventually(function () use ($functionId, $deploymentId) { + $rules = $this->listRules([ + 'queries' => [ + Query::limit(1)->toString(), + Query::equal('type', ['deployment'])->toString(), + Query::equal('automation', ['function=' . $functionId])->toString() + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(0, $rules['body']['total']); + $this->assertCount(0, $rules['body']['rules']); + + $rules = $this->listRules([ + 'queries' => [ + Query::limit(1)->toString(), + Query::equal('type', ['deployment'])->toString(), + Query::equal('value', [$deploymentId])->toString() + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(0, $rules['body']['total']); + $this->assertCount(0, $rules['body']['rules']); + }); } public function testCreateSiteRule(): void @@ -162,8 +192,12 @@ class ProxyCustomServerTest extends Scope $response = $proxyClient->call(Client::METHOD_GET, '/contact'); $this->assertEquals(404, $response['headers']['status-code']); - $siteId = $this->setupSite(); + $setup = $this->setupSite(); + $siteId = $setup['siteId']; + $deploymentId = $setup['deploymentId']; + $this->assertNotEmpty($siteId); + $this->assertNotEmpty($deploymentId); $ruleId = $this->setupSiteRule($domain, $siteId); $this->assertNotEmpty($ruleId); @@ -173,6 +207,32 @@ class ProxyCustomServerTest extends Scope $this->assertStringContainsString('Contact page', $response['body']); $this->cleanupRule($ruleId); + + $this->cleanupSite($siteId); + + $this->assertEventually(function () use ($siteId, $deploymentId) { + $rules = $this->listRules([ + 'queries' => [ + Query::limit(1)->toString(), + Query::equal('type', ['deployment'])->toString(), + Query::equal('automation', ['site=' . $siteId])->toString() + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(0, $rules['body']['total']); + $this->assertCount(0, $rules['body']['rules']); + + $rules = $this->listRules([ + 'queries' => [ + Query::limit(1)->toString(), + Query::equal('type', ['deployment'])->toString(), + Query::equal('value', [$deploymentId])->toString() + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(0, $rules['body']['total']); + $this->assertCount(0, $rules['body']['rules']); + }); } public function testCreatSiteBranchRule(): void