1
0
Fork 0
mirror of synced 2024-06-01 18:39:57 +12:00

Added more tests

This commit is contained in:
Eldad Fux 2020-07-11 22:40:58 +03:00
parent 1b897b4223
commit 64c17a82c5
2 changed files with 376 additions and 2 deletions

View file

@ -856,7 +856,8 @@ App::post('/v1/projects/:projectId/tasks')
->param('name', null, function () { return new Text(256); }, 'Task name.')
->param('status', null, function () { return new WhiteList(['play', 'pause']); }, 'Task status.')
->param('schedule', null, function () { return new Cron(); }, 'Task schedule CRON syntax.')
->param('security', false, function () { return new Boolean(true); }, 'Certificate verification, false for disabled or true for enabled.') ->param('httpMethod', '', function () { return new WhiteList(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT']); }, 'Task HTTP method.')
->param('security', false, function () { return new Boolean(true); }, 'Certificate verification, false for disabled or true for enabled.')
->param('httpMethod', '', function () { return new WhiteList(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT']); }, 'Task HTTP method.')
->param('httpUrl', '', function () { return new URL(); }, 'Task HTTP URL')
->param('httpHeaders', null, function () { return new ArrayList(new Text(256)); }, 'Task HTTP headers list.', true)
->param('httpUser', '', function () { return new Text(256); }, 'Task HTTP user.', true)

View file

@ -679,4 +679,377 @@ class ProjectsConsoleClientTest extends Scope
return $data;
}
}
// Tasks
/**
* @depends testCreateProject
*/
public function testCreateProjectTask($data): array
{
$id = (isset($data['projectId'])) ? $data['projectId'] : '';
$response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/tasks', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Task Test',
'status' => 'play',
'schedule' => '* * * * *',
'security' => true,
'httpMethod' => 'GET',
'httpUrl' => 'http://example.com',
'httpHeaders' => ['demo:value'],
'httpUser' => 'username',
'httpPass' => 'password',
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('Task Test', $response['body']['name']);
$this->assertEquals('play', $response['body']['status']);
$this->assertEquals(true, $response['body']['security']);
$this->assertEquals('* * * * *', $response['body']['schedule']);
$this->assertEquals('GET', $response['body']['httpMethod']);
$this->assertEquals('http://example.com', $response['body']['httpUrl']);
$this->assertContains('demo:value', $response['body']['httpHeaders']);
$this->assertCount(1, $response['body']['httpHeaders']);
$this->assertEquals('username', $response['body']['httpUser']);
// $this->assertEquals('password', $response['body']['httpPass']); // TODO add after encrypt refactor
$data = array_merge($data, ['taskId' => $response['body']['$id']]);
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/tasks', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Task Test',
'status' => 'unknown',
'schedule' => '* * * * *',
'security' => true,
'httpMethod' => 'GET',
'httpUrl' => 'http://example.com',
'httpHeaders' => ['demo:value'],
'httpUser' => 'username',
'httpPass' => 'password',
]);
$this->assertEquals(400, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/tasks', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Task Test',
'status' => 'play',
'schedule' => 'unknown',
'security' => true,
'httpMethod' => 'GET',
'httpUrl' => 'http://example.com',
'httpHeaders' => ['demo:value'],
'httpUser' => 'username',
'httpPass' => 'password',
]);
$this->assertEquals(400, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/tasks', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Task Test',
'status' => 'play',
'schedule' => '* * * * *',
'security' => 'string',
'httpMethod' => 'GET',
'httpUrl' => 'http://example.com',
'httpHeaders' => ['demo:value'],
'httpUser' => 'username',
'httpPass' => 'password',
]);
$this->assertEquals(400, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/tasks', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Task Test',
'status' => 'play',
'schedule' => '* * * * *',
'security' => true,
'httpMethod' => 'UNKNOWN',
'httpUrl' => 'http://example.com',
'httpHeaders' => ['demo:value'],
'httpUser' => 'username',
'httpPass' => 'password',
]);
$this->assertEquals(400, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/tasks', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Task Test',
'status' => 'play',
'schedule' => '* * * * *',
'security' => true,
'httpMethod' => 'GET',
'httpUrl' => 'http://example.com',
'httpHeaders' => 'string',
'httpUser' => 'username',
'httpPass' => 'password',
]);
$this->assertEquals(400, $response['headers']['status-code']);
return $data;
}
/**
* @depends testCreateProjectTask
*/
public function testGetProjectTask($data): array
{
$id = (isset($data['projectId'])) ? $data['projectId'] : '';
$taskId = (isset($data['taskId'])) ? $data['taskId'] : '';
$response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/tasks/'.$taskId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($taskId, $response['body']['$id']);
$this->assertEquals('Task Test', $response['body']['name']);
$this->assertEquals('play', $response['body']['status']);
$this->assertEquals(true, $response['body']['security']);
$this->assertEquals('* * * * *', $response['body']['schedule']);
$this->assertEquals('GET', $response['body']['httpMethod']);
$this->assertEquals('http://example.com', $response['body']['httpUrl']);
$this->assertContains('demo:value', $response['body']['httpHeaders']);
$this->assertCount(1, $response['body']['httpHeaders']);
$this->assertEquals('username', $response['body']['httpUser']);
// $this->assertEquals('password', $response['body']['httpPass']); // TODO add after encrypt refactor
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/tasks/error', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
return $data;
}
/**
* @depends testCreateProjectTask
*/
public function testUpdateProjectTask($data): array
{
$id = (isset($data['projectId'])) ? $data['projectId'] : '';
$taskId = (isset($data['taskId'])) ? $data['taskId'] : '';
$response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/tasks/'.$taskId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Task Test 2',
'status' => 'pause',
'schedule' => '*/5 * * * *',
'security' => false,
'httpMethod' => 'POST',
'httpUrl' => 'http://example.com/demo',
'httpHeaders' => ['demo1: value1', 'demo2:value2'],
'httpUser' => 'username1',
'httpPass' => 'password1',
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($taskId, $response['body']['$id']);
$this->assertEquals('Task Test 2', $response['body']['name']);
$this->assertEquals('pause', $response['body']['status']);
$this->assertEquals(false, $response['body']['security']);
$this->assertEquals('*/5 * * * *', $response['body']['schedule']);
$this->assertEquals('POST', $response['body']['httpMethod']);
$this->assertEquals('http://example.com/demo', $response['body']['httpUrl']);
$this->assertContains('demo1: value1', $response['body']['httpHeaders']);
$this->assertContains('demo2:value2', $response['body']['httpHeaders']);
$this->assertCount(2, $response['body']['httpHeaders']);
$this->assertEquals('username1', $response['body']['httpUser']);
// $this->assertEquals('password1', $response['body']['httpPass']); // TODO add after encrypt refactor
$response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/tasks/'.$taskId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($taskId, $response['body']['$id']);
$this->assertEquals('Task Test 2', $response['body']['name']);
$this->assertEquals('pause', $response['body']['status']);
$this->assertEquals(false, $response['body']['security']);
$this->assertEquals('*/5 * * * *', $response['body']['schedule']);
$this->assertEquals('POST', $response['body']['httpMethod']);
$this->assertEquals('http://example.com/demo', $response['body']['httpUrl']);
$this->assertContains('demo1: value1', $response['body']['httpHeaders']);
$this->assertContains('demo2:value2', $response['body']['httpHeaders']);
$this->assertCount(2, $response['body']['httpHeaders']);
$this->assertEquals('username1', $response['body']['httpUser']);
// $this->assertEquals('password1', $response['body']['httpPass']); // TODO add after encrypt refactor
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/tasks/'.$taskId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Task Test 2',
'status' => 'pause1',
'schedule' => '* * * * *',
'security' => false,
'httpMethod' => 'POST',
'httpUrl' => 'http://example.com/demo',
'httpHeaders' => ['demo1: value1', 'demo2:value2'],
'httpUser' => 'username1',
'httpPass' => 'password1',
]);
$this->assertEquals(400, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/tasks/'.$taskId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Task Test 2',
'status' => 'pause',
'schedule' => '* * * * *xxx',
'security' => false,
'httpMethod' => 'POST',
'httpUrl' => 'http://example.com/demo',
'httpHeaders' => ['demo1: value1', 'demo2:value2'],
'httpUser' => 'username1',
'httpPass' => 'password1',
]);
$this->assertEquals(400, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/tasks/'.$taskId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Task Test 2',
'status' => 'pause',
'schedule' => '* * * * *',
'security' => 'string',
'httpMethod' => 'POST',
'httpUrl' => 'http://example.com/demo',
'httpHeaders' => ['demo1: value1', 'demo2:value2'],
'httpUser' => 'username1',
'httpPass' => 'password1',
]);
$this->assertEquals(400, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/tasks/'.$taskId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Task Test 2',
'status' => 'pause',
'schedule' => '* * * * *',
'security' => false,
'httpMethod' => 'UNKNOWN',
'httpUrl' => 'http://example.com/demo',
'httpHeaders' => ['demo1: value1', 'demo2:value2'],
'httpUser' => 'username1',
'httpPass' => 'password1',
]);
$this->assertEquals(400, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/tasks/'.$taskId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Task Test 2',
'status' => 'pause',
'schedule' => '* * * * *',
'security' => false,
'httpMethod' => 'POST',
'httpUrl' => 'example.com/demo',
'httpHeaders' => ['demo1: value1', 'demo2:value2'],
'httpUser' => 'username1',
'httpPass' => 'password1',
]);
$this->assertEquals(400, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/tasks/'.$taskId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Task Test 2',
'status' => 'pause',
'schedule' => '* * * * *',
'security' => false,
'httpMethod' => 'POST',
'httpUrl' => 'http://example.com/demo',
'httpHeaders' => 'string',
'httpUser' => 'username1',
'httpPass' => 'password1',
]);
$this->assertEquals(400, $response['headers']['status-code']);
return $data;
}
/**
* @depends testCreateProjectTask
*/
public function testDeleteProjectTask($data): array
{
$id = (isset($data['projectId'])) ? $data['projectId'] : '';
$taskId = (isset($data['taskId'])) ? $data['taskId'] : '';
$response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/tasks/'.$taskId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(204, $response['headers']['status-code']);
$this->assertEmpty($response['body']);
$response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/tasks/'.$taskId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/tasks/error', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
return $data;
}
}