Location test additions

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-05 08:29:00 +01:00
parent 7455bf329d
commit 97775fb790
2 changed files with 52 additions and 8 deletions

View file

@ -6,25 +6,31 @@ use App\Models\Location;
use App\Models\User;
use Tests\TestCase;
class UpdateLocationsTest extends TestCase
class CreateLocationsTest extends TestCase
{
public function testCanUpdateLocationViaPatchWithoutLocationType()
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', $location), [
'name' => 'Test Location',
->patchJson(route('api.locations.update', $location2), [
'name' => $location->name,
])
->assertOk()
->assertStatusMessageIs('success')
->assertStatusMessageIs('error')
->assertStatus(200)
->json();
$location->refresh();
$this->assertEquals('Test Location', $location->name, 'Name was not updated');
}
}

View file

@ -0,0 +1,38 @@
<?php
namespace Tests\Feature\Locations\Api;
use App\Models\Location;
use App\Models\User;
use Tests\TestCase;
class UpdateLocationsTest extends TestCase
{
public function testRequiresPermissionToEditLocation()
{
$this->actingAsForApi(User::factory()->create())
->postJson(route('api.locations.store', Location::factory()->create()))
->assertForbidden();
}
public function testCanUpdateLocationViaPatch()
{
$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');
}
}