Lock import and increase timeout

This commit is contained in:
Constantin Graf
2024-09-17 22:17:19 +02:00
committed by Constantin Graf
parent 5c6b32d5bb
commit d4e71e7c2c
4 changed files with 34 additions and 4 deletions

View File

@@ -6,8 +6,10 @@ namespace Tests\Unit\Service\Import;
use App\Models\Organization;
use App\Service\Import\Importers\ImporterProvider;
use App\Service\Import\Importers\ImportException;
use App\Service\Import\ImportService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
@@ -40,4 +42,23 @@ class ImportServiceTest extends TestCase
$this->assertSame(2, $report->projectsCreated);
$this->assertSame(1, $report->clientsCreated);
}
public function test_import_throws_exception_if_import_is_already_in_progress(): void
{
// Arrange
Storage::fake(config('filesystems.default'));
$organization = Organization::factory()->create();
$timezone = 'Europe/Vienna';
$data = Storage::disk('testfiles')->get('toggl_time_entries_import_test_1.csv');
Cache::lock('import:'.$organization->getKey(), 10)->get();
// Act
$importService = app(ImportService::class);
try {
$importService->import($organization, 'toggl_time_entries', $data, $timezone);
} catch (ImportException $e) {
// Assert
$this->assertSame('Import is already in progress', $e->getMessage());
}
}
}