mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 08:12:17 +01:00
Stricter validation for uuid and integer
This commit is contained in:
committed by
Constantin Graf
parent
2b1da883fb
commit
69d3ff4f7b
@@ -284,6 +284,60 @@ class ProjectEndpointTest extends ApiEndpointTestAbstract
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_store_endpoint_highest_possible_billable_rate_can_be_stored_in_database(): void
|
||||
{
|
||||
// Arrange
|
||||
$billableRate = 2147483647;
|
||||
$data = $this->createUserWithPermission([
|
||||
'projects:create',
|
||||
]);
|
||||
$projectFake = Project::factory()->forOrganization($data->organization)->make();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.projects.store', [$data->organization->getKey()]), [
|
||||
'name' => $projectFake->name,
|
||||
'color' => $projectFake->color,
|
||||
'is_billable' => $projectFake->is_billable,
|
||||
'billable_rate' => $billableRate,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(201);
|
||||
$this->assertDatabaseHas(Project::class, [
|
||||
'name' => $projectFake->name,
|
||||
'color' => $projectFake->color,
|
||||
'organization_id' => $projectFake->organization_id,
|
||||
'is_billable' => $projectFake->is_billable,
|
||||
'billable_rate' => $billableRate,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_fails_if_billable_rate_is_too_high(): void
|
||||
{
|
||||
// Arrange
|
||||
$billableRate = 2147483647 + 1;
|
||||
$data = $this->createUserWithPermission([
|
||||
'projects:create',
|
||||
]);
|
||||
$projectFake = Project::factory()->forOrganization($data->organization)->make();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.projects.store', [$data->organization->getKey()]), [
|
||||
'name' => $projectFake->name,
|
||||
'color' => $projectFake->color,
|
||||
'is_billable' => $projectFake->is_billable,
|
||||
'billable_rate' => $billableRate,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors([
|
||||
'billable_rate' => 'The billable rate field must not be greater than 2147483647.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_creates_new_project(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -958,6 +958,27 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_fails_gracefully_if_non_uuid_text_is_in_uuid_validated_field_in_body(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:create:own',
|
||||
]);
|
||||
$timeEntryFake = TimeEntry::factory()->withTask($data->organization)->forOrganization($data->organization)->make();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
|
||||
'member_id' => 'non-uuid-text',
|
||||
'tags' => ['non-uuid-text', 1],
|
||||
'project_id' => 'non-uuid-text',
|
||||
'task_id' => 'non-uuid-text',
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(422);
|
||||
}
|
||||
|
||||
public function test_store_endpoints_sets_billable_rate(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Reference in New Issue
Block a user