diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 3e81d97c8ab1..0e0b70570af3 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -124,7 +124,7 @@ class Handler extends ExceptionHandler } }); - if ($this->validException($exception) && auth()->guard('contact')->user()->company->account->report_errors) { + if ($this->validException($exception)) { app('sentry')->captureException($exception); } } diff --git a/app/Http/Controllers/TaskController.php b/app/Http/Controllers/TaskController.php index 4770fa148f36..c4907663ec3b 100644 --- a/app/Http/Controllers/TaskController.php +++ b/app/Http/Controllers/TaskController.php @@ -280,6 +280,7 @@ class TaskController extends BaseController $old_task = json_decode(json_encode($task)); $task = $this->task_repo->save($request->all(), $task); + $task = $this->task_repo->triggeredActions($request, $task); if($task->status_order != $old_task->status_order) $this->task_repo->sortStatuses($old_task, $task); @@ -377,6 +378,7 @@ class TaskController extends BaseController public function store(StoreTaskRequest $request) { $task = $this->task_repo->save($request->all(), TaskFactory::create(auth()->user()->company()->id, auth()->user()->id)); + $task = $this->task_repo->triggeredActions($request, $task); event(new TaskWasCreated($task, $task->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); diff --git a/app/Repositories/TaskRepository.php b/app/Repositories/TaskRepository.php index 518a70a9791e..4834518daf5a 100644 --- a/app/Repositories/TaskRepository.php +++ b/app/Repositories/TaskRepository.php @@ -203,7 +203,7 @@ class TaskRepository extends BaseRepository $last = end($log); - if($last[1] !== 0){ + if(is_array($last) && $last[1] !== 0){ $new = [time(), 0]; $log = array_merge($log, [$new]); @@ -212,6 +212,7 @@ class TaskRepository extends BaseRepository } + return $task; } public function stop(Task $task) @@ -220,7 +221,7 @@ class TaskRepository extends BaseRepository $last = end($log); - if($last[1] === 0){ + if(is_array($last) && $last[1] === 0){ $last[1] = time(); @@ -231,5 +232,21 @@ class TaskRepository extends BaseRepository $task->save(); } + return $task; + + } + + public function triggeredActions($request, $task) + { + + if ($request->has('start') && $request->input('start') == 'true') { + $task = $this->start($task); + } + + if ($request->has('stop') && $request->input('stop') == 'true') { + $task = $this->stop($task); + } + + return $task; } } diff --git a/tests/Feature/TaskApiTest.php b/tests/Feature/TaskApiTest.php index b19051878b52..643fb7ed6f32 100644 --- a/tests/Feature/TaskApiTest.php +++ b/tests/Feature/TaskApiTest.php @@ -90,7 +90,7 @@ class TaskApiTest extends TestCase $response->assertStatus(200); $this->assertEquals('taskynumber', $arr['data']['number']); - + $this->assertLessThan(5, strlen($arr['data']['time_log'])); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), @@ -113,6 +113,23 @@ class TaskApiTest extends TestCase $this->assertNotEmpty($arr['data']['number']); } + public function testTaskPostNoDefinedTaskNumber() + { + $data = [ + 'description' => $this->faker->firstName, + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + '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 = [ @@ -224,4 +241,46 @@ class TaskApiTest extends TestCase $this->assertTrue($arr['data'][0]['is_deleted']); } + + + public function testTaskPostWithStartAction() + { + $data = [ + 'description' => $this->faker->firstName, + 'number' => 'taskynumber2' + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/tasks?start=true', $data); + + $arr = $response->json(); + $response->assertStatus(200); + + $this->assertEquals('taskynumber2', $arr['data']['number']); + $this->assertGreaterThan(5, strlen($arr['data']['time_log'])); + + } + + public function testTaskPostWithStopAction() + { + $data = [ + 'description' => $this->faker->firstName, + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/tasks?stop=true', $data); + + $arr = $response->json(); + $response->assertStatus(200); + + $this->assertLessThan(5, strlen($arr['data']['time_log'])); + + } + + + }