mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 11:34:35 -04:00
Improvements for validation
This commit is contained in:
parent
ceb4708b5d
commit
478dbe5c4a
@ -94,6 +94,7 @@ class StoreClientRequest extends Request
|
|||||||
$rules['number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)];
|
$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['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['classification'] = 'bail|sometimes|nullable|in:individual,business,company,partnership,trust,charity,government,other';
|
||||||
|
$rules['documents'] = 'bail|sometimes|array';
|
||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,8 @@ class UpdateClientRequest extends Request
|
|||||||
//'regex:/[@$!%*#?&.]/', // must contain a special character
|
//'regex:/[@$!%*#?&.]/', // must contain a special character
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$rules['documents'] = 'bail|sometimes|array';
|
||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,78 @@ class ClientApiTest extends TestCase
|
|||||||
Model::reguard();
|
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()
|
public function testClientDocumentQuery()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user