1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Additional tests for project task rates

This commit is contained in:
David Bomba 2024-07-08 09:20:05 +10:00
parent bfac91851a
commit 1a5a70688e
2 changed files with 113 additions and 2 deletions

View File

@ -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);
}

View File

@ -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()
{