74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Enums\DistributionModeEnum;
|
|
use App\Models\Scenario;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class ScenarioUpdateTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private Scenario $scenario;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->scenario = Scenario::factory()->create();
|
|
}
|
|
|
|
public function test_can_update_distribution_mode(): void
|
|
{
|
|
$response = $this->patchJson("/scenarios/{$this->scenario->uuid}", [
|
|
'distribution_mode' => 'priority',
|
|
]);
|
|
|
|
$response->assertOk();
|
|
$this->assertDatabaseHas('scenarios', [
|
|
'id' => $this->scenario->id,
|
|
'distribution_mode' => DistributionModeEnum::PRIORITY->value,
|
|
]);
|
|
}
|
|
|
|
public function test_rejects_invalid_distribution_mode(): void
|
|
{
|
|
$response = $this->patchJson("/scenarios/{$this->scenario->uuid}", [
|
|
'distribution_mode' => 'invalid',
|
|
]);
|
|
|
|
$response->assertUnprocessable();
|
|
$response->assertJsonValidationErrors(['distribution_mode']);
|
|
}
|
|
|
|
public function test_can_update_distribution_mode_without_name(): void
|
|
{
|
|
$originalName = $this->scenario->name;
|
|
|
|
$response = $this->patchJson("/scenarios/{$this->scenario->uuid}", [
|
|
'distribution_mode' => 'priority',
|
|
]);
|
|
|
|
$response->assertOk();
|
|
$this->assertDatabaseHas('scenarios', [
|
|
'id' => $this->scenario->id,
|
|
'name' => $originalName,
|
|
'distribution_mode' => DistributionModeEnum::PRIORITY->value,
|
|
]);
|
|
}
|
|
|
|
public function test_can_update_name_without_distribution_mode(): void
|
|
{
|
|
$response = $this->patchJson("/scenarios/{$this->scenario->uuid}", [
|
|
'name' => 'Updated Name',
|
|
]);
|
|
|
|
$response->assertOk();
|
|
$this->assertDatabaseHas('scenarios', [
|
|
'id' => $this->scenario->id,
|
|
'name' => 'Updated Name',
|
|
'distribution_mode' => $this->scenario->distribution_mode->value,
|
|
]);
|
|
}
|
|
}
|