2024-07-05 03:29:30 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Locations\Ui;
|
|
|
|
|
|
|
|
use App\Models\Location;
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\User;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class CreateLocationsTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testPermissionRequiredToCreateLocation()
|
|
|
|
{
|
|
|
|
$this->actingAs(User::factory()->create())
|
|
|
|
->post(route('locations.store'), [
|
|
|
|
'name' => 'Test Location',
|
|
|
|
'company_id' => Company::factory()->create()->id
|
|
|
|
])
|
|
|
|
->assertForbidden();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUserCanCreateLocations()
|
|
|
|
{
|
|
|
|
$this->assertFalse(Location::where('name', 'Test Location')->exists());
|
|
|
|
|
|
|
|
$this->actingAs(User::factory()->superuser()->create())
|
|
|
|
->post(route('locations.store'), [
|
|
|
|
'name' => 'Test Location',
|
|
|
|
'company_id' => Company::factory()->create()->id
|
|
|
|
])
|
|
|
|
->assertRedirect(route('locations.index'));
|
|
|
|
|
|
|
|
$this->assertTrue(Location::where('name', 'Test Location')->exists());
|
|
|
|
}
|
2024-08-21 01:58:47 -07:00
|
|
|
|
|
|
|
public function testUserCannotCreateLocationsWithInvalidParent()
|
|
|
|
{
|
|
|
|
$this->assertFalse(Location::where('name', 'Test Location')->exists());
|
|
|
|
|
|
|
|
$this->actingAs(User::factory()->superuser()->create())
|
2024-08-21 02:09:35 -07:00
|
|
|
->from(route('locations.create'))
|
2024-08-21 01:58:47 -07:00
|
|
|
->post(route('locations.store'), [
|
|
|
|
'name' => 'Test Location',
|
|
|
|
'parent_id' => '100000000'
|
|
|
|
])
|
2024-08-21 02:09:35 -07:00
|
|
|
->assertRedirect(route('locations.create'));
|
2024-08-21 01:58:47 -07:00
|
|
|
|
|
|
|
$this->assertFalse(Location::where('name', 'Test Location')->exists());
|
|
|
|
}
|
2024-07-05 03:29:30 -07:00
|
|
|
|
|
|
|
}
|