41 lines
2.0 KiB
PHP
41 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Services\InvestmentGeography;
|
|
use App\Services\VirtualDesk;
|
|
use Database\Seeders\TerritoryReferenceSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Tests\TestCase;
|
|
|
|
final class DeskLocationApplicabilityTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_a_preserved_inactive_location_does_not_require_a_hidden_source_but_an_active_location_still_does(): void
|
|
{
|
|
$this->seed(TerritoryReferenceSeeder::class);
|
|
$territory = app(InvestmentGeography::class)->publicReferences()->where('location_type', 'province')->value('id');
|
|
$this->assertNotEmpty($territory);
|
|
$definition = ['fields' => [
|
|
'branch' => ['label' => 'Synthetic branch', 'type' => 'select', 'required' => true, 'options' => ['yes' => 'Yes', 'no' => 'No']],
|
|
'territory_id' => ['label' => 'Location', 'type' => 'territory', 'required' => false, 'when' => ['field' => 'branch', 'equals' => 'yes']],
|
|
'location_source' => ['label' => 'Source', 'type' => 'text', 'required' => false, 'when' => ['field' => 'branch', 'equals' => 'yes']],
|
|
]];
|
|
$desk = app(VirtualDesk::class);
|
|
$payload = ['branch' => 'no', 'territory_id' => $territory];
|
|
$this->assertSame($payload, $desk->validateFields($payload, $definition, true));
|
|
$payload['branch'] = 'yes';
|
|
try {
|
|
$desk->validateFields($payload, $definition, true);
|
|
$this->fail('An applicable selected location must retain its source requirement.');
|
|
} catch (ValidationException $error) {
|
|
$this->assertArrayHasKey('payload.location_source', $error->errors());
|
|
}
|
|
$payload['location_source'] = 'Synthetic QA use of the packaged reference';
|
|
$this->assertSame($payload, $desk->validateFields($payload, $definition, true));
|
|
$this->assertSame(['branch' => 'yes'], $desk->validateFields(['branch' => 'yes'], $definition, true));
|
|
}
|
|
}
|