From 7173ba2931d5ba1ef8698e52d8debe0273e10773 Mon Sep 17 00:00:00 2001 From: = Date: Sat, 20 Mar 2021 11:16:29 +1100 Subject: [PATCH] catch project exceptions --- app/Http/Middleware/QueryLogging.php | 2 +- app/Models/Project.php | 1 + tests/Feature/ProjectApiTest.php | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/Http/Middleware/QueryLogging.php b/app/Http/Middleware/QueryLogging.php index 92aee1a2046b..b898814f6855 100644 --- a/app/Http/Middleware/QueryLogging.php +++ b/app/Http/Middleware/QueryLogging.php @@ -54,7 +54,7 @@ class QueryLogging nlog($request->method().' - '.$request->url().": $count queries - ".$time); // if($count > 50) - // Log::nlog($queries); + //nlog($queries); } } diff --git a/app/Models/Project.php b/app/Models/Project.php index 42b84cbbaa29..daf67ad2d1e8 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -37,6 +37,7 @@ class Project extends BaseModel 'custom_value4', 'assigned_user_id', 'color', + 'number', ]; public function getEntityType() diff --git a/tests/Feature/ProjectApiTest.php b/tests/Feature/ProjectApiTest.php index d843329482d7..a9062e742cab 100644 --- a/tests/Feature/ProjectApiTest.php +++ b/tests/Feature/ProjectApiTest.php @@ -16,6 +16,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Session; use Tests\MockAccountData; use Tests\TestCase; +use Illuminate\Validation\ValidationException; /** * @test @@ -56,6 +57,7 @@ class ProjectApiTest extends TestCase $data = [ 'name' => $this->faker->firstName, 'client_id' => $this->client->hashed_id, + 'number' => 'duplicate', ]; $response = $this->withHeaders([ @@ -64,6 +66,26 @@ class ProjectApiTest extends TestCase ])->post('/api/v1/projects', $data); $response->assertStatus(200); + + $arr = $response->json(); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->put('/api/v1/projects/'.$arr['data']['id'], $data)->assertStatus(200); + + try{ + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/projects', $data); + } + catch(ValidationException $e){ + $response->assertStatus(302); + } + + + } public function testProjectPut()