mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
Add ability to set task to done, fixes ST-244
This commit is contained in:
committed by
Gregor Vostrak
parent
75e739f6fb
commit
364168debd
@@ -9,6 +9,7 @@ use App\Models\Project;
|
||||
use App\Models\ProjectMember;
|
||||
use App\Models\Task;
|
||||
use App\Models\TimeEntry;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Laravel\Passport\Passport;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
|
||||
@@ -76,6 +77,85 @@ class TaskEndpointTest extends ApiEndpointTestAbstract
|
||||
$response->assertJsonCount(4, 'data');
|
||||
}
|
||||
|
||||
public function test_index_endpoint_without_filter_done_returns_list_of_all_tasks_of_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tasks:view',
|
||||
'tasks:view:all',
|
||||
]);
|
||||
$notDoneTasks = Task::factory()->forOrganization($data->organization)->createMany(2);
|
||||
$doneTasks = Task::factory()->forOrganization($data->organization)->isDone()->createMany(2);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.tasks.index', [$data->organization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonCount(2, 'data');
|
||||
$this->assertEqualsCanonicalizing($notDoneTasks->pluck('id')->toArray(), $response->json('data.*.id'));
|
||||
}
|
||||
|
||||
public function test_index_endpoint_with_filter_done_true_returns_list_of_all_done_tasks_of_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tasks:view',
|
||||
'tasks:view:all',
|
||||
]);
|
||||
$notDoneTasks = Task::factory()->forOrganization($data->organization)->createMany(2);
|
||||
$doneTasks = Task::factory()->forOrganization($data->organization)->isDone()->createMany(2);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.tasks.index', [$data->organization->getKey(), 'done' => 'true']));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonCount(2, 'data');
|
||||
$this->assertEqualsCanonicalizing($doneTasks->pluck('id')->toArray(), $response->json('data.*.id'));
|
||||
}
|
||||
|
||||
public function test_index_endpoint_with_filter_done_false_returns_list_of_all_not_done_tasks_of_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tasks:view',
|
||||
'tasks:view:all',
|
||||
]);
|
||||
$notDoneTasks = Task::factory()->forOrganization($data->organization)->createMany(2);
|
||||
$doneTasks = Task::factory()->forOrganization($data->organization)->isDone()->createMany(2);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.tasks.index', [$data->organization->getKey(), 'done' => 'false']));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonCount(2, 'data');
|
||||
$this->assertEqualsCanonicalizing($notDoneTasks->pluck('id')->toArray(), $response->json('data.*.id'));
|
||||
}
|
||||
|
||||
public function test_index_endpoint_with_filter_done_all_returns_list_of_all_tasks_of_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tasks:view',
|
||||
'tasks:view:all',
|
||||
]);
|
||||
$notDoneTasks = Task::factory()->forOrganization($data->organization)->createMany(2);
|
||||
$doneTasks = Task::factory()->forOrganization($data->organization)->isDone()->createMany(2);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.tasks.index', [$data->organization->getKey(), 'done' => 'all']));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonCount(4, 'data');
|
||||
}
|
||||
|
||||
public function test_index_endpoint_returns_list_of_all_tasks_with_access_of_organization_if_user_has_no_all_permission(): void
|
||||
{
|
||||
// Arrange
|
||||
@@ -395,6 +475,54 @@ class TaskEndpointTest extends ApiEndpointTestAbstract
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_can_set_task_to_done(): void
|
||||
{
|
||||
// Arrange
|
||||
$now = Carbon::now();
|
||||
$this->travelTo($now);
|
||||
$data = $this->createUserWithPermission([
|
||||
'tasks:update',
|
||||
]);
|
||||
$task = Task::factory()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.tasks.update', [$data->organization->getKey(), $task->getKey()]), [
|
||||
'name' => $task->name,
|
||||
'is_done' => true,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$this->assertDatabaseHas(Task::class, [
|
||||
'id' => $task->getKey(),
|
||||
'done_at' => $now->toDateTimeString(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_can_set_task_to_not_done(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tasks:update',
|
||||
]);
|
||||
$task = Task::factory()->forOrganization($data->organization)->isDone()->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.tasks.update', [$data->organization->getKey(), $task->getKey()]), [
|
||||
'name' => $task->name,
|
||||
'is_done' => false,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$this->assertDatabaseHas(Task::class, [
|
||||
'id' => $task->getKey(),
|
||||
'done_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_delete_endpoint_deletes_tasks_if_user_has_permission(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Reference in New Issue
Block a user