Add local setup for S3

This commit is contained in:
Constantin Graf
2024-09-09 22:30:24 +02:00
committed by Constantin Graf
parent fc614b796c
commit 9a8945b0dc
9 changed files with 115 additions and 18 deletions

View File

@@ -81,13 +81,13 @@ class ExportEndpointTest extends ApiEndpointTestAbstract
Passport::actingAs($user->user);
// Act
$response = $this->postJson(route('api.v1.export.export', ['organization' => $user->organization->getKey()]));
$response = $this->postJson(route('api.v1.export.export', [
'organization' => $user->organization->getKey(),
]));
// Assert
$response->assertStatus(200);
$response->assertExactJson([
'success' => true,
'download_url' => Storage::disk('local')->temporaryUrl($filepath, $now->addMinutes(10)),
]);
$response->assertJsonPath('success', true);
$this->assertStringContainsString($filepath, $response->json('download_url'));
}
}

View File

@@ -261,10 +261,11 @@ class DeletionServiceTest extends TestCaseWithDatabase
public function test_delete_user_deletes_all_resources_of_the_user_but_does_not_delete_other_resources(): void
{
// Arrange
$this->mockPublicStorage();
$user = User::factory()->withProfilePicture()->withPersonalOrganization()->create();
$otherUser = User::factory()->withProfilePicture()->withPersonalOrganization()->create();
Storage::disk('public')->assertExists($user->profile_photo_path);
Storage::disk('public')->assertExists($otherUser->profile_photo_path);
Storage::disk(config('filesystems.public'))->assertExists($user->profile_photo_path);
Storage::disk(config('filesystems.public'))->assertExists($otherUser->profile_photo_path);
// Act
$this->deletionService->deleteUser($user);
@@ -288,8 +289,8 @@ class DeletionServiceTest extends TestCaseWithDatabase
$this->assertDatabaseMissing(Member::class, [
'user_id' => $user->getKey(),
]);
Storage::disk('public')->assertMissing($user->profile_photo_path);
Storage::disk('public')->assertExists($otherUser->profile_photo_path);
Storage::disk(config('filesystems.public'))->assertMissing($user->profile_photo_path);
Storage::disk(config('filesystems.public'))->assertExists($otherUser->profile_photo_path);
Log::assertLoggedTimes(fn (LogEntry $log) => $log->level === 'debug'
&& $log->message === 'Start deleting user'
&& $log->context['id'] === $user->getKey(),

View File

@@ -53,6 +53,7 @@ class ExportServiceTest extends TestCaseWithDatabase
public function test_export_creates_zip_with_all_the_data_of_the_organization(): void
{
// Arrange
$this->mockPrivateStorage();
$organization1 = $this->getFullOrganization();
$organization2 = $this->getFullOrganization();
@@ -61,6 +62,6 @@ class ExportServiceTest extends TestCaseWithDatabase
$zip = $exportService->export($organization1);
// Assert
Storage::disk('local')->assertExists($zip);
Storage::disk(config('filesystems.default'))->assertExists($zip);
}
}

View File

@@ -8,6 +8,7 @@ use App\Models\Organization;
use App\Service\Import\Importers\DefaultImporter;
use App\Service\Import\Importers\ImportException;
use App\Service\Import\Importers\TogglTimeEntriesImporter;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
@@ -28,10 +29,14 @@ class TogglTimeEntriesImporterTest extends ImporterTestAbstract
$data = Storage::disk('testfiles')->get('toggl_time_entries_import_test_1.csv');
// Act
DB::enableQueryLog();
DB::flushQueryLog();
$importer->importData($data, $timezone);
$report = $importer->getReport();
$queryLog = DB::getQueryLog();
// Assert
$this->assertCount(31, $queryLog);
$testScenario = $this->checkTestScenarioAfterImportExcludingTimeEntries();
$this->checkTimeEntries($testScenario);
$this->assertSame(2, $report->timeEntriesCreated);
@@ -55,10 +60,14 @@ class TogglTimeEntriesImporterTest extends ImporterTestAbstract
$importer->init($organization);
// Act
DB::enableQueryLog();
DB::flushQueryLog();
$importer->importData($data, $timezone);
$report = $importer->getReport();
$queryLog = DB::getQueryLog();
// Assert
$this->assertCount(15, $queryLog);
$testScenario = $this->checkTestScenarioAfterImportExcludingTimeEntries();
$this->checkTimeEntries($testScenario, true);
$this->assertSame(2, $report->timeEntriesCreated);