Added tests

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-08-21 09:58:47 +01:00
parent 4d03f1e110
commit a23dee52f2
2 changed files with 29 additions and 1 deletions

View file

@ -32,6 +32,19 @@ class CreateLocationsTest extends TestCase
$this->assertTrue(Location::where('name', 'Test Location')->exists());
}
public function testUserCannotCreateLocationsWithInvalidParent()
{
$this->assertFalse(Location::where('name', 'Test Location')->exists());
$this->actingAs(User::factory()->superuser()->create())
->post(route('locations.store'), [
'name' => 'Test Location',
'parent_id' => '100000000'
])
->assertRedirect(route('locations.index'));
$this->assertFalse(Location::where('name', 'Test Location')->exists());
}
}

View file

@ -52,6 +52,21 @@ class UpdateLocationsTest extends TestCase
$this->assertFalse(Location::where('name', 'Test Location')->exists());
}
public function testUserCannotEditLocationsWithInvalidParent()
{
$location = Location::factory()->create();
$response = $this->actingAs(User::factory()->superuser()->create())
->from(route('locations.edit', ['location' => $location->id]))
->put(route('locations.update', ['location' => $location]), [
'name' => 'Test Location',
'parent_id' => '100000000'
])
->assertRedirect(route('locations.index'));
$this->followRedirects($response)->assertSee(trans('general.error'));
$this->assertFalse(Location::where('name', 'Test Location')->exists());
}
}