diff --git a/app/Repositories/TaskRepository.php b/app/Repositories/TaskRepository.php index 6e9ac946071a..3479e67380bc 100644 --- a/app/Repositories/TaskRepository.php +++ b/app/Repositories/TaskRepository.php @@ -51,7 +51,6 @@ class TaskRepository extends BaseRepository $task->fill($data); $task->save(); - $task->start_time = $task->start_time ?: $task->calcStartTime(); $task->number = empty($task->number) ? $this->getNextTaskNumber($task) : $task->number; if (isset($data['description'])) { @@ -90,6 +89,7 @@ class TaskRepository extends BaseRepository } $task->time_log = json_encode($time_log); + $task->start_time = $task->start_time ?: $task->calcStartTime(); $task->duration = $task->calcDuration(); $task->save(); diff --git a/tests/Feature/TaskApiTest.php b/tests/Feature/TaskApiTest.php index 885007a6e3b2..937846ec2a04 100644 --- a/tests/Feature/TaskApiTest.php +++ b/tests/Feature/TaskApiTest.php @@ -62,7 +62,29 @@ class TaskApiTest extends TestCase 'X-API-TOKEN' => $this->token, ])->post('/api/v1/tasks', $data); + $arr = $response->json(); $response->assertStatus(200); + + $this->assertNotEmpty($arr['data']['number']); + } + + public function testTaskPostWithActionStart() + { + $data = [ + 'description' => $this->faker->firstName, + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/tasks?action=start', $data); + + $arr = $response->json(); + $response->assertStatus(200); + + $this->assertGreaterThan(0, $arr['data']['start_time']); + + } public function testTaskPut()