From 76cdc52331a8ea20305dfa3e857d8b2e6a8a6b2b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 12 Apr 2024 09:06:34 +1000 Subject: [PATCH] Fixes for tasks --- .../Requests/Invoice/UpdateInvoiceRequest.php | 1 - tests/Feature/TaskApiTest.php | 44 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php index d863c5323c..6da6baa268 100644 --- a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php +++ b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php @@ -80,7 +80,6 @@ class UpdateInvoiceRequest extends Request $rules['partial_due_date'] = ['bail', 'sometimes', 'exclude_if:partial,0', Rule::requiredIf(fn () => $this->partial > 0), 'date', 'before:due_date']; $rules['due_date'] = ['bail', 'sometimes', 'nullable', 'after:partial_due_date', Rule::requiredIf(fn () => strlen($this->partial_due_date) > 1), 'date']; - return $rules; } diff --git a/tests/Feature/TaskApiTest.php b/tests/Feature/TaskApiTest.php index b4a0a06e2e..22ed457ceb 100644 --- a/tests/Feature/TaskApiTest.php +++ b/tests/Feature/TaskApiTest.php @@ -104,6 +104,50 @@ class TaskApiTest extends TestCase } } + public function testUserFilters() + { + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->getJson("/api/v1/tasks")->assertStatus(200); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->getJson("/api/v1/tasks?user_id={$this->user->hashed_id}"); + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertEquals($this->user->hashed_id, $arr['data'][0]['user_id']); + $this->assertCount(1, $arr['data']); + + $t = Task::factory()->create([ + 'client_id' => $this->client->id, + 'user_id' => $this->user->id, + 'assigned_user_id' => $this->user->id, + 'company_id' => $this->company->id, + 'description' => 'Test Task', + 'time_log' => '[[1681165417,1681165432,"sumtin",true],[1681165446,0]]', + ]); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->getJson("/api/v1/tasks?assigned_user={$this->user->hashed_id}"); + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertEquals($this->user->hashed_id, $arr['data'][0]['user_id']); + $this->assertEquals($this->user->hashed_id, $arr['data'][0]['assigned_user_id']); + $this->assertCount(1, $arr['data']); + + } + public function testEmptyTimeLogArray() {