Wait for background import in e2e helper and fix coverage metadata of import and export tests

This commit is contained in:
Constantin Graf
2026-11-19 11:59:38 +01:00
committed by Constantin Graf
parent cbc7261a12
commit 463182666b
6 changed files with 63 additions and 2 deletions

View File

@@ -623,8 +623,25 @@ export async function createPlaceholderMemberViaImportApi(
},
}
);
expect(response.status()).toBe(200);
return await response.json();
expect(response.status()).toBe(202);
const body = await response.json();
const importId = body.data.id;
// Imports are processed in the background, wait until it is finished
await expect
.poll(
async () => {
const statusResponse = await ctx.request.get(
`${PLAYWRIGHT_BASE_URL}/api/v1/organizations/${ctx.orgId}/imports/${importId}`
);
expect(statusResponse.status()).toBe(200);
return (await statusResponse.json()).data.status;
},
{ timeout: 15000 }
)
.toBe('completed');
return body;
}
// ──────────────────────────────────────────────────

View File

@@ -16,6 +16,7 @@ use RuntimeException;
use Tests\TestCaseWithDatabase;
#[CoversClass(ProcessExport::class)]
#[CoversClass(ExportStatus::class)]
class ProcessExportTest extends TestCaseWithDatabase
{
public function test_job_processes_export_via_export_service(): void

View File

@@ -16,6 +16,7 @@ use RuntimeException;
use Tests\TestCaseWithDatabase;
#[CoversClass(ProcessImport::class)]
#[CoversClass(ImportStatus::class)]
class ProcessImportTest extends TestCaseWithDatabase
{
public function test_job_processes_import_via_import_service(): void

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Tests\Unit\Model;
use App\Models\Export;
use App\Models\Import;
use App\Models\Member;
use App\Models\Organization;
use PHPUnit\Framework\Attributes\CoversClass;
@@ -25,4 +27,38 @@ class OrganizationModelTest extends ModelTestAbstract
$this->assertNotNull($membersRel);
$this->assertCount(3, $membersRel);
}
public function test_it_has_many_imports(): void
{
// Arrange
$organization = Organization::factory()->create();
$otherOrganization = Organization::factory()->create();
Import::factory()->forOrganization($organization)->completed()->createMany(2);
Import::factory()->forOrganization($otherOrganization)->completed()->create();
// Act
$organization->refresh();
$imports = $organization->imports;
// Assert
$this->assertCount(2, $imports);
$this->assertTrue($imports->every(fn (Import $import): bool => $import->organization_id === $organization->getKey()));
}
public function test_it_has_many_exports(): void
{
// Arrange
$organization = Organization::factory()->create();
$otherOrganization = Organization::factory()->create();
Export::factory()->forOrganization($organization)->completed()->createMany(2);
Export::factory()->forOrganization($otherOrganization)->completed()->create();
// Act
$organization->refresh();
$exports = $organization->exports;
// Assert
$this->assertCount(2, $exports);
$this->assertTrue($exports->every(fn (Export $export): bool => $export->organization_id === $organization->getKey()));
}
}

View File

@@ -19,6 +19,7 @@ use App\Models\Tag;
use App\Models\Task;
use App\Models\TimeEntry;
use App\Models\User;
use App\Service\ErrorDetailsFormatter;
use App\Service\Export\ExportException;
use App\Service\Export\ExportService;
use Illuminate\Database\UniqueConstraintViolationException;
@@ -32,6 +33,7 @@ use Tests\TestCaseWithDatabase;
use ZipArchive;
#[CoversClass(ExportService::class)]
#[CoversClass(ErrorDetailsFormatter::class)]
class ExportServiceTest extends TestCaseWithDatabase
{
private function getFullOrganization(): Organization

View File

@@ -11,9 +11,11 @@ use App\Models\Import;
use App\Models\Organization;
use App\Models\TimeEntry;
use App\Models\User;
use App\Service\ErrorDetailsFormatter;
use App\Service\Import\Importers\ImporterContract;
use App\Service\Import\Importers\ImporterProvider;
use App\Service\Import\Importers\ImportException;
use App\Service\Import\Importers\ReportDto;
use App\Service\Import\ImportService;
use Illuminate\Database\UniqueConstraintViolationException;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -28,6 +30,8 @@ use Tests\TestCase;
#[CoversClass(ImportService::class)]
#[CoversClass(ImporterProvider::class)]
#[CoversClass(ErrorDetailsFormatter::class)]
#[CoversClass(ReportDto::class)]
class ImportServiceTest extends TestCase
{
use RefreshDatabase;