From 1a5a70688e7597178a9b79555f9691e8773030c2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 8 Jul 2024 09:20:05 +1000 Subject: [PATCH 1/3] Additional tests for project task rates --- .../Requests/Project/StoreProjectRequest.php | 4 +- tests/Feature/ProjectApiTest.php | 111 ++++++++++++++++++ 2 files changed, 113 insertions(+), 2 deletions(-) diff --git a/app/Http/Requests/Project/StoreProjectRequest.php b/app/Http/Requests/Project/StoreProjectRequest.php index 04c698feef29..84010aaffe33 100644 --- a/app/Http/Requests/Project/StoreProjectRequest.php +++ b/app/Http/Requests/Project/StoreProjectRequest.php @@ -80,8 +80,8 @@ class StoreProjectRequest extends Request $input['budgeted_hours'] = 0; } - $input['task_rate'] = isset($input['task_rate']) ? $input['task_rate'] : 0; - + $input['task_rate'] = (isset($input['task_rate']) && floatval($input['task_rate']) >= 0) ? $input['task_rate'] : 0; + $this->replace($input); } diff --git a/tests/Feature/ProjectApiTest.php b/tests/Feature/ProjectApiTest.php index 11e38a57cc20..8b3e054daa93 100644 --- a/tests/Feature/ProjectApiTest.php +++ b/tests/Feature/ProjectApiTest.php @@ -47,6 +47,117 @@ class ProjectApiTest extends TestCase Model::reguard(); } + public function testCreateProjectWithNullTaskRate() + { + + $data = [ + 'client_id' => $this->client->hashed_id, + 'name' => 'howdy', + 'task_rate' => null, + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson("/api/v1/projects", $data); + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertEquals(0, $arr['data']['task_rate']); + + } + + public function testCreateProjectWithNullTaskRate2() + { + + $data = [ + 'client_id' => $this->client->hashed_id, + 'name' => 'howdy', + 'task_rate' => "A", + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson("/api/v1/projects", $data); + + $response->assertStatus(422); + + $arr = $response->json(); + + } + + + public function testCreateProjectWithNullTaskRate3() + { + + $data = [ + 'client_id' => $this->client->hashed_id, + 'name' => 'howdy', + 'task_rate' => "10", + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson("/api/v1/projects", $data); + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertEquals(10, $arr['data']['task_rate']); + + } + + public function testCreateProjectWithNullTaskRate5() + { + + $data = [ + 'client_id' => $this->client->hashed_id, + 'name' => 'howdy', + 'task_rate' => "-10", + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson("/api/v1/projects", $data); + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertEquals(0, $arr['data']['task_rate']); + + } + + + + public function testCreateProjectWithNullTaskRate4() + { + + $data = [ + 'client_id' => $this->client->hashed_id, + 'name' => 'howdy', + 'task_rate' => 10, + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson("/api/v1/projects", $data); + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertEquals(10, $arr['data']['task_rate']); + + } + public function testProjectIncludesZeroCount() { From 11ead67df82907ce68d2bed4d93b024c758af6e5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 8 Jul 2024 09:20:50 +1000 Subject: [PATCH 2/3] Additional validation --- app/Http/Requests/Project/UpdateProjectRequest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/Project/UpdateProjectRequest.php b/app/Http/Requests/Project/UpdateProjectRequest.php index cab826e32ac6..820940dd0d19 100644 --- a/app/Http/Requests/Project/UpdateProjectRequest.php +++ b/app/Http/Requests/Project/UpdateProjectRequest.php @@ -45,7 +45,8 @@ class UpdateProjectRequest extends Request $rules['number'] = Rule::unique('projects')->where('company_id', $user->company()->id)->ignore($this->project->id); } - $rules['budgeted_hours'] = 'sometimes|numeric'; + $rules['budgeted_hours'] = 'sometimes|bail|numeric'; + $rules['task_rate'] = 'sometimes|bail|numeric'; if ($this->file('documents') && is_array($this->file('documents'))) { $rules['documents.*'] = $this->fileValidation(); From 41253ec09d31fe1b44ef8c0ec8e85fc15a68ded2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 8 Jul 2024 09:47:28 +1000 Subject: [PATCH 3/3] v5.10.5 --- VERSION.txt | 2 +- config/ninja.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 6af1ed16172e..a16dcb354a2b 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.10.4 \ No newline at end of file +5.10.5 \ No newline at end of file diff --git a/config/ninja.php b/config/ninja.php index b8d1f187c242..e77809a3f432 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -17,8 +17,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => env('APP_VERSION', '5.10.4'), - 'app_tag' => env('APP_TAG', '5.10.4'), + 'app_version' => env('APP_VERSION', '5.10.5'), + 'app_tag' => env('APP_TAG', '5.10.5'), 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', false),