2021-08-29 19:50:52 +12:00
|
|
|
<?php
|
|
|
|
|
2021-08-29 20:43:14 +12:00
|
|
|
namespace Tests\E2E\Services\Functions;
|
2021-08-29 19:50:52 +12:00
|
|
|
|
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
use Tests\E2E\Client;
|
2021-08-29 19:59:08 +12:00
|
|
|
use Tests\E2E\Scopes\SideConsole;
|
2021-08-29 19:50:52 +12:00
|
|
|
|
2021-08-29 20:11:29 +12:00
|
|
|
class FunctionsConsoleClientTest extends Scope
|
2021-08-29 19:50:52 +12:00
|
|
|
{
|
|
|
|
use ProjectCustom;
|
2021-08-29 19:59:08 +12:00
|
|
|
use SideConsole;
|
2021-08-29 19:50:52 +12:00
|
|
|
|
2021-10-27 02:19:28 +13:00
|
|
|
public function testCreateFunction(): array
|
2021-08-29 19:50:52 +12:00
|
|
|
{
|
2021-08-29 19:59:08 +12:00
|
|
|
$function = $this->client->call(Client::METHOD_POST, '/functions', array_merge([
|
2021-08-29 19:50:52 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2021-08-29 19:59:08 +12:00
|
|
|
'functionId' => 'unique()',
|
|
|
|
'name' => 'Test',
|
2021-10-27 02:19:28 +13:00
|
|
|
'execute' => ['user:' . $this->getUser()['$id']],
|
2021-08-29 19:59:08 +12:00
|
|
|
'runtime' => 'php-8.0',
|
|
|
|
'vars' => [
|
|
|
|
'funcKey1' => 'funcValue1',
|
|
|
|
'funcKey2' => 'funcValue2',
|
|
|
|
'funcKey3' => 'funcValue3',
|
|
|
|
],
|
|
|
|
'events' => [
|
|
|
|
'account.create',
|
|
|
|
'account.delete',
|
|
|
|
],
|
|
|
|
'schedule' => '0 0 1 1 *',
|
|
|
|
'timeout' => 10,
|
2021-08-29 19:50:52 +12:00
|
|
|
]);
|
|
|
|
|
2021-08-29 19:59:08 +12:00
|
|
|
$this->assertEquals(201, $function['headers']['status-code']);
|
2021-08-29 19:50:52 +12:00
|
|
|
|
2021-08-29 19:59:08 +12:00
|
|
|
return [
|
|
|
|
'functionId' => $function['body']['$id']
|
|
|
|
];
|
2021-08-29 19:50:52 +12:00
|
|
|
}
|
2021-10-27 02:19:28 +13:00
|
|
|
|
2021-08-29 19:59:08 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateFunction
|
|
|
|
*/
|
|
|
|
public function testGetCollectionUsage(array $data)
|
2021-08-29 19:50:52 +12:00
|
|
|
{
|
|
|
|
/**
|
2021-08-29 19:59:08 +12:00
|
|
|
* Test for FAILURE
|
2021-08-29 19:50:52 +12:00
|
|
|
*/
|
|
|
|
|
2021-10-27 02:19:28 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/usage', array_merge([
|
2021-08-29 19:50:52 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id']
|
|
|
|
], $this->getHeaders()), [
|
2021-08-29 19:59:08 +12:00
|
|
|
'range' => '232h'
|
2021-08-29 19:50:52 +12:00
|
|
|
]);
|
|
|
|
|
2021-08-29 19:59:08 +12:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/functions/randomFunctionId/usage', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id']
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'range' => '24h'
|
|
|
|
]);
|
2021-08-29 19:50:52 +12:00
|
|
|
|
2021-08-29 19:59:08 +12:00
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
2021-08-29 19:50:52 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
|
2021-10-27 02:19:28 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/usage', array_merge([
|
2021-08-29 19:50:52 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id']
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'range' => '24h'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
2021-08-29 20:11:29 +12:00
|
|
|
$this->assertEquals(count($response['body']), 4);
|
2021-08-29 19:50:52 +12:00
|
|
|
$this->assertEquals($response['body']['range'], '24h');
|
2021-10-27 02:19:28 +13:00
|
|
|
$this->assertIsArray($response['body']['functionsExecutions']);
|
|
|
|
$this->assertIsArray($response['body']['functionsFailures']);
|
|
|
|
$this->assertIsArray($response['body']['functionsCompute']);
|
2021-08-29 19:50:52 +12:00
|
|
|
}
|
2021-10-27 02:19:28 +13:00
|
|
|
}
|