mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Added tests
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
da2b64c96d
commit
a6b2f5df1d
52
tests/Feature/Consumables/Api/ConsumableUpdateTest.php
Normal file
52
tests/Feature/Consumables/Api/ConsumableUpdateTest.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Consumables\Api;
|
||||
|
||||
use App\Models\Consumable;
|
||||
use App\Models\Category;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ConsumableUpdateTest extends TestCase
|
||||
{
|
||||
|
||||
public function testCanUpdateConsumableViaPatchWithoutCategoryType()
|
||||
{
|
||||
$consumable = Consumable::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->patchJson(route('api.consumables.update', $consumable), [
|
||||
'name' => 'Test Consumable',
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('success')
|
||||
->assertStatus(200)
|
||||
->json();
|
||||
|
||||
$consumable->refresh();
|
||||
$this->assertEquals('Test Consumable', $consumable->name, 'Name was not updated');
|
||||
|
||||
}
|
||||
|
||||
public function testCannotUpdateConsumableViaPatchWithInvalidCategoryType()
|
||||
{
|
||||
$category = Category::factory()->create(['category_type' => 'asset']);
|
||||
$consumable = Consumable::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->patchJson(route('api.consumables.update', $consumable), [
|
||||
'name' => 'Test Consumable',
|
||||
'category_id' => $category->id,
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('error')
|
||||
->assertStatus(200)
|
||||
->json();
|
||||
|
||||
$category->refresh();
|
||||
$this->assertNotEquals('Test Consumable', $consumable->name, 'Name was not updated');
|
||||
$this->assertNotEquals('consumable', $consumable->category_id, 'Category was not updated');
|
||||
|
||||
}
|
||||
|
||||
}
|
51
tests/Feature/Consumables/Api/ConsumableViewTest.php
Normal file
51
tests/Feature/Consumables/Api/ConsumableViewTest.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Consumables\Api;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Consumable;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ConsumableViewTest extends TestCase
|
||||
{
|
||||
public function testConsumableViewAdheresToCompanyScoping()
|
||||
{
|
||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||
|
||||
$consumableA = Consumable::factory()->for($companyA)->create();
|
||||
$consumableB = Consumable::factory()->for($companyB)->create();
|
||||
|
||||
$superUser = $companyA->users()->save(User::factory()->superuser()->make());
|
||||
$userInCompanyA = $companyA->users()->save(User::factory()->viewConsumables()->make());
|
||||
$userInCompanyB = $companyB->users()->save(User::factory()->viewConsumables()->make());
|
||||
|
||||
$this->settings->disableMultipleFullCompanySupport();
|
||||
|
||||
$this->actingAsForApi($superUser)
|
||||
->getJson(route('api.consumables.show', $consumableA))
|
||||
->assertOk();
|
||||
|
||||
$this->actingAsForApi($userInCompanyA)
|
||||
->getJson(route('api.consumables.show', $consumableA))
|
||||
->assertOk();
|
||||
|
||||
$this->actingAsForApi($userInCompanyB)
|
||||
->getJson(route('api.consumables.show', $consumableB))
|
||||
->assertOk();
|
||||
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
$this->actingAsForApi($superUser)
|
||||
->getJson(route('api.consumables.show', $consumableA))
|
||||
->assertOk();
|
||||
|
||||
$this->actingAsForApi($userInCompanyA)
|
||||
->getJson(route('api.consumables.index'))
|
||||
->assertOk();
|
||||
|
||||
$this->actingAsForApi($userInCompanyB)
|
||||
->getJson(route('api.consumables.index'))
|
||||
->assertOk();
|
||||
}
|
||||
}
|
26
tests/Feature/Consumables/Ui/ConsumableViewTest.php
Normal file
26
tests/Feature/Consumables/Ui/ConsumableViewTest.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Consumables\Ui;
|
||||
|
||||
use App\Models\Consumable;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ConsumableViewTest extends TestCase
|
||||
{
|
||||
public function testPermissionRequiredToViewConsumable()
|
||||
{
|
||||
$consumable = Consumable::factory()->create();
|
||||
$this->actingAs(User::factory()->create())
|
||||
->get(route('consumables.show', $consumable))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testUserCanListConsumables()
|
||||
{
|
||||
$consumable = Consumable::factory()->create();
|
||||
$this->actingAs(User::factory()->superuser()->create())
|
||||
->get(route('consumables.show', $consumable))
|
||||
->assertOk();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue