wowowowowo
This commit is contained in:
@@ -74,3 +74,153 @@ it('stores a managed attachment and generated environment variables', function (
|
||||
->and($environment->variables()->where('key', 'DB_CONNECTION')->first()->value)->toBe('pgsql')
|
||||
->and($service->slices()->where('name', 'billing_api')->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
it('stores gateway route configuration on caddy attachments', 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' => 'gateway',
|
||||
'category' => ServiceCategory::GATEWAY,
|
||||
'type' => ServiceType::CADDY,
|
||||
'version' => '2',
|
||||
'version_track' => '2',
|
||||
'driver_name' => 'caddy.2',
|
||||
]);
|
||||
|
||||
$this->actingAs($user)->post(route('environment-attachments.store', [
|
||||
'organisation' => $organisation->id,
|
||||
'application' => $application->id,
|
||||
'environment' => $environment->id,
|
||||
]), [
|
||||
'service_id' => $service->id,
|
||||
'role' => EnvironmentAttachmentRole::GATEWAY->value,
|
||||
'name' => 'billing',
|
||||
'domain' => 'billing.example.com',
|
||||
'path_prefix' => '/app',
|
||||
'tls_enabled' => true,
|
||||
'is_primary' => true,
|
||||
])->assertRedirect(route('environments.show', [
|
||||
'organisation' => $organisation->id,
|
||||
'application' => $application->id,
|
||||
'environment' => $environment->id,
|
||||
]));
|
||||
|
||||
$slice = $service->slices()->where('type', 'route')->firstOrFail();
|
||||
|
||||
expect($slice->config['domain'])->toBe('billing.example.com')
|
||||
->and($slice->config['path_prefix'])->toBe('/app')
|
||||
->and($slice->config['tls_enabled'])->toBeTrue();
|
||||
|
||||
$attachment = $environment->attachments()->firstOrFail();
|
||||
|
||||
$this->actingAs($user)->put(route('environment-attachments.update', [
|
||||
'organisation' => $organisation->id,
|
||||
'application' => $application->id,
|
||||
'environment' => $environment->id,
|
||||
'attachment' => $attachment->id,
|
||||
]), [
|
||||
'role' => EnvironmentAttachmentRole::GATEWAY->value,
|
||||
'env_prefix' => null,
|
||||
'is_primary' => true,
|
||||
'domain' => 'www.example.com',
|
||||
'path_prefix' => '/',
|
||||
'tls_enabled' => false,
|
||||
'certificate_status' => 'disabled',
|
||||
])->assertRedirect(route('environments.show', [
|
||||
'organisation' => $organisation->id,
|
||||
'application' => $application->id,
|
||||
'environment' => $environment->id,
|
||||
]));
|
||||
|
||||
expect($slice->refresh()->config)->toMatchArray([
|
||||
'domain' => 'www.example.com',
|
||||
'path_prefix' => '/',
|
||||
'tls_enabled' => false,
|
||||
'certificate_status' => 'disabled',
|
||||
]);
|
||||
});
|
||||
|
||||
it('manages gateway routes through dedicated route pages', 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' => 'gateway',
|
||||
'category' => ServiceCategory::GATEWAY,
|
||||
'type' => ServiceType::CADDY,
|
||||
'version' => '2',
|
||||
'version_track' => '2',
|
||||
'driver_name' => 'caddy.2',
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('gateway.routes.create', [$organisation, $application, $environment]))
|
||||
->assertOk()
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->component('gateway-routes/Create', false)
|
||||
->has('services', 1)
|
||||
->where('services.0.id', $service->id));
|
||||
|
||||
$this->actingAs($user)
|
||||
->post(route('gateway.routes.store', [$organisation, $application, $environment]), [
|
||||
'service_id' => $service->id,
|
||||
'name' => 'billing',
|
||||
'domain' => 'billing.example.com',
|
||||
'path_prefix' => '/app',
|
||||
'tls_enabled' => true,
|
||||
])
|
||||
->assertRedirect(route('gateway.routes.index', [$organisation, $application, $environment]));
|
||||
|
||||
$attachment = $environment->attachments()->with('serviceSlice')->firstOrFail();
|
||||
|
||||
expect($attachment->role)->toBe(EnvironmentAttachmentRole::GATEWAY)
|
||||
->and($attachment->serviceSlice->config)->toMatchArray([
|
||||
'domain' => 'billing.example.com',
|
||||
'path_prefix' => '/app',
|
||||
'tls_enabled' => true,
|
||||
'certificate_status' => 'pending',
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('gateway.routes.index', [$organisation, $application, $environment]))
|
||||
->assertOk()
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->component('gateway-routes/Index', false)
|
||||
->has('routes', 1)
|
||||
->where('routes.0.id', $attachment->id)
|
||||
->where('routes.0.service_slice.config.domain', 'billing.example.com'));
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('gateway.routes.edit', [$organisation, $application, $environment, $attachment]))
|
||||
->assertOk()
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->component('gateway-routes/Edit', false)
|
||||
->where('routeAttachment.id', $attachment->id));
|
||||
|
||||
$this->actingAs($user)
|
||||
->put(route('gateway.routes.update', [$organisation, $application, $environment, $attachment]), [
|
||||
'domain' => 'www.example.com',
|
||||
'path_prefix' => '/',
|
||||
'tls_enabled' => false,
|
||||
'certificate_status' => 'disabled',
|
||||
])
|
||||
->assertRedirect(route('gateway.routes.index', [$organisation, $application, $environment]));
|
||||
|
||||
expect($attachment->serviceSlice->refresh()->config)->toMatchArray([
|
||||
'domain' => 'www.example.com',
|
||||
'path_prefix' => '/',
|
||||
'tls_enabled' => false,
|
||||
'certificate_status' => 'disabled',
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->delete(route('gateway.routes.destroy', [$organisation, $application, $environment, $attachment]))
|
||||
->assertRedirect(route('gateway.routes.index', [$organisation, $application, $environment]));
|
||||
|
||||
expect($environment->attachments()->exists())->toBeFalse();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user