create(); $organisation = Organisation::factory()->create(['owner_id' => $user->id]); $application = Application::factory()->for($organisation)->create(); $environment = Environment::factory()->for($application)->create(); Service::factory()->for($environment)->create([ 'organisation_id' => $organisation->id, 'name' => 'postgres', 'category' => ServiceCategory::DATABASE, 'type' => ServiceType::POSTGRES, 'version' => '18', 'version_track' => '18', 'driver_name' => 'postgres.18', ]); $response = $this->actingAs($user)->get(route('environment-attachments.create', [ 'organisation' => $organisation->id, 'application' => $application->id, 'environment' => $environment->id, ])); $response->assertOk(); $response->assertInertia(fn (AssertableInertia $page) => $page ->component('environment-attachments/Create', false) ->has('services', 1) ->where('roles.0', EnvironmentAttachmentRole::DATABASE->value)); }); it('stores a managed attachment and generated environment variables', function () { $user = User::factory()->create(); $organisation = Organisation::factory()->create(['owner_id' => $user->id]); $application = Application::factory()->for($organisation)->create(['name' => 'Billing API']); $environment = Environment::factory()->for($application)->create(['name' => 'production']); $service = Service::factory()->for($environment)->create([ 'organisation_id' => $organisation->id, 'name' => 'postgres', 'category' => ServiceCategory::DATABASE, 'type' => ServiceType::POSTGRES, 'version' => '18', 'version_track' => '18', 'driver_name' => 'postgres.18', ]); $response = $this->actingAs($user)->post(route('environment-attachments.store', [ 'organisation' => $organisation->id, 'application' => $application->id, 'environment' => $environment->id, ]), [ 'service_id' => $service->id, 'role' => EnvironmentAttachmentRole::DATABASE->value, 'name' => 'billing_api', 'is_primary' => true, ]); $response->assertRedirect(route('environments.show', [ 'organisation' => $organisation->id, 'application' => $application->id, 'environment' => $environment->id, ])); expect($environment->attachments()->where('service_id', $service->id)->exists())->toBeTrue() ->and($environment->variables()->where('key', 'DB_CONNECTION')->first()->value)->toBe('pgsql') ->and($service->slices()->where('name', 'billing_api')->exists())->toBeTrue(); });