API improvements (#1826)
This commit is contained in:
@@ -12,7 +12,9 @@ namespace App\Tests\API;
|
||||
use App\DataFixtures\UserFixtures;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\ProjectMeta;
|
||||
use App\Entity\ProjectRate;
|
||||
use App\Entity\Team;
|
||||
use App\Entity\User;
|
||||
use App\Repository\ProjectRateRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
@@ -86,7 +88,7 @@ class ProjectControllerTest extends APIControllerBaseTest
|
||||
$this->assertIsArray($result);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals(1, \count($result));
|
||||
$this->assertStructure($result[0], false);
|
||||
self::assertApiResponseTypeStructure('ProjectCollection', $result[0]);
|
||||
}
|
||||
|
||||
protected function loadProjectTestData(HttpKernelBrowser $client)
|
||||
@@ -114,8 +116,25 @@ class ProjectControllerTest extends APIControllerBaseTest
|
||||
$em->persist($project);
|
||||
|
||||
$project = (new Project())->setName('fifth')->setVisible(true)->setCustomer($customer);
|
||||
|
||||
// add meta fields
|
||||
$meta = new ProjectMeta();
|
||||
$meta->setName('bar')->setValue('foo')->setIsVisible(false);
|
||||
$project->setMetaField($meta);
|
||||
$meta = new ProjectMeta();
|
||||
$meta->setName('foo')->setValue('bar')->setIsVisible(true);
|
||||
$project->setMetaField($meta);
|
||||
$em->persist($project);
|
||||
|
||||
// and a team
|
||||
$team = new Team();
|
||||
$team->setName('Testing project team');
|
||||
$team->setTeamLead($this->getUserByRole(User::ROLE_USER));
|
||||
$team->addCustomer($customer);
|
||||
$team->addProject($project);
|
||||
$team->addUser($this->getUserByRole(User::ROLE_TEAMLEAD));
|
||||
$em->persist($team);
|
||||
|
||||
$project = (new Project())->setName('sixth')->setVisible(false)->setCustomer($customer3);
|
||||
$em->persist($project);
|
||||
|
||||
@@ -138,7 +157,7 @@ class ProjectControllerTest extends APIControllerBaseTest
|
||||
for ($i = 0; $i < \count($expected); $i++) {
|
||||
$project = $result[$i];
|
||||
$compare = $expected[$i];
|
||||
$this->assertStructure($project, false);
|
||||
self::assertApiResponseTypeStructure('ProjectCollection', $project);
|
||||
$this->assertEquals($compare[1], $project['customer']);
|
||||
}
|
||||
}
|
||||
@@ -169,7 +188,7 @@ class ProjectControllerTest extends APIControllerBaseTest
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertStructure($result);
|
||||
self::assertApiResponseTypeStructure('ProjectEntity', $result);
|
||||
}
|
||||
|
||||
public function testNotFound()
|
||||
@@ -195,7 +214,7 @@ class ProjectControllerTest extends APIControllerBaseTest
|
||||
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertIsArray($result);
|
||||
$this->assertStructure($result);
|
||||
self::assertApiResponseTypeStructure('ProjectEntity', $result);
|
||||
$this->assertNotEmpty($result['id']);
|
||||
self::assertEquals('2018-02-08T13:02:54+0000', $result['orderDate']);
|
||||
self::assertEquals('2019-02-01T19:32:17+0000', $result['start']);
|
||||
@@ -214,7 +233,7 @@ class ProjectControllerTest extends APIControllerBaseTest
|
||||
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertIsArray($result);
|
||||
$this->assertStructure($result);
|
||||
self::assertApiResponseTypeStructure('ProjectEntity', $result);
|
||||
$this->assertNotEmpty($result['id']);
|
||||
self::assertEquals('foo', $result['name']);
|
||||
}
|
||||
@@ -265,7 +284,7 @@ class ProjectControllerTest extends APIControllerBaseTest
|
||||
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertIsArray($result);
|
||||
$this->assertStructure($result);
|
||||
self::assertApiResponseTypeStructure('ProjectEntity', $result);
|
||||
$this->assertNotEmpty($result['id']);
|
||||
}
|
||||
|
||||
@@ -354,23 +373,4 @@ class ProjectControllerTest extends APIControllerBaseTest
|
||||
$project = $em->getRepository(Project::class)->find(1);
|
||||
$this->assertEquals('another,testing,bar', $project->getMetaField('metatestmock')->getValue());
|
||||
}
|
||||
|
||||
protected function assertStructure(array $result, $full = true)
|
||||
{
|
||||
$expectedKeys = [
|
||||
'id', 'name', 'visible', 'customer', 'color', 'metaFields', 'parentTitle', 'start', 'end', 'teams'
|
||||
];
|
||||
|
||||
if ($full) {
|
||||
$expectedKeys = array_merge($expectedKeys, [
|
||||
'comment', 'budget', 'timeBudget', 'orderNumber', 'orderDate'
|
||||
]);
|
||||
}
|
||||
|
||||
$actual = array_keys($result);
|
||||
sort($actual);
|
||||
sort($expectedKeys);
|
||||
|
||||
$this->assertEquals($expectedKeys, $actual, 'Project structure does not match');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user