diff --git a/src/Appwrite/Utopia/Response/Model/Execution.php b/src/Appwrite/Utopia/Response/Model/Execution.php index d7d30fe549..944f475bd1 100644 --- a/src/Appwrite/Utopia/Response/Model/Execution.php +++ b/src/Appwrite/Utopia/Response/Model/Execution.php @@ -38,12 +38,19 @@ class Execution extends Model 'example' => [Role::any()->toString()], 'array' => true, ]) + // TODO: Sites listLogs will not have this, and will need siteId instead ->addRule('functionId', [ 'type' => self::TYPE_STRING, 'description' => 'Function ID.', 'default' => '', 'example' => '5e5ea6g16897e', ]) + ->addRule('deploymentId', [ + 'type' => self::TYPE_STRING, + 'description' => 'Function\'s deployment ID used to create the execution.', + 'default' => '', + 'example' => '5e5ea5c16897e', + ]) ->addRule('trigger', [ 'type' => self::TYPE_STRING, 'description' => 'The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`.', diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 6597f1af69..9d2e731d06 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -945,6 +945,29 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(1, $executions['body']['total']); $this->assertIsArray($executions['body']['executions']); $this->assertCount(1, $executions['body']['executions']); + $this->assertEquals($data['deploymentId'], $executions['body']['executions'][0]['deploymentId']); + + $executions = $this->listExecutions($data['functionId'], [ + 'queries' => [ + Query::equal('deploymentId', [$data['deploymentId']])->toString(), + ], + ]); + + $this->assertEquals(200, $executions['headers']['status-code']); + $this->assertEquals(1, $executions['body']['total']); + $this->assertIsArray($executions['body']['executions']); + $this->assertCount(1, $executions['body']['executions']); + + $executions = $this->listExecutions($data['functionId'], [ + 'queries' => [ + Query::equal('deploymentId', ['some-random-id'])->toString(), + ], + ]); + + $this->assertEquals(200, $executions['headers']['status-code']); + $this->assertEquals(0, $executions['body']['total']); + $this->assertIsArray($executions['body']['executions']); + $this->assertCount(0, $executions['body']['executions']); $executions = $this->listExecutions($data['functionId'], [ 'queries' => [ @@ -1034,8 +1057,9 @@ class FunctionsCustomServerTest extends Scope */ $execution = $this->getExecution($data['functionId'], $data['executionId']); - $this->assertEquals($execution['headers']['status-code'], 200); - $this->assertEquals($execution['body']['$id'], $data['executionId']); + $this->assertEquals(200, $execution['headers']['status-code']); + $this->assertEquals($data['executionId'], $execution['body']['$id']); + $this->assertEquals($data['deploymentId'], $execution['body']['deploymentId']); /** * Test for FAILURE diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index f76122c00a..0e792d6c36 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1887,6 +1887,7 @@ class SitesCustomServerTest extends Scope Query::limit(1)->toString(), ]); $this->assertEquals(200, $logs['headers']['status-code']); + $this->assertStringContainsString($deploymentId, $logs['body']['executions'][0]['deploymentId']); $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); $this->assertStringContainsString("/logs-inline", $logs['body']['executions'][0]['requestPath']); $this->assertStringContainsString("Log1", $logs['body']['executions'][0]['logs']); @@ -1896,6 +1897,24 @@ class SitesCustomServerTest extends Scope $log1Id = $logs['body']['executions'][0]['$id']; $this->assertNotEmpty($log1Id); + $logs = $this->listLogs($siteId, [ + Query::orderDesc('$createdAt')->toString(), + Query::limit(1)->toString(), + Query::equal('deploymentId', [$deploymentId])->toString() + ]); + $this->assertEquals(200, $logs['headers']['status-code']); + $this->assertGreaterThanOrEqual(1, $logs['body']['total']); + $this->assertCount(1, $logs['body']['executions']); + + $logs = $this->listLogs($siteId, [ + Query::orderDesc('$createdAt')->toString(), + Query::limit(1)->toString(), + Query::equal('deploymentId', ['some-random-id'])->toString() + ]); + $this->assertEquals(200, $logs['headers']['status-code']); + $this->assertEquals(0, $logs['body']['total']); + $this->assertCount(0, $logs['body']['executions']); + $response = $proxyClient->call(Client::METHOD_GET, '/logs-action'); $this->assertEquals(200, $response['headers']['status-code']); $this->assertStringContainsString("Action logs printed.", $response['body']); @@ -1905,6 +1924,7 @@ class SitesCustomServerTest extends Scope Query::limit(1)->toString(), ]); $this->assertEquals(200, $logs['headers']['status-code']); + $this->assertStringContainsString($deploymentId, $logs['body']['executions'][0]['deploymentId']); $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); $this->assertStringContainsString("/logs-action", $logs['body']['executions'][0]['requestPath']); $this->assertStringContainsString("Log1", $logs['body']['executions'][0]['logs']);