mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-11 17:52:15 +01:00
Added aggregate time entries endpoint
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Endpoint\Api\V1;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\TimeEntry;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
@@ -384,6 +385,92 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
);
|
||||
}
|
||||
|
||||
public function test_aggregate_endpoint_fails_if_user_has_no_permission_to_view_time_entries(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.time-entries.aggregate', [$data->organization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_aggregate_endpoint_groups_by_two_groups(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:view:all',
|
||||
]);
|
||||
$timeEntries = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->createMany(3);
|
||||
$project = Project::factory()->forOrganization($data->organization)->create();
|
||||
$timeEntries = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->forProject($project)->createMany(3);
|
||||
$timeEntries = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->state([
|
||||
'start' => $timeEntries->get(0)->start,
|
||||
])->createMany(3);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.time-entries.aggregate', [
|
||||
$data->organization->getKey(),
|
||||
'group_1' => 'day',
|
||||
'group_2' => 'project',
|
||||
]));
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_aggregate_endpoint_groups_by_one_group(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:view:all',
|
||||
]);
|
||||
$timeEntries = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->createMany(3);
|
||||
$project = Project::factory()->forOrganization($data->organization)->create();
|
||||
$timeEntries = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->forProject($project)->createMany(3);
|
||||
$timeEntries = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->state([
|
||||
'start' => $timeEntries->get(0)->start,
|
||||
])->createMany(3);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.time-entries.aggregate', [
|
||||
$data->organization->getKey(),
|
||||
'group_1' => 'week',
|
||||
]));
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_aggregate_endpoint_with_no_group(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:view:all',
|
||||
]);
|
||||
$timeEntries = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->createMany(3);
|
||||
$project = Project::factory()->forOrganization($data->organization)->create();
|
||||
$timeEntries = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->forProject($project)->createMany(3);
|
||||
$timeEntries = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->state([
|
||||
'start' => $timeEntries->get(0)->start,
|
||||
])->createMany(3);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.time-entries.aggregate', [
|
||||
$data->organization->getKey(),
|
||||
]));
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_store_endpoint_fails_if_user_has_no_permission_to_create_time_entries(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -6,8 +6,10 @@ namespace Tests\Unit\Model;
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectMember;
|
||||
use App\Models\Task;
|
||||
use App\Models\TimeEntry;
|
||||
use App\Models\User;
|
||||
|
||||
class TaskModelTest extends ModelTestAbstract
|
||||
{
|
||||
@@ -56,4 +58,32 @@ class TaskModelTest extends ModelTestAbstract
|
||||
// Assert
|
||||
$this->assertCount(3, $timeEntries);
|
||||
}
|
||||
|
||||
public function test_scope_visible_by_user_filters_so_that_only_tasks_of_public_projects_or_projects_where_the_user_is_member_are_shown(): void
|
||||
{
|
||||
// Arrange
|
||||
$user = User::factory()->create();
|
||||
$projectPrivate = Project::factory()->isPrivate()->create();
|
||||
$projectPublic = Project::factory()->isPublic()->create();
|
||||
$projectPrivateButMember = Project::factory()->isPrivate()->create();
|
||||
ProjectMember::factory()->forProject($projectPrivateButMember)->forUser($user)->create();
|
||||
$taskPrivate = Task::factory()->forProject($projectPrivate)->create();
|
||||
$taskPublic = Task::factory()->forProject($projectPublic)->create();
|
||||
$taskPrivateButMember = Task::factory()->forProject($projectPrivateButMember)->create();
|
||||
|
||||
// Act
|
||||
$tasksVisible = Task::query()->visibleByUser($user)->get();
|
||||
$allTasks = Task::query()->get();
|
||||
|
||||
// Assert
|
||||
$this->assertEqualsIdsOfEloquentCollection([
|
||||
$taskPublic->getKey(),
|
||||
$taskPrivateButMember->getKey(),
|
||||
], $tasksVisible);
|
||||
$this->assertEqualsIdsOfEloquentCollection([
|
||||
$taskPrivate->getKey(),
|
||||
$taskPublic->getKey(),
|
||||
$taskPrivateButMember->getKey(),
|
||||
], $allTasks);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user