mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Added more locations tests
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
24ad74f136
commit
7455bf329d
30
tests/Feature/Locations/Api/CreateLocationsTest.php
Normal file
30
tests/Feature/Locations/Api/CreateLocationsTest.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Locations\Api;
|
||||
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdateLocationsTest extends TestCase
|
||||
{
|
||||
|
||||
public function testCanUpdateLocationViaPatchWithoutLocationType()
|
||||
{
|
||||
$location = Location::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->patchJson(route('api.locations.update', $location), [
|
||||
'name' => 'Test Location',
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('success')
|
||||
->assertStatus(200)
|
||||
->json();
|
||||
|
||||
$location->refresh();
|
||||
$this->assertEquals('Test Location', $location->name, 'Name was not updated');
|
||||
|
||||
}
|
||||
|
||||
}
|
93
tests/Feature/Locations/Api/DeleteLocationsTest.php
Normal file
93
tests/Feature/Locations/Api/DeleteLocationsTest.php
Normal file
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Locations\Api;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteLocationsTest extends TestCase
|
||||
{
|
||||
|
||||
public function testErrorReturnedViaApiIfLocationDoesNotExist()
|
||||
{
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->deleteJson(route('api.users.destroy', 'invalid-id'))
|
||||
->assertOk()
|
||||
->assertStatus(200)
|
||||
->assertStatusMessageIs('error')
|
||||
->json();
|
||||
}
|
||||
|
||||
public function testErrorReturnedViaApiIfLocationIsAlreadyDeleted()
|
||||
{
|
||||
$location = Location::factory()->deletedLocation()->create();
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->deleteJson(route('api.locations.destroy', $location->id))
|
||||
->assertOk()
|
||||
->assertStatus(200)
|
||||
->assertStatusMessageIs('error')
|
||||
->json();
|
||||
}
|
||||
|
||||
public function testDisallowLocationDeletionViaApiIfStillHasPeople()
|
||||
{
|
||||
$location = Location::factory()->create();
|
||||
User::factory()->count(5)->create(['location_id' => $location->id]);
|
||||
|
||||
$this->assertFalse($location->isDeletable());
|
||||
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->deleteJson(route('api.locations.destroy', $location->id))
|
||||
->assertOk()
|
||||
->assertStatus(200)
|
||||
->assertStatusMessageIs('error')
|
||||
->json();
|
||||
}
|
||||
|
||||
public function testDisallowUserDeletionViaApiIfStillHasChildLocations()
|
||||
{
|
||||
$parent = Location::factory()->create();
|
||||
Location::factory()->count(5)->create(['parent_id' => $parent->id]);
|
||||
$this->assertFalse($parent->isDeletable());
|
||||
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->deleteJson(route('api.locations.destroy', $parent->id))
|
||||
->assertOk()
|
||||
->assertStatus(200)
|
||||
->assertStatusMessageIs('error')
|
||||
->json();
|
||||
}
|
||||
|
||||
public function testDisallowUserDeletionViaApiIfStillHasAssetsAssigned()
|
||||
{
|
||||
$location = Location::factory()->create();
|
||||
Asset::factory()->count(5)->assignedToLocation($location)->create();
|
||||
|
||||
$this->assertFalse($location->isDeletable());
|
||||
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->deleteJson(route('api.locations.destroy', $location->id))
|
||||
->assertOk()
|
||||
->assertStatus(200)
|
||||
->assertStatusMessageIs('error')
|
||||
->json();
|
||||
}
|
||||
|
||||
public function testDisallowUserDeletionViaApiIfStillHasAssetsAsLocation()
|
||||
{
|
||||
$location = Location::factory()->create();
|
||||
Asset::factory()->count(5)->create(['location_id' => $location->id]);
|
||||
|
||||
$this->assertFalse($location->isDeletable());
|
||||
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->deleteJson(route('api.locations.destroy', $location->id))
|
||||
->assertOk()
|
||||
->assertStatus(200)
|
||||
->assertStatusMessageIs('error')
|
||||
->json();
|
||||
}
|
||||
|
||||
}
|
23
tests/Feature/Locations/Ui/IndexLocationsTest.php
Normal file
23
tests/Feature/Locations/Ui/IndexLocationsTest.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\AssetModels\Ui;
|
||||
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class IndexLocationsTest extends TestCase
|
||||
{
|
||||
public function testPermissionRequiredToViewLocationsList()
|
||||
{
|
||||
$this->actingAs(User::factory()->create())
|
||||
->get(route('locations.index'))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testUserCanListLocations()
|
||||
{
|
||||
$this->actingAs(User::factory()->superuser()->create())
|
||||
->get(route('locations.index'))
|
||||
->assertOk();
|
||||
}
|
||||
}
|
|
@ -152,9 +152,4 @@ class DeleteUserTest extends TestCase
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue