mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-13 18:52:14 +01:00
Added tasks endpoints; Added more test
This commit is contained in:
34
tests/Unit/Service/Import/ImportServiceTest.php
Normal file
34
tests/Unit/Service/Import/ImportServiceTest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Service\Import;
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Service\Import\ImportService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ImportServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_import_gets_importer_from_provider_runs_importer_and_returns_report(): void
|
||||
{
|
||||
// Arrange
|
||||
$organization = Organization::factory()->create();
|
||||
$data = file_get_contents(storage_path('tests/toggl_time_entries_import_test_1.csv'));
|
||||
|
||||
// Act
|
||||
$importService = app(ImportService::class);
|
||||
$report = $importService->import($organization, 'toggl_time_entries', $data);
|
||||
|
||||
// Assert
|
||||
$this->assertSame(2, $report->timeEntriesCreated);
|
||||
$this->assertSame(2, $report->tagsCreated);
|
||||
$this->assertSame(1, $report->tasksCreated);
|
||||
$this->assertSame(1, $report->usersCreated);
|
||||
$this->assertSame(2, $report->projectsCreated);
|
||||
$this->assertSame(1, $report->clientsCreated);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ class ClockifyProjectsImporterTest extends ImporterTestAbstract
|
||||
$data = file_get_contents(storage_path('tests/clockify_projects_import_test_1.csv'));
|
||||
|
||||
// Act
|
||||
$importer->importData($data, []);
|
||||
$importer->importData($data);
|
||||
|
||||
// Assert
|
||||
$this->checkTestScenarioProjectsOnlyAfterImport();
|
||||
@@ -31,12 +31,12 @@ class ClockifyProjectsImporterTest extends ImporterTestAbstract
|
||||
$importer = new ClockifyProjectsImporter();
|
||||
$importer->init($organization);
|
||||
$data = file_get_contents(storage_path('tests/clockify_projects_import_test_1.csv'));
|
||||
$importer->importData($data, []);
|
||||
$importer->importData($data);
|
||||
$importer = new ClockifyProjectsImporter();
|
||||
$importer->init($organization);
|
||||
|
||||
// Act
|
||||
$importer->importData($data, []);
|
||||
$importer->importData($data);
|
||||
|
||||
// Assert
|
||||
$this->checkTestScenarioProjectsOnlyAfterImport();
|
||||
|
||||
@@ -19,7 +19,7 @@ class ClockifyTimeEntriesImporterTest extends ImporterTestAbstract
|
||||
$data = file_get_contents(storage_path('tests/clockify_time_entries_import_test_1.csv'));
|
||||
|
||||
// Act
|
||||
$importer->importData($data, []);
|
||||
$importer->importData($data);
|
||||
|
||||
// Assert
|
||||
$testScenario = $this->checkTestScenarioAfterImportExcludingTimeEntries();
|
||||
@@ -48,12 +48,12 @@ class ClockifyTimeEntriesImporterTest extends ImporterTestAbstract
|
||||
$importer = new ClockifyTimeEntriesImporter();
|
||||
$importer->init($organization);
|
||||
$data = file_get_contents(storage_path('tests/clockify_time_entries_import_test_1.csv'));
|
||||
$importer->importData($data, []);
|
||||
$importer->importData($data);
|
||||
$importer = new ClockifyTimeEntriesImporter();
|
||||
$importer->init($organization);
|
||||
|
||||
// Act
|
||||
$importer->importData($data, []);
|
||||
$importer->importData($data);
|
||||
|
||||
// Assert
|
||||
$testScenario = $this->checkTestScenarioAfterImportExcludingTimeEntries();
|
||||
|
||||
@@ -38,9 +38,17 @@ class TogglDataImporterTest extends ImporterTestAbstract
|
||||
|
||||
// Act
|
||||
$importer->importData($data);
|
||||
$report = $importer->getReport();
|
||||
|
||||
// Assert
|
||||
$this->checkTestScenarioAfterImportExcludingTimeEntries();
|
||||
$this->assertSame(0, $report->timeEntriesCreated);
|
||||
$this->assertSame(2, $report->tagsCreated);
|
||||
$this->assertSame(1, $report->tasksCreated);
|
||||
$this->assertSame(1, $report->usersCreated);
|
||||
$this->assertSame(2, $report->projectsCreated);
|
||||
$this->assertSame(1, $report->clientsCreated);
|
||||
|
||||
}
|
||||
|
||||
public function test_import_of_test_file_twice_succeeds(): void
|
||||
@@ -57,8 +65,15 @@ class TogglDataImporterTest extends ImporterTestAbstract
|
||||
|
||||
// Act
|
||||
$importer->importData($data);
|
||||
$report = $importer->getReport();
|
||||
|
||||
// Assert
|
||||
$this->checkTestScenarioAfterImportExcludingTimeEntries();
|
||||
$this->assertSame(0, $report->timeEntriesCreated);
|
||||
$this->assertSame(0, $report->tagsCreated);
|
||||
$this->assertSame(0, $report->tasksCreated);
|
||||
$this->assertSame(0, $report->usersCreated);
|
||||
$this->assertSame(0, $report->projectsCreated);
|
||||
$this->assertSame(0, $report->clientsCreated);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ class TogglTimeEntriesImporterTest extends ImporterTestAbstract
|
||||
$data = file_get_contents(storage_path('tests/toggl_time_entries_import_test_1.csv'));
|
||||
|
||||
// Act
|
||||
$importer->importData($data, []);
|
||||
$importer->importData($data);
|
||||
$report = $importer->getReport();
|
||||
|
||||
// Assert
|
||||
$testScenario = $this->checkTestScenarioAfterImportExcludingTimeEntries();
|
||||
@@ -39,6 +40,12 @@ class TogglTimeEntriesImporterTest extends ImporterTestAbstract
|
||||
$this->assertSame('2024-03-04 11:23:01', $timeEntry2->end->toDateTimeString());
|
||||
$this->assertTrue($timeEntry2->billable);
|
||||
$this->assertSame([], $timeEntry2->tags);
|
||||
$this->assertSame(2, $report->timeEntriesCreated);
|
||||
$this->assertSame(2, $report->tagsCreated);
|
||||
$this->assertSame(1, $report->tasksCreated);
|
||||
$this->assertSame(1, $report->usersCreated);
|
||||
$this->assertSame(2, $report->projectsCreated);
|
||||
$this->assertSame(1, $report->clientsCreated);
|
||||
}
|
||||
|
||||
public function test_import_of_test_file_twice_succeeds(): void
|
||||
@@ -53,7 +60,8 @@ class TogglTimeEntriesImporterTest extends ImporterTestAbstract
|
||||
$importer->init($organization);
|
||||
|
||||
// Act
|
||||
$importer->importData($data, []);
|
||||
$importer->importData($data);
|
||||
$report = $importer->getReport();
|
||||
|
||||
// Assert
|
||||
$testScenario = $this->checkTestScenarioAfterImportExcludingTimeEntries();
|
||||
@@ -73,5 +81,11 @@ class TogglTimeEntriesImporterTest extends ImporterTestAbstract
|
||||
$this->assertSame('2024-03-04 11:23:01', $timeEntry2->end->toDateTimeString());
|
||||
$this->assertTrue($timeEntry2->billable);
|
||||
$this->assertSame([], $timeEntry2->tags);
|
||||
$this->assertSame(2, $report->timeEntriesCreated);
|
||||
$this->assertSame(0, $report->tagsCreated);
|
||||
$this->assertSame(0, $report->tasksCreated);
|
||||
$this->assertSame(0, $report->usersCreated);
|
||||
$this->assertSame(0, $report->projectsCreated);
|
||||
$this->assertSame(0, $report->clientsCreated);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,18 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Service;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Service\TimezoneService;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Tests\TestCase;
|
||||
use TiMacDonald\Log\LogEntry;
|
||||
|
||||
class TimezoneServiceTest extends TestCase
|
||||
{
|
||||
public function test_get_timezones_returns_all_available_timezones(): void
|
||||
{
|
||||
// Arrange
|
||||
$service = new \App\Service\TimezoneService();
|
||||
$service = app(TimezoneService::class);
|
||||
|
||||
// Act
|
||||
$result = $service->getTimezones();
|
||||
@@ -23,4 +27,42 @@ class TimezoneServiceTest extends TestCase
|
||||
$this->assertContains('Europe/Berlin', $result);
|
||||
$this->assertContains('Europe/London', $result);
|
||||
}
|
||||
|
||||
public function test_get_timezone_from_user_returns_timezone_of_user_as_carbon_timezone(): void
|
||||
{
|
||||
// Arrange
|
||||
$user = User::factory()->create([
|
||||
'timezone' => 'Europe/Berlin',
|
||||
]);
|
||||
|
||||
/** @var TimezoneService $service */
|
||||
$service = app(TimezoneService::class);
|
||||
|
||||
// Act
|
||||
$result = $service->getTimezoneFromUser($user);
|
||||
|
||||
// Assert
|
||||
$this->assertEquals('Europe/Berlin', $result->getName());
|
||||
}
|
||||
|
||||
public function test_get_timezone_from_user_falls_back_to_utc_and_logs_this_failure_if_timezone_in_db_is_corrupt(): void
|
||||
{
|
||||
// Arrange
|
||||
$corruptTimezone = 'Invalid/Timezone';
|
||||
$user = User::factory()->create([
|
||||
'timezone' => $corruptTimezone,
|
||||
]);
|
||||
|
||||
/** @var TimezoneService $service */
|
||||
$service = app(TimezoneService::class);
|
||||
|
||||
// Act
|
||||
$result = $service->getTimezoneFromUser($user);
|
||||
|
||||
// Assert
|
||||
$this->assertEquals('UTC', $result->getName());
|
||||
Log::assertLogged(fn (LogEntry $log) => $log->level === 'error'
|
||||
&& $log->message === 'User has a invalid timezone'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user