create(); $organisation = Organisation::factory()->create(['owner_id' => $user->id]); $application = Application::factory()->for($organisation)->create(); $environment = Environment::factory()->for($application)->create(); $response = $this->actingAs($user)->get(route('environment-variables.create', [ 'organisation' => $organisation->id, 'application' => $application->id, 'environment' => $environment->id, ])); $response->assertOk(); $response->assertInertia(fn (AssertableInertia $page) => $page ->component('environment-variables/Create', false)); }); it('stores editable user-defined environment variables', function () { $user = User::factory()->create(); $organisation = Organisation::factory()->create(['owner_id' => $user->id]); $application = Application::factory()->for($organisation)->create(); $environment = Environment::factory()->for($application)->create(); $response = $this->actingAs($user)->post(route('environment-variables.store', [ 'organisation' => $organisation->id, 'application' => $application->id, 'environment' => $environment->id, ]), [ 'key' => 'APP_DEBUG', 'value' => 'false', ]); $response->assertRedirect(route('environments.show', [ 'organisation' => $organisation->id, 'application' => $application->id, 'environment' => $environment->id, ])); $variable = $environment->variables()->firstOrFail(); expect($variable->key)->toBe('APP_DEBUG') ->and($variable->value)->toBe('false') ->and($variable->source)->toBe(EnvironmentVariableSource::USER) ->and($variable->overridable)->toBeTrue() ->and($variable->service_slice_id)->toBeNull(); }); it('lists updates and deletes environment variables', function () { $user = User::factory()->create(); $organisation = Organisation::factory()->create(['owner_id' => $user->id]); $application = Application::factory()->for($organisation)->create(); $environment = Environment::factory()->for($application)->create(); $variable = $environment->variables()->create([ 'key' => 'APP_DEBUG', 'value' => 'false', 'source' => EnvironmentVariableSource::USER, 'overridable' => true, ]); $this->actingAs($user) ->get(route('environment-variables.index', [$organisation, $application, $environment])) ->assertOk() ->assertInertia(fn (AssertableInertia $page) => $page ->component('environment-variables/Index', false) ->has('variables', 1) ->where('variables.0.value', 'false')); $this->actingAs($user) ->put(route('environment-variables.update', [$organisation, $application, $environment, $variable]), [ 'key' => 'APP_ENV', 'value' => 'production', 'overridable' => false, ]) ->assertRedirect(route('environment-variables.index', [$organisation, $application, $environment])); expect($variable->refresh()->key)->toBe('APP_ENV') ->and($variable->overridable)->toBeFalse(); $this->actingAs($user) ->delete(route('environment-variables.destroy', [$organisation, $application, $environment, $variable])) ->assertRedirect(route('environment-variables.index', [$organisation, $application, $environment])); expect($environment->variables()->exists())->toBeFalse(); }); it('bulk imports dotenv environment variables', function () { $user = User::factory()->create(); $organisation = Organisation::factory()->create(['owner_id' => $user->id]); $application = Application::factory()->for($organisation)->create(); $environment = Environment::factory()->for($application)->create(); $this->actingAs($user) ->post(route('environment-variables.import', [$organisation, $application, $environment]), [ 'contents' => implode("\n", [ '# ignored comment', 'APP_ENV=production', 'APP_NAME="Billing API"', "export FEATURE_FLAG='enabled'", 'bad-key=ignored', ]), 'overridable' => false, ]) ->assertRedirect(route('environment-variables.index', [$organisation, $application, $environment])); expect($environment->variables()->count())->toBe(3) ->and($environment->variables()->where('key', 'APP_ENV')->first()->value)->toBe('production') ->and($environment->variables()->where('key', 'APP_NAME')->first()->value)->toBe('Billing API') ->and($environment->variables()->where('key', 'FEATURE_FLAG')->first()->value)->toBe('enabled') ->and($environment->variables()->where('key', 'APP_ENV')->first()->overridable)->toBeFalse(); });