mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 10:44:36 -04:00
Fixes for task edge cases
This commit is contained in:
parent
2d0c6fd0af
commit
3a22fd0384
@ -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);
|
app('sentry')->captureException($exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,6 +280,7 @@ class TaskController extends BaseController
|
|||||||
$old_task = json_decode(json_encode($task));
|
$old_task = json_decode(json_encode($task));
|
||||||
|
|
||||||
$task = $this->task_repo->save($request->all(), $task);
|
$task = $this->task_repo->save($request->all(), $task);
|
||||||
|
$task = $this->task_repo->triggeredActions($request, $task);
|
||||||
|
|
||||||
if($task->status_order != $old_task->status_order)
|
if($task->status_order != $old_task->status_order)
|
||||||
$this->task_repo->sortStatuses($old_task, $task);
|
$this->task_repo->sortStatuses($old_task, $task);
|
||||||
@ -377,6 +378,7 @@ class TaskController extends BaseController
|
|||||||
public function store(StoreTaskRequest $request)
|
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->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)));
|
event(new TaskWasCreated($task, $task->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ class TaskRepository extends BaseRepository
|
|||||||
|
|
||||||
$last = end($log);
|
$last = end($log);
|
||||||
|
|
||||||
if($last[1] !== 0){
|
if(is_array($last) && $last[1] !== 0){
|
||||||
|
|
||||||
$new = [time(), 0];
|
$new = [time(), 0];
|
||||||
$log = array_merge($log, [$new]);
|
$log = array_merge($log, [$new]);
|
||||||
@ -212,6 +212,7 @@ class TaskRepository extends BaseRepository
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $task;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function stop(Task $task)
|
public function stop(Task $task)
|
||||||
@ -220,7 +221,7 @@ class TaskRepository extends BaseRepository
|
|||||||
|
|
||||||
$last = end($log);
|
$last = end($log);
|
||||||
|
|
||||||
if($last[1] === 0){
|
if(is_array($last) && $last[1] === 0){
|
||||||
|
|
||||||
$last[1] = time();
|
$last[1] = time();
|
||||||
|
|
||||||
@ -231,5 +232,21 @@ class TaskRepository extends BaseRepository
|
|||||||
$task->save();
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ class TaskApiTest extends TestCase
|
|||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
$this->assertEquals('taskynumber', $arr['data']['number']);
|
$this->assertEquals('taskynumber', $arr['data']['number']);
|
||||||
|
$this->assertLessThan(5, strlen($arr['data']['time_log']));
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
@ -113,6 +113,23 @@ class TaskApiTest extends TestCase
|
|||||||
$this->assertNotEmpty($arr['data']['number']);
|
$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()
|
public function testTaskPostWithActionStart()
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
@ -224,4 +241,46 @@ class TaskApiTest extends TestCase
|
|||||||
|
|
||||||
$this->assertTrue($arr['data'][0]['is_deleted']);
|
$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']));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user