diff --git a/app/Service/Import/Importers/ClockifyProjectsImporter.php b/app/Service/Import/Importers/ClockifyProjectsImporter.php index fa0188f2..5c41c0a3 100644 --- a/app/Service/Import/Importers/ClockifyProjectsImporter.php +++ b/app/Service/Import/Importers/ClockifyProjectsImporter.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Service\Import\Importers; use Exception; +use Illuminate\Support\Carbon; use Illuminate\Support\Str; use League\Csv\Exception as CsvException; use League\Csv\Reader; @@ -44,6 +45,7 @@ class ClockifyProjectsImporter extends DefaultImporter 'is_billable' => $record['Billability'] === 'Yes', 'billable_rate' => $billableRateKey !== null && $record[$billableRateKey] !== '' ? (int) (((float) $record[$billableRateKey]) * 100) : null, 'estimated_time' => $record['Estimated (h)'] !== '' && is_numeric($record['Estimated (h)']) ? (int) ($record['Estimated (h)'] * 3600) : null, + 'archived_at' => $record['Status'] === 'Archived' ? Carbon::now() : null, ]); } diff --git a/resources/testfiles/clockify_projects_import_test_2.csv b/resources/testfiles/clockify_projects_import_test_2.csv new file mode 100644 index 00000000..40fabe0f --- /dev/null +++ b/resources/testfiles/clockify_projects_import_test_2.csv @@ -0,0 +1,3 @@ +"Project","Client","Status","Visibility","Billability","Task","Tracked (h)","Estimated (h)","Remaining (h)","Overage (h)","Progress(%)","Billable (h)","Non-billable (h)","Billable Rate (USD)","Amount (USD)","Project members","Project manager","Note" +"Active Project","Big Company","Active","Public","Yes","Task 1, Task 2","0.00","100.00","","","","0.00","0.00","100.01","0.00","Constantin Graf","","" +"Archived Project","","Archived","Public","Yes","","0.00","","","","","0.00","0.00","","0.00","Constantin Graf","","" diff --git a/tests/Unit/Service/Import/Importers/ClockifyProjectsImporterTest.php b/tests/Unit/Service/Import/Importers/ClockifyProjectsImporterTest.php index 4e848316..1b313717 100644 --- a/tests/Unit/Service/Import/Importers/ClockifyProjectsImporterTest.php +++ b/tests/Unit/Service/Import/Importers/ClockifyProjectsImporterTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Tests\Unit\Service\Import\Importers; use App\Models\Organization; +use App\Models\Project; use App\Service\Import\Importers\ClockifyProjectsImporter; use App\Service\Import\Importers\DefaultImporter; use App\Service\Import\Importers\ImportException; @@ -50,4 +51,26 @@ class ClockifyProjectsImporterTest extends ImporterTestAbstract // Assert $this->checkTestScenarioProjectsOnlyAfterImport(); } + + public function test_import_sets_archived_at_based_on_status_column(): void + { + // Arrange + $organization = Organization::factory()->create(); + $timezone = 'Europe/Vienna'; + $importer = new ClockifyProjectsImporter; + $importer->init($organization); + $data = Storage::disk('testfiles')->get('clockify_projects_import_test_2.csv'); + + // Act + $importer->importData($data, $timezone); + + // Assert + $activeProject = Project::query()->where('organization_id', $organization->id)->where('name', 'Active Project')->firstOrFail(); + $this->assertNull($activeProject->archived_at); + $this->assertFalse($activeProject->is_archived); + + $archivedProject = Project::query()->where('organization_id', $organization->id)->where('name', 'Archived Project')->firstOrFail(); + $this->assertNotNull($archivedProject->archived_at); + $this->assertTrue($archivedProject->is_archived); + } }