mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
Make name fields in projects, tasks, clients and tags unique; fixes ST-265
This commit is contained in:
committed by
Gregor Vostrak
parent
313cee2db0
commit
512089ccbd
@@ -33,8 +33,7 @@ class TaskEndpointTest extends ApiEndpointTestAbstract
|
||||
public function test_index_endpoint_fails_if_user_has_no_permission_to_view_tasks(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
]);
|
||||
$data = $this->createUserWithPermission();
|
||||
Task::factory()->forOrganization($data->organization)->createMany(4);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
@@ -48,8 +47,7 @@ class TaskEndpointTest extends ApiEndpointTestAbstract
|
||||
public function test_index_endpoint_validation_fails_if_project_id_is_not_pat(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
]);
|
||||
$data = $this->createUserWithPermission();
|
||||
Task::factory()->forOrganization($data->organization)->createMany(4);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
@@ -199,8 +197,7 @@ class TaskEndpointTest extends ApiEndpointTestAbstract
|
||||
public function test_store_endpoint_fails_if_user_has_no_permission_to_create_tasks()
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
]);
|
||||
$data = $this->createUserWithPermission();
|
||||
$project = Project::factory()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
@@ -217,6 +214,59 @@ class TaskEndpointTest extends ApiEndpointTestAbstract
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_fails_if_task_with_same_name_already_exists_in_same_project(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tasks:create',
|
||||
]);
|
||||
$project = Project::factory()->forOrganization($data->organization)->create();
|
||||
$task = Task::factory()->forOrganization($data->organization)->forProject($project)->create([
|
||||
'name' => 'Task 1',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.tasks.store', [$data->organization->getKey()]), [
|
||||
'name' => $task->name,
|
||||
'project_id' => $project->getKey(),
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors([
|
||||
'name' => 'A task with the same name already exists in the project.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_creates_new_task_even_if_task_with_same_name_already_exists_in_other_project(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tasks:create',
|
||||
]);
|
||||
$project = Project::factory()->forOrganization($data->organization)->create();
|
||||
$otherProject = Project::factory()->forOrganization($data->organization)->create();
|
||||
$task = Task::factory()->forOrganization($data->organization)->forProject($otherProject)->create([
|
||||
'name' => 'Task 1',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.tasks.store', [$data->organization->getKey()]), [
|
||||
'name' => $task->name,
|
||||
'project_id' => $project->getKey(),
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(201);
|
||||
$this->assertDatabaseHas(Task::class, [
|
||||
'name' => $task->name,
|
||||
'project_id' => $project->getKey(),
|
||||
'organization_id' => $data->organization->getKey(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_creates_new_task_if_user_has_permission_to_create_tasks()
|
||||
{
|
||||
// Arrange
|
||||
@@ -244,8 +294,7 @@ class TaskEndpointTest extends ApiEndpointTestAbstract
|
||||
public function test_update_endpoint_fails_if_user_has_no_permission(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
]);
|
||||
$data = $this->createUserWithPermission();
|
||||
$task = Task::factory()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
@@ -266,6 +315,64 @@ class TaskEndpointTest extends ApiEndpointTestAbstract
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_fails_if_task_with_same_name_already_exists_in_same_project(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tasks:update',
|
||||
]);
|
||||
$project = Project::factory()->forOrganization($data->organization)->create();
|
||||
$name = 'Task 1';
|
||||
$task = Task::factory()->forProject($project)->forOrganization($data->organization)->create([
|
||||
'name' => $name,
|
||||
]);
|
||||
$otherTask = Task::factory()->forProject($project)->forOrganization($data->organization)->create([
|
||||
'name' => $name,
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.tasks.update', [$data->organization->getKey(), $task->getKey()]), [
|
||||
'name' => $name,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors([
|
||||
'name' => 'A task with the same name already exists in the project.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_updates_task_if_task_with_same_name_already_exists_in_other_project(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tasks:update',
|
||||
]);
|
||||
$project = Project::factory()->forOrganization($data->organization)->create();
|
||||
$otherProject = Project::factory()->forOrganization($data->organization)->create();
|
||||
$name = 'Task 1';
|
||||
$task = Task::factory()->forProject($project)->forOrganization($data->organization)->create([
|
||||
'name' => $name,
|
||||
]);
|
||||
$otherTask = Task::factory()->forProject($otherProject)->forOrganization($data->organization)->create([
|
||||
'name' => $name,
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.tasks.update', [$data->organization->getKey(), $task->getKey()]), [
|
||||
'name' => $name,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$this->assertDatabaseHas(Task::class, [
|
||||
'id' => $task->getKey(),
|
||||
'name' => $name,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_updates_task_if_user_has_permission(): void
|
||||
{
|
||||
// Arrange
|
||||
@@ -331,8 +438,7 @@ class TaskEndpointTest extends ApiEndpointTestAbstract
|
||||
public function test_delete_endpoint_fails_if_user_has_no_permission_to_delete_tasks(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
]);
|
||||
$data = $this->createUserWithPermission();
|
||||
$task = Task::factory()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user