mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-13 00:03:18 +01:00
add time entry filter normalizeation
This commit is contained in:
@@ -606,6 +606,51 @@ class ReportEndpointTest extends ApiEndpointTestAbstract
|
||||
);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_stores_empty_id_filters_as_null(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:create',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.reports.store', [$data->organization->getKey()]), [
|
||||
'name' => 'Test Report with empty Filters',
|
||||
'is_public' => false,
|
||||
'properties' => [
|
||||
'start' => Carbon::now()->subDays(30)->toIso8601ZuluString(),
|
||||
'end' => Carbon::now()->toIso8601ZuluString(),
|
||||
'group' => TimeEntryAggregationType::Project->value,
|
||||
'sub_group' => TimeEntryAggregationType::Task->value,
|
||||
'history_group' => TimeEntryAggregationType::Day->value,
|
||||
'member_ids' => [],
|
||||
'project_ids' => [],
|
||||
'client_ids' => [],
|
||||
'tag_ids' => [],
|
||||
'task_ids' => [],
|
||||
],
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(201);
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->where('data.properties.member_ids', null)
|
||||
->where('data.properties.project_ids', null)
|
||||
->where('data.properties.client_ids', null)
|
||||
->where('data.properties.tag_ids', null)
|
||||
->where('data.properties.task_ids', null)
|
||||
->etc()
|
||||
);
|
||||
/** @var Report $report */
|
||||
$report = Report::query()->findOrFail($response->json('data.id'));
|
||||
$this->assertNull($report->properties->memberIds);
|
||||
$this->assertNull($report->properties->projectIds);
|
||||
$this->assertNull($report->properties->clientIds);
|
||||
$this->assertNull($report->properties->tagIds);
|
||||
$this->assertNull($report->properties->taskIds);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_creates_report_with_none_filter_values(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -88,4 +88,25 @@ class ReportPropertiesDtoTest extends TestCase
|
||||
$this->assertSame(TimeEntryType::Work, $dtoWork->timeEntryType);
|
||||
$this->assertSame(TimeEntryType::Break, $dtoBreak->timeEntryType);
|
||||
}
|
||||
|
||||
public function test_empty_id_filters_of_a_persisted_report_are_read_as_null(): void
|
||||
{
|
||||
// Arrange
|
||||
$properties = $this->getBaseProperties();
|
||||
$properties['memberIds'] = [];
|
||||
$properties['clientIds'] = [];
|
||||
$properties['projectIds'] = [];
|
||||
$properties['tagIds'] = [];
|
||||
$properties['taskIds'] = [];
|
||||
|
||||
// Act
|
||||
$dto = $this->castFromJson($properties);
|
||||
|
||||
// Assert
|
||||
$this->assertNull($dto->memberIds);
|
||||
$this->assertNull($dto->clientIds);
|
||||
$this->assertNull($dto->projectIds);
|
||||
$this->assertNull($dto->tagIds);
|
||||
$this->assertNull($dto->taskIds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,6 +416,81 @@ class TimeEntryFilterTest extends TestCaseWithDatabase
|
||||
$this->assertCount(3, $builderContains->get());
|
||||
}
|
||||
|
||||
public function test_add_member_ids_filter_with_empty_array_applies_no_filter(): void
|
||||
{
|
||||
// Arrange
|
||||
TimeEntry::factory()->createMany(2);
|
||||
|
||||
$builder = TimeEntry::query();
|
||||
$filter = new TimeEntryFilter($builder);
|
||||
|
||||
// Act
|
||||
$filter->addMemberIdsFilter([]);
|
||||
|
||||
// Assert
|
||||
$this->assertCount(2, $builder->get());
|
||||
}
|
||||
|
||||
public function test_add_project_ids_filter_with_empty_array_applies_no_filter(): void
|
||||
{
|
||||
// Arrange
|
||||
$project = Project::factory()->create();
|
||||
TimeEntry::factory()->create([
|
||||
'project_id' => $project->getKey(),
|
||||
'organization_id' => $project->organization_id,
|
||||
]);
|
||||
TimeEntry::factory()->create(['project_id' => null]);
|
||||
|
||||
$builder = TimeEntry::query();
|
||||
$filter = new TimeEntryFilter($builder);
|
||||
|
||||
// Act
|
||||
$filter->addProjectIdsFilter([]);
|
||||
|
||||
// Assert
|
||||
$this->assertCount(2, $builder->get());
|
||||
}
|
||||
|
||||
public function test_add_task_ids_filter_with_empty_array_applies_no_filter(): void
|
||||
{
|
||||
// Arrange
|
||||
$task = Task::factory()->create();
|
||||
TimeEntry::factory()->create([
|
||||
'task_id' => $task->getKey(),
|
||||
'organization_id' => $task->organization_id,
|
||||
]);
|
||||
TimeEntry::factory()->create(['task_id' => null]);
|
||||
|
||||
$builder = TimeEntry::query();
|
||||
$filter = new TimeEntryFilter($builder);
|
||||
|
||||
// Act
|
||||
$filter->addTaskIdsFilter([]);
|
||||
|
||||
// Assert
|
||||
$this->assertCount(2, $builder->get());
|
||||
}
|
||||
|
||||
public function test_add_client_ids_filter_with_empty_array_applies_no_filter(): void
|
||||
{
|
||||
// Arrange
|
||||
$client = Client::factory()->create();
|
||||
TimeEntry::factory()->create([
|
||||
'client_id' => $client->getKey(),
|
||||
'organization_id' => $client->organization_id,
|
||||
]);
|
||||
TimeEntry::factory()->create(['client_id' => null]);
|
||||
|
||||
$builder = TimeEntry::query();
|
||||
$filter = new TimeEntryFilter($builder);
|
||||
|
||||
// Act
|
||||
$filter->addClientIdsFilter([]);
|
||||
|
||||
// Assert
|
||||
$this->assertCount(2, $builder->get());
|
||||
}
|
||||
|
||||
public function test_add_tag_ids_filter_with_null_match_type_defaults_to_contains(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Reference in New Issue
Block a user