fix required fields in API (#1718)

This commit is contained in:
Kevin Papst
2020-05-19 11:24:30 +02:00
committed by GitHub
parent e61ffe4db4
commit 3c511df7f7
7 changed files with 58 additions and 2 deletions

View File

@@ -201,6 +201,21 @@ class ActivityControllerTest extends APIControllerBaseTest
$this->assertNotEmpty($result['id']);
}
public function testPostActionWithLeastFields()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$data = [
'name' => 'foo',
];
$this->request($client, '/api/activities', 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertIsArray($result);
$this->assertStructure($result);
$this->assertNotEmpty($result['id']);
}
public function testPostActionWithInvalidUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);

View File

@@ -136,6 +136,24 @@ class CustomerControllerTest extends APIControllerBaseTest
$this->assertNotEmpty($result['id']);
}
public function testPostActionWithLeastFields()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$data = [
'name' => 'foo',
'country' => 'DE',
'currency' => 'EUR',
'timezone' => 'Europe/Berlin',
];
$this->request($client, '/api/customers', 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertIsArray($result);
$this->assertStructure($result);
$this->assertNotEmpty($result['id']);
}
public function testPostActionWithInvalidUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);

View File

@@ -202,6 +202,23 @@ class ProjectControllerTest extends APIControllerBaseTest
self::assertEquals('2020-02-08T21:11:42+0000', $result['end']);
}
public function testPostActionWithLeastFields()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$data = [
'name' => 'foo',
'customer' => 1
];
$this->request($client, '/api/projects', 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertIsArray($result);
$this->assertStructure($result);
$this->assertNotEmpty($result['id']);
self::assertEquals('foo', $result['name']);
}
public function testPostActionWithInvalidUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);