From 1a5a70688e7597178a9b79555f9691e8773030c2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 8 Jul 2024 09:20:05 +1000 Subject: [PATCH] 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 04c698feef..84010aaffe 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 11e38a57cc..8b3e054daa 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() {