diff --git a/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php b/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php index b8b064f077..9dae8efdb4 100644 --- a/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php @@ -21,8 +21,8 @@ class FunctionsConsoleClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [Role::user($this->getUser()['$id'])->toString()], - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', 'events' => [ 'users.*.create', 'users.*.delete', @@ -39,8 +39,8 @@ class FunctionsConsoleClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test Failure', 'execute' => ['some-random-string'], - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', ]); $this->assertEquals(400, $function2['headers']['status-code']); @@ -453,7 +453,7 @@ class FunctionsConsoleClientTest extends Scope { $function = $this->createFunction([ 'functionId' => ID::unique(), - 'runtime' => 'node-18.0', + 'runtime' => 'node-22', 'name' => 'Variable E2E Test', 'entrypoint' => 'index.js', 'logging' => false, @@ -481,7 +481,7 @@ class FunctionsConsoleClientTest extends Scope $deploymentId = $this->setupDeployment($functionId, [ 'entrypoint' => 'index.js', - 'code' => $this->packageFunction('generic'), + 'code' => $this->packageFunction('basic'), 'activate' => true ]); @@ -502,7 +502,7 @@ class FunctionsConsoleClientTest extends Scope { $functionId = $this->setupFunction([ 'functionId' => ID::unique(), - 'runtime' => 'node-18.0', + 'runtime' => 'node-22', 'name' => 'Download Test', 'entrypoint' => 'index.js', 'logging' => false, @@ -511,7 +511,7 @@ class FunctionsConsoleClientTest extends Scope $deploymentId = $this->setupDeployment($functionId, [ 'entrypoint' => 'index.js', - 'code' => $this->packageFunction('generic'), + 'code' => $this->packageFunction('basic'), 'activate' => true ]); diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 6fae88fcd2..ccabc2a79e 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -81,7 +81,7 @@ class FunctionsCustomClientTest extends Scope */ $functionId = $this->setupFunction([ 'functionId' => ID::unique(), - 'name' => 'Test ', + 'name' => 'Test', 'execute' => [Role::any()->toString()], 'runtime' => 'node-22', 'entrypoint' => 'index.js', @@ -105,8 +105,8 @@ class FunctionsCustomClientTest extends Scope $this->assertEquals('Test', $output['APPWRITE_FUNCTION_NAME']); $this->assertEquals($deploymentId, $output['APPWRITE_FUNCTION_DEPLOYMENT']); $this->assertEquals('http', $output['APPWRITE_FUNCTION_TRIGGER']); - $this->assertEquals('PHP', $output['APPWRITE_FUNCTION_RUNTIME_NAME']); - $this->assertEquals('8.0', $output['APPWRITE_FUNCTION_RUNTIME_VERSION']); + $this->assertEquals('Node.js', $output['APPWRITE_FUNCTION_RUNTIME_NAME']); + $this->assertEquals('22', $output['APPWRITE_FUNCTION_RUNTIME_VERSION']); $this->assertEquals(APP_VERSION_STABLE, $output['APPWRITE_VERSION']); $this->assertEquals(System::getEnv('_APP_REGION', 'default'), $output['APPWRITE_REGION']); $this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT']); @@ -172,8 +172,8 @@ class FunctionsCustomClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [], - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', 'timeout' => 10, ]); @@ -210,11 +210,11 @@ class FunctionsCustomClientTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals(200, $execution['body']['responseStatusCode']); $this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']); - $this->assertEquals('Test', $output['APPWRITE_FUNCTION_NAME']); + $this->assertEquals('Test synchronous execution', $output['APPWRITE_FUNCTION_NAME']); $this->assertEquals($deploymentId, $output['APPWRITE_FUNCTION_DEPLOYMENT']); $this->assertEquals('http', $output['APPWRITE_FUNCTION_TRIGGER']); - $this->assertEquals('PHP', $output['APPWRITE_FUNCTION_RUNTIME_NAME']); - $this->assertEquals('8.0', $output['APPWRITE_FUNCTION_RUNTIME_VERSION']); + $this->assertEquals('Node.js', $output['APPWRITE_FUNCTION_RUNTIME_NAME']); + $this->assertEquals('22', $output['APPWRITE_FUNCTION_RUNTIME_VERSION']); $this->assertEquals(APP_VERSION_STABLE, $output['APPWRITE_VERSION']); $this->assertEquals(System::getEnv('_APP_REGION', 'default'), $output['APPWRITE_REGION']); $this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT']); @@ -235,12 +235,12 @@ class FunctionsCustomClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [Role::any()->toString()], - 'runtime' => 'node-18.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.js' ]); $this->setupDeployment($functionId, [ 'entrypoint' => 'index.js', - 'code' => $this->packageFunction('generic'), + 'code' => $this->packageFunction('basic'), 'activate' => true ]); @@ -336,7 +336,7 @@ class FunctionsCustomClientTest extends Scope 'limit' => 5, 'offset' => 2, 'useCases' => ['databases'], - 'runtimes' => ['node-16.0'] + 'runtimes' => ['node-22'] ]); $this->assertEquals(200, $templates['headers']['status-code']); @@ -348,7 +348,7 @@ class FunctionsCustomClientTest extends Scope $this->assertContains($template['useCases'][0], ['databases']); } - $this->assertContains('node-16.0', array_column($templates['body']['templates'][0]['runtimes'], 'name')); + $this->assertContains('node-22', array_column($templates['body']['templates'][0]['runtimes'], 'name')); /** * Test for FAILURE diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 4d0646b12e..488db8e6da 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -902,8 +902,8 @@ class FunctionsCustomServerTest extends Scope $this->assertStringContainsString($data['deploymentId'], $execution['body']['responseBody']); $this->assertStringContainsString('Test1', $execution['body']['responseBody']); $this->assertStringContainsString('http', $execution['body']['responseBody']); - $this->assertStringContainsString('PHP', $execution['body']['responseBody']); - $this->assertStringContainsString('8.0', $execution['body']['responseBody']); + $this->assertStringContainsString('Node.js', $execution['body']['responseBody']); + $this->assertStringContainsString('22', $execution['body']['responseBody']); $this->assertStringContainsString('Global Variable Value', $execution['body']['responseBody']); // $this->assertStringContainsString('êä', $execution['body']['responseBody']); // tests unknown utf-8 chars $this->assertNotEmpty($execution['body']['errors']); @@ -1016,8 +1016,8 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(200, $execution['body']['responseStatusCode']); $this->assertStringContainsString('Test1', $execution['body']['responseBody']); $this->assertStringContainsString('http', $execution['body']['responseBody']); - $this->assertStringContainsString('PHP', $execution['body']['responseBody']); - $this->assertStringContainsString('8.0', $execution['body']['responseBody']); + $this->assertStringContainsString('Node.js', $execution['body']['responseBody']); + $this->assertStringContainsString('22', $execution['body']['responseBody']); // $this->assertStringContainsString('êä', $execution['body']['response']); // tests unknown utf-8 chars $this->assertLessThan(1.500, $execution['body']['duration']); @@ -1282,7 +1282,7 @@ class FunctionsCustomServerTest extends Scope // Most disabled to keep tests fast return [ // ['folder' => 'php-fn', 'name' => 'php-8.0', 'entrypoint' => 'index.php', 'runtimeName' => 'PHP', 'runtimeVersion' => '8.0'], - ['folder' => 'node', 'name' => 'node-18.0', 'entrypoint' => 'index.js', 'runtimeName' => 'Node.js', 'runtimeVersion' => '18.0'], + ['folder' => 'node', 'name' => 'node-22', 'entrypoint' => 'index.js', 'runtimeName' => 'Node.js', 'runtimeVersion' => '22'], // ['folder' => 'python', 'name' => 'python-3.9', 'entrypoint' => 'main.py', 'runtimeName' => 'Python', 'runtimeVersion' => '3.9'], // ['folder' => 'ruby', 'name' => 'ruby-3.1', 'entrypoint' => 'main.rb', 'runtimeName' => 'Ruby', 'runtimeVersion' => '3.1'], // [ 'folder' => 'dart', 'name' => 'dart-2.15', 'entrypoint' => 'main.dart', 'runtimeName' => 'Dart', 'runtimeVersion' => '2.15' ], @@ -1323,27 +1323,14 @@ class FunctionsCustomServerTest extends Scope ]); $execution = $this->createExecution($functionId, [ - 'body' => 'foobar', 'async' => 'false' ]); - + $output = json_decode($execution['body']['responseBody'], true); $this->assertEquals(201, $execution['headers']['status-code']); - $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals(200, $execution['body']['responseStatusCode']); - $this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']); - $this->assertEquals('Test ' . $name, $output['APPWRITE_FUNCTION_NAME']); - $this->assertEquals($deploymentId, $output['APPWRITE_FUNCTION_DEPLOYMENT']); - $this->assertEquals('http', $output['APPWRITE_FUNCTION_TRIGGER']); - $this->assertEquals($runtimeName, $output['APPWRITE_FUNCTION_RUNTIME_NAME']); - $this->assertEquals($runtimeVersion, $output['APPWRITE_FUNCTION_RUNTIME_VERSION']); - $this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT']); - $this->assertEquals('foobar', $output['APPWRITE_FUNCTION_DATA']); - $this->assertEquals('variable', $output['CUSTOM_VARIABLE']); - $this->assertEmpty($output['APPWRITE_FUNCTION_USER_ID']); - $this->assertEmpty($output['APPWRITE_FUNCTION_JWT']); - $this->assertEquals($this->getProject()['$id'], $output['APPWRITE_FUNCTION_PROJECT_ID']); - $this->assertStringContainsString('log-works', $execution['body']['logs']); + $this->assertEquals('OK', $execution['body']['responseBody']); + $this->assertEmpty($execution['body']['logs']); $this->assertEmpty($execution['body']['errors']); $executionId = $execution['body']['$id'] ?? ''; @@ -1356,7 +1343,8 @@ class FunctionsCustomServerTest extends Scope $this->assertCount(1, $executions['body']['executions']); $this->assertEquals($executions['body']['executions'][0]['$id'], $executionId); $this->assertEquals($executions['body']['executions'][0]['trigger'], 'http'); - $this->assertStringContainsString('log-works', $executions['body']['executions'][0]['logs']); + $this->assertEquals(200, $executions['body']['executions'][0]['responseStatusCode']); + $this->assertEmpty($executions['body']['executions'][0]['responseBody']); $this->cleanupFunction($functionId); } @@ -1840,7 +1828,7 @@ class FunctionsCustomServerTest extends Scope { $function = $this->createFunction([ 'functionId' => ID::unique(), - 'runtime' => 'node-18.0', + 'runtime' => 'node-22', 'name' => 'Logging Test', 'entrypoint' => 'index.js', 'logging' => false, @@ -1856,7 +1844,7 @@ class FunctionsCustomServerTest extends Scope $domain = $this->setupFunctionDomain($functionId); $this->setupDeployment($functionId, [ - 'code' => $this->packageFunction('generic'), + 'code' => $this->packageFunction('basic'), 'activate' => true ]); @@ -1933,7 +1921,7 @@ class FunctionsCustomServerTest extends Scope // Check if the function specifications are correctly set in builds $function = $this->createFunction([ 'functionId' => ID::unique(), - 'runtime' => 'node-18.0', + 'runtime' => 'node-22', 'name' => 'Specification Test', 'entrypoint' => 'index.js', 'logging' => false, @@ -1949,7 +1937,7 @@ class FunctionsCustomServerTest extends Scope $functionId = $functionId = $function['body']['$id'] ?? ''; $deploymentId = $this->setupDeployment($functionId, [ - 'code' => $this->packageFunction('generic'), + 'code' => $this->packageFunction('basic'), 'activate' => true ]); @@ -1975,7 +1963,7 @@ class FunctionsCustomServerTest extends Scope { $functionId = $this->setupFunction([ 'functionId' => ID::unique(), - 'runtime' => 'node-18.0', + 'runtime' => 'node-22', 'name' => 'Duplicate Deployment Test', 'entrypoint' => 'index.js', 'commands' => '' @@ -1983,7 +1971,7 @@ class FunctionsCustomServerTest extends Scope $this->assertNotEmpty($functionId); $deploymentId1 = $this->setupDeployment($functionId, [ - 'code' => $this->packageFunction('generic'), + 'code' => $this->packageFunction('basic'), 'activate' => true ]); $this->assertNotEmpty($deploymentId1); @@ -1993,7 +1981,7 @@ class FunctionsCustomServerTest extends Scope $this->assertStringContainsString('APPWRITE_FUNCTION_ID', $execution['body']['responseBody']); $function = $this->updateFunction($functionId, [ - 'runtime' => 'node-18.0', + 'runtime' => 'node-22', 'name' => 'Duplicate Deployment Test', 'entrypoint' => 'index.js', 'commands' => 'rm index.js && mv maintenance.js index.js' diff --git a/tests/e2e/Services/Projects/ProjectsCustomServerTest.php b/tests/e2e/Services/Projects/ProjectsCustomServerTest.php index a01073f3a3..68ff53ae55 100644 --- a/tests/e2e/Services/Projects/ProjectsCustomServerTest.php +++ b/tests/e2e/Services/Projects/ProjectsCustomServerTest.php @@ -30,8 +30,6 @@ class ProjectsCustomServerTest extends Scope 'domain' => $testId . '-api.appwrite.test', ]); - \var_dump($response); - $this->assertEquals(201, $response['headers']['status-code']); $response = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', $headers, [ diff --git a/tests/e2e/Services/Proxy/ProxyBase.php b/tests/e2e/Services/Proxy/ProxyBase.php index b04a8594cb..f125f433f1 100644 --- a/tests/e2e/Services/Proxy/ProxyBase.php +++ b/tests/e2e/Services/Proxy/ProxyBase.php @@ -244,7 +244,7 @@ trait ProxyBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ]), [ - 'code' => $this->packageFunction('generic'), + 'code' => $this->packageFunction('basic'), 'activate' => 'true' ]); diff --git a/tests/resources/functions/node/index.js b/tests/resources/functions/node/index.js new file mode 100644 index 0000000000..a43ed308ac --- /dev/null +++ b/tests/resources/functions/node/index.js @@ -0,0 +1,3 @@ +module.exports = async(context) => { + return context.res.send('OK'); +} \ No newline at end of file