2024-07-05 00:21:31 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Locations\Api;
|
|
|
|
|
|
|
|
use App\Models\Location;
|
|
|
|
use App\Models\User;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-07-05 00:29:00 -07:00
|
|
|
class CreateLocationsTest extends TestCase
|
2024-07-05 00:21:31 -07:00
|
|
|
{
|
|
|
|
|
2024-07-05 00:29:00 -07:00
|
|
|
public function testRequiresPermissionToCreateLocation()
|
|
|
|
{
|
|
|
|
$this->actingAsForApi(User::factory()->create())
|
|
|
|
->postJson(route('api.departments.store'))
|
|
|
|
->assertForbidden();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCannotCreateNewLocationsWithTheSameName()
|
2024-07-05 00:21:31 -07:00
|
|
|
{
|
|
|
|
$location = Location::factory()->create();
|
2024-07-05 00:29:00 -07:00
|
|
|
$location2 = Location::factory()->create();
|
2024-07-05 00:21:31 -07:00
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->superuser()->create())
|
2024-07-05 00:29:00 -07:00
|
|
|
->patchJson(route('api.locations.update', $location2), [
|
|
|
|
'name' => $location->name,
|
2024-07-05 00:21:31 -07:00
|
|
|
])
|
|
|
|
->assertOk()
|
2024-07-05 00:29:00 -07:00
|
|
|
->assertStatusMessageIs('error')
|
2024-07-05 00:21:31 -07:00
|
|
|
->assertStatus(200)
|
|
|
|
->json();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-07-05 00:29:00 -07:00
|
|
|
|
2024-07-05 00:21:31 -07:00
|
|
|
}
|