diff --git a/app/Http/Requests/Client/StoreClientRequest.php b/app/Http/Requests/Client/StoreClientRequest.php index 66aa798b0ad7..46b8bf9a2a96 100644 --- a/app/Http/Requests/Client/StoreClientRequest.php +++ b/app/Http/Requests/Client/StoreClientRequest.php @@ -94,6 +94,7 @@ class StoreClientRequest extends Request $rules['number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)]; $rules['id_number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)]; $rules['classification'] = 'bail|sometimes|nullable|in:individual,business,company,partnership,trust,charity,government,other'; + $rules['documents'] = 'bail|sometimes|array'; return $rules; } diff --git a/app/Http/Requests/Client/UpdateClientRequest.php b/app/Http/Requests/Client/UpdateClientRequest.php index b891731cbd23..26ae1f517d57 100644 --- a/app/Http/Requests/Client/UpdateClientRequest.php +++ b/app/Http/Requests/Client/UpdateClientRequest.php @@ -84,6 +84,8 @@ class UpdateClientRequest extends Request //'regex:/[@$!%*#?&.]/', // must contain a special character ]; + $rules['documents'] = 'bail|sometimes|array'; + return $rules; } diff --git a/tests/Feature/ClientApiTest.php b/tests/Feature/ClientApiTest.php index 882fd3cdd459..0d08a8642b10 100644 --- a/tests/Feature/ClientApiTest.php +++ b/tests/Feature/ClientApiTest.php @@ -59,6 +59,78 @@ class ClientApiTest extends TestCase Model::reguard(); } + public function testDocumentValidation() + { + $data = [ + 'name' => 'name of client', + 'documents' => [], + ]; + + $response = $this->withHeaders([ + 'X-API-TOKEN' => $this->token, + ])->postJson("/api/v1/clients",$data) + ->assertStatus(200); + + } + + public function testDocumentValidationFails() + { + $data = [ + 'name' => 'name of client', + 'documents' => 'wut', + ]; + + $response = $this->withHeaders([ + 'X-API-TOKEN' => $this->token, + ])->postJson("/api/v1/clients", $data) + ->assertStatus(422); + + $data = [ + 'name' => 'name of client', + 'documents' => null, + ]; + + $response = $this->withHeaders([ + 'X-API-TOKEN' => $this->token, + ])->postJson("/api/v1/clients", $data) + ->assertStatus(422); + + } + + public function testDocumentValidationPutFails() + { + $data = [ + 'name' => 'name of client', + 'documents' => 'wut', + ]; + + $response = $this->withHeaders([ + 'X-API-TOKEN' => $this->token, + ])->putJson("/api/v1/clients/{$this->client->hashed_id}", $data) + ->assertStatus(422); + + $data = [ + 'name' => 'name of client', + 'documents' => null, + ]; + + $response = $this->withHeaders([ + 'X-API-TOKEN' => $this->token, + ])->putJson("/api/v1/clients/{$this->client->hashed_id}", $data) + ->assertStatus(422); + + $data = [ + 'name' => 'name of client', + 'documents' => [], + ]; + + $response = $this->withHeaders([ + 'X-API-TOKEN' => $this->token, + ])->putJson("/api/v1/clients/{$this->client->hashed_id}", $data) + ->assertStatus(200); + + } + public function testClientDocumentQuery() {