Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 3m45s
Implemented the first version of review output resolve actions. Included a ReviewOutputResolveActionMapper, commands to seed browser fixtures, updated CustomerReviewWorkspace, EnvironmentReviewResource, UI enforcement, and related views. Also added extensive unit, feature, and browser tests, and updated the design coverage matrix.
113 lines
4.5 KiB
PHP
113 lines
4.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Pages\Reviews\CustomerReviewWorkspace;
|
|
use App\Filament\Resources\EnvironmentReviewResource;
|
|
use App\Filament\Resources\EnvironmentReviewResource\Pages\ViewEnvironmentReview;
|
|
use App\Models\EnvironmentReview;
|
|
use App\Models\ManagedEnvironment;
|
|
use App\Models\ReviewPack;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use App\Support\EnvironmentReviewStatus;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Filament\Actions\Action;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
Storage::fake('exports');
|
|
});
|
|
|
|
it('seeds a deterministic published-to-ready browser fixture for review output', function (): void {
|
|
$this->artisan('tenantpilot:review-output:seed-browser-fixture', ['--no-interaction' => true])
|
|
->assertSuccessful()
|
|
->expectsOutputToContain('Fixture login URL')
|
|
->expectsOutputToContain('Ready review detail URL')
|
|
->expectsOutputToContain('Workspace URL');
|
|
|
|
$workspaceConfig = config('tenantpilot.review_output.browser_smoke_fixture.workspace');
|
|
$userConfig = config('tenantpilot.review_output.browser_smoke_fixture.user');
|
|
$scenarioConfig = config('tenantpilot.review_output.browser_smoke_fixture.ready_draft');
|
|
|
|
$workspace = Workspace::query()->where('slug', $workspaceConfig['slug'])->first();
|
|
$user = User::query()->where('email', $userConfig['email'])->first();
|
|
$environment = ManagedEnvironment::query()->where('slug', $scenarioConfig['managed_environment_slug'])->first();
|
|
|
|
expect($workspace)->not->toBeNull();
|
|
expect($user)->not->toBeNull();
|
|
expect($environment)->not->toBeNull();
|
|
|
|
$publishedReview = EnvironmentReview::query()
|
|
->where('managed_environment_id', (int) $environment->getKey())
|
|
->where('status', EnvironmentReviewStatus::Superseded->value)
|
|
->latest('id')
|
|
->first();
|
|
|
|
expect($publishedReview)->not->toBeNull()
|
|
->and($publishedReview?->superseded_by_review_id)->not->toBeNull();
|
|
|
|
$readyReview = EnvironmentReview::query()->find($publishedReview->superseded_by_review_id);
|
|
|
|
expect($readyReview)->not->toBeNull()
|
|
->and($readyReview?->status)->toBe(EnvironmentReviewStatus::Ready->value)
|
|
->and($readyReview?->publishBlockers())->toBe([]);
|
|
|
|
$reviewPack = ReviewPack::query()->find($publishedReview->current_export_review_pack_id);
|
|
|
|
expect($reviewPack)->not->toBeNull()
|
|
->and($reviewPack?->status)->toBe(ReviewPack::STATUS_READY)
|
|
->and($reviewPack?->environment_review_id)->toBe((int) $publishedReview->getKey());
|
|
|
|
Storage::disk('exports')->assertExists((string) $reviewPack->file_path);
|
|
|
|
$this->actingAs($user)->withSession([
|
|
WorkspaceContext::SESSION_KEY => (int) $workspace->getKey(),
|
|
WorkspaceContext::LAST_ENVIRONMENT_IDS_SESSION_KEY => [
|
|
(string) $workspace->getKey() => (int) $environment->getKey(),
|
|
],
|
|
]);
|
|
|
|
$this->get(CustomerReviewWorkspace::environmentFilterUrl($environment))
|
|
->assertSuccessful()
|
|
->assertSee('Draft review exists')
|
|
->assertSee('Open draft review')
|
|
->assertDontSee('No released customer reviews match the active environment filter.');
|
|
|
|
$detailUrl = EnvironmentReviewResource::environmentScopedUrl('view', ['record' => $readyReview], $environment);
|
|
$detailRedirect = tenantpilotReviewOutputFixtureRelativeAdminRedirect($detailUrl);
|
|
|
|
$this->get(route('admin.local.smoke-login', [
|
|
'email' => $user->email,
|
|
'tenant' => $environment->slug,
|
|
'workspace' => $workspace->slug,
|
|
'redirect' => $detailRedirect,
|
|
]))
|
|
->assertRedirect($detailRedirect)
|
|
->assertSessionHas(WorkspaceContext::SESSION_KEY, (int) $workspace->getKey());
|
|
|
|
$this->assertAuthenticatedAs($user);
|
|
|
|
setAdminEnvironmentContext($environment);
|
|
|
|
Livewire::actingAs($user)
|
|
->test(ViewEnvironmentReview::class, ['record' => $readyReview->getKey()])
|
|
->assertActionVisible('publish_review')
|
|
->assertActionExists('publish_review', fn (Action $action): bool => $action->isConfirmationRequired());
|
|
});
|
|
|
|
function tenantpilotReviewOutputFixtureRelativeAdminRedirect(string $url): string
|
|
{
|
|
$parsed = parse_url($url);
|
|
|
|
$path = '/'.ltrim((string) ($parsed['path'] ?? ''), '/');
|
|
$query = isset($parsed['query']) ? '?'.$parsed['query'] : '';
|
|
$fragment = isset($parsed['fragment']) ? '#'.$parsed['fragment'] : '';
|
|
|
|
return $path.$query.$fragment;
|
|
}
|