restart via API allows to copy description (#782)

This commit is contained in:
Kevin Papst
2019-05-13 17:32:01 +02:00
committed by GitHub
parent 1f5710eaba
commit bbe1f9beda
28 changed files with 250 additions and 118 deletions

View File

@@ -430,16 +430,15 @@ class TimesheetControllerTest extends APIControllerBaseTest
$this->assertEntityNotFound(User::ROLE_USER, '/api/timesheets/' . $id);
}
public function testDeleteActionWithUnknownTimesheet()
{
$this->assertEntityNotFoundForDelete(User::ROLE_ADMIN, '/api/timesheets/255', []);
}
public function testDeleteActionForDifferentUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/api/timesheets/1');
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertIsArray($result);
$this->assertDefaultStructure($result);
$this->assertNotEmpty($result['id']);
$id = $result['id'];
$id = 1;
$this->request($client, '/api/timesheets/' . $id, 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -631,6 +630,91 @@ class TimesheetControllerTest extends APIControllerBaseTest
$this->assertDefaultStructure($result[0], false);
}
public function testRestartAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$data = [
'description' => 'foo',
'tags' => 'another,testing,bar'
];
$this->request($client, '/api/timesheets/1', 'PATCH', [], json_encode($data));
$this->request($client, '/api/timesheets/1/restart', 'PATCH');
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertDefaultStructure($result, true);
$this->assertEmpty($result['description']);
$this->assertEmpty($result['tags']);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find($result['id']);
$this->assertInstanceOf(\DateTime::class, $timesheet->getBegin());
$this->assertNull($timesheet->getEnd());
$this->assertEquals(1, $timesheet->getActivity()->getId());
$this->assertEquals(1, $timesheet->getProject()->getId());
$this->assertEmpty($timesheet->getDescription());
$this->assertEmpty($timesheet->getTags());
}
public function testRestartActionWithCopyData()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$data = [
'description' => 'foo',
'tags' => 'another,testing,bar'
];
$this->request($client, '/api/timesheets/1', 'PATCH', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$this->assertEquals('foo', $timesheet->getDescription());
$this->request($client, '/api/timesheets/1/restart', 'PATCH', ['copy' => 'all']);
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertDefaultStructure($result, true);
$this->assertEquals('foo', $result['description']);
$this->assertEquals(['another', 'testing', 'bar'], $result['tags']);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find($result['id']);
$this->assertInstanceOf(\DateTime::class, $timesheet->getBegin());
$this->assertNull($timesheet->getEnd());
$this->assertEquals(1, $timesheet->getActivity()->getId());
$this->assertEquals(1, $timesheet->getProject()->getId());
$this->assertEquals('foo', $timesheet->getDescription());
$this->assertEquals(['another', 'testing', 'bar'], $timesheet->getTagsAsArray());
}
public function testRestartNotAllowedForUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$start = new \DateTime('-10 days');
$fixture = new TimesheetFixtures();
$fixture
->setFixedRate(true)
->setHourlyRate(true)
->setAmount(2)
->setUser($this->getUserByRole($em, User::ROLE_ADMIN))
->setStartDate($start)
->setAmountRunning(3)
;
$this->importFixture($em, $fixture);
$this->request($client, '/api/timesheets/12/restart', 'PATCH');
$this->assertApiResponseAccessDenied($client->getResponse(), 'You are not allowed to re-start this timesheet');
}
protected function assertDefaultStructure(array $result, $full = true)
{
$expectedKeys = [