mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Validation for project budgeted hours
This commit is contained in:
parent
c705784137
commit
58fabe2704
@ -44,6 +44,7 @@ class StoreProjectRequest extends Request
|
|||||||
|
|
||||||
$rules['name'] = 'required';
|
$rules['name'] = 'required';
|
||||||
$rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id;
|
$rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id;
|
||||||
|
$rules['budgeted_hours'] = 'sometimes|numeric';
|
||||||
|
|
||||||
if (isset($this->number)) {
|
if (isset($this->number)) {
|
||||||
$rules['number'] = Rule::unique('projects')->where('company_id', $user->company()->id);
|
$rules['number'] = Rule::unique('projects')->where('company_id', $user->company()->id);
|
||||||
@ -74,6 +75,9 @@ class StoreProjectRequest extends Request
|
|||||||
$input['color'] = '';
|
$input['color'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(array_key_exists('budgeted_hours', $input) && empty($input['budgeted_hours']))
|
||||||
|
$input['budgeted_hours'] = 0;
|
||||||
|
|
||||||
$this->replace($input);
|
$this->replace($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,8 @@ class UpdateProjectRequest extends Request
|
|||||||
$rules['number'] = Rule::unique('projects')->where('company_id', $user->company()->id)->ignore($this->project->id);
|
$rules['number'] = Rule::unique('projects')->where('company_id', $user->company()->id)->ignore($this->project->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$rules['budgeted_hours'] = 'sometimes|numeric';
|
||||||
|
|
||||||
if ($this->file('documents') && is_array($this->file('documents'))) {
|
if ($this->file('documents') && is_array($this->file('documents'))) {
|
||||||
$rules['documents.*'] = $this->file_validation;
|
$rules['documents.*'] = $this->file_validation;
|
||||||
} elseif ($this->file('documents')) {
|
} elseif ($this->file('documents')) {
|
||||||
@ -73,6 +75,10 @@ class UpdateProjectRequest extends Request
|
|||||||
if (array_key_exists('color', $input) && is_null($input['color'])) {
|
if (array_key_exists('color', $input) && is_null($input['color'])) {
|
||||||
$input['color'] = '';
|
$input['color'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(array_key_exists('budgeted_hours', $input) && empty($input['budgeted_hours'])) {
|
||||||
|
$input['budgeted_hours'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
$this->replace($input);
|
$this->replace($input);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ class ProjectApiTest extends TestCase
|
|||||||
use DatabaseTransactions;
|
use DatabaseTransactions;
|
||||||
use MockAccountData;
|
use MockAccountData;
|
||||||
|
|
||||||
|
protected $faker;
|
||||||
|
|
||||||
protected function setUp() :void
|
protected function setUp() :void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@ -42,6 +44,110 @@ class ProjectApiTest extends TestCase
|
|||||||
Model::reguard();
|
Model::reguard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testProjectValidationForBudgetedHoursPut()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = $this->project->toArray();
|
||||||
|
$data['budgeted_hours'] = "aa";
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->putJson("/api/v1/projects/{$this->project->hashed_id}", $data);
|
||||||
|
|
||||||
|
$response->assertStatus(422);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testProjectValidationForBudgetedHoursPutNull()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = $this->project->toArray();
|
||||||
|
$data['budgeted_hours'] = null;
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->putJson("/api/v1/projects/{$this->project->hashed_id}", $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testProjectValidationForBudgetedHoursPutEmpty()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = $this->project->toArray();
|
||||||
|
$data['budgeted_hours'] = "";
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->putJson("/api/v1/projects/{$this->project->hashed_id}", $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testProjectValidationForBudgetedHours()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->firstName(),
|
||||||
|
'client_id' => $this->client->hashed_id,
|
||||||
|
'number' => 'duplicate',
|
||||||
|
'budgeted_hours' => null
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/projects', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testProjectValidationForBudgetedHours2()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->firstName(),
|
||||||
|
'client_id' => $this->client->hashed_id,
|
||||||
|
'number' => 'duplicate',
|
||||||
|
'budgeted_hours' => "a"
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/projects', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(422);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testProjectValidationForBudgetedHours3()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->firstName(),
|
||||||
|
'client_id' => $this->client->hashed_id,
|
||||||
|
'number' => 'duplicate',
|
||||||
|
'budgeted_hours' => ""
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/projects', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function testProjectGetFilter()
|
public function testProjectGetFilter()
|
||||||
{
|
{
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
|
@ -72,6 +72,11 @@ trait MockAccountData
|
|||||||
use MakesHash;
|
use MakesHash;
|
||||||
use GeneratesCounter;
|
use GeneratesCounter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var
|
||||||
|
*/
|
||||||
|
public $project;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var
|
* @var
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user