Implement Keystone environment deployments
This commit is contained in:
55
tests/Feature/EnvironmentWorkerControllerTest.php
Normal file
55
tests/Feature/EnvironmentWorkerControllerTest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\DeployPolicy;
|
||||
use App\Enums\ServiceType;
|
||||
use App\Models\Application;
|
||||
use App\Models\Environment;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\User;
|
||||
|
||||
it('creates a dedicated laravel worker service for an environment', 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([
|
||||
'build_config' => [
|
||||
'php_version' => '8.4',
|
||||
],
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->post(route('environment-workers.store', [
|
||||
'organisation' => $organisation->id,
|
||||
'application' => $application->id,
|
||||
'environment' => $environment->id,
|
||||
]));
|
||||
|
||||
$response->assertRedirect(route('applications.show', [
|
||||
'organisation' => $organisation->id,
|
||||
'application' => $application->id,
|
||||
]));
|
||||
|
||||
$worker = $environment->services()->where('name', 'worker')->firstOrFail();
|
||||
|
||||
expect($worker->type)->toBe(ServiceType::LARAVEL)
|
||||
->and($worker->deploy_policy)->toBe(DeployPolicy::WITH_ENVIRONMENT)
|
||||
->and($worker->process_roles)->toBe(['worker'])
|
||||
->and($worker->config['command'])->toBe('php artisan queue:work --sleep=3 --tries=3');
|
||||
});
|
||||
|
||||
it('does not create duplicate worker services for repeated clicks', 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();
|
||||
|
||||
$route = route('environment-workers.store', [
|
||||
'organisation' => $organisation->id,
|
||||
'application' => $application->id,
|
||||
'environment' => $environment->id,
|
||||
]);
|
||||
|
||||
$this->actingAs($user)->post($route);
|
||||
$this->actingAs($user)->post($route);
|
||||
|
||||
expect($environment->services()->where('name', 'worker')->count())->toBe(1);
|
||||
});
|
||||
Reference in New Issue
Block a user