mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-15 01:54:09 -08:00
a8ddb2f44a
Signed-off-by: snipe <snipe@snipe.net>
57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Locations\Api;
|
|
|
|
use App\Models\Location;
|
|
use App\Models\User;
|
|
use Tests\TestCase;
|
|
|
|
class CreateLocationsTest extends TestCase
|
|
{
|
|
|
|
public function testRequiresPermissionToCreateLocation()
|
|
{
|
|
$this->actingAsForApi(User::factory()->create())
|
|
->postJson(route('api.departments.store'))
|
|
->assertForbidden();
|
|
}
|
|
|
|
public function testCannotCreateNewLocationsWithTheSameName()
|
|
{
|
|
$location = Location::factory()->create();
|
|
$location2 = Location::factory()->create();
|
|
|
|
$this->actingAsForApi(User::factory()->superuser()->create())
|
|
->patchJson(route('api.locations.update', $location2), [
|
|
'name' => $location->name,
|
|
])
|
|
->assertOk()
|
|
->assertStatusMessageIs('error')
|
|
->assertStatus(200)
|
|
->json();
|
|
|
|
|
|
}
|
|
|
|
public function testUserCannotCreateLocationsThatAreTheirOwnParent()
|
|
{
|
|
$location = Location::factory()->create();
|
|
|
|
$this->actingAsForApi(User::factory()->superuser()->create())
|
|
->patchJson(route('api.locations.update', $location), [
|
|
'parent_id' => $location->id,
|
|
])
|
|
->assertOk()
|
|
->assertStatusMessageIs('error')
|
|
->assertJson([
|
|
'messages' => [
|
|
'parent_id' => ['The parent id must not create a circular reference.'],
|
|
],
|
|
])
|
|
->json();
|
|
|
|
|
|
}
|
|
|
|
}
|