mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
Merge pull request #15965 from marcusmoore/testing/consumable-ui
Added Consumable UI tests
This commit is contained in:
commit
0984194ec6
|
@ -50,7 +50,7 @@ class ConsumablesController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('create', Consumable::class);
|
$this->authorize('create', Consumable::class);
|
||||||
|
|
||||||
return view('consumables/edit')->with('category_type', 'consumable')
|
return view('consumables.edit')->with('category_type', 'consumable')
|
||||||
->with('item', new Consumable);
|
->with('item', new Consumable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,66 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Consumables\Ui;
|
namespace Tests\Feature\Consumables\Ui;
|
||||||
|
|
||||||
|
use App\Models\Category;
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\Location;
|
||||||
|
use App\Models\Manufacturer;
|
||||||
|
use App\Models\Supplier;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use Tests\Concerns\TestsPermissionsRequirement;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class CreateConsumableTest extends TestCase
|
class CreateConsumableTest extends TestCase implements TestsPermissionsRequirement
|
||||||
{
|
{
|
||||||
|
public function testRequiresPermission()
|
||||||
|
{
|
||||||
|
$this->actingAs(User::factory()->create())
|
||||||
|
->get(route('consumables.create'))
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanRenderCreateConsumablePage()
|
||||||
|
{
|
||||||
|
$this->actingAs(User::factory()->createConsumables()->create())
|
||||||
|
->get(route('consumables.create'))
|
||||||
|
->assertOk()
|
||||||
|
->assertViewIs('consumables.edit');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanCreateConsumable()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'company_id' => Company::factory()->create()->id,
|
||||||
|
'name' => 'My Consumable',
|
||||||
|
'category_id' => Category::factory()->consumableInkCategory()->create()->id,
|
||||||
|
'supplier_id' => Supplier::factory()->create()->id,
|
||||||
|
'manufacturer_id' => Manufacturer::factory()->create()->id,
|
||||||
|
'location_id' => Location::factory()->create()->id,
|
||||||
|
'model_number' => '1234',
|
||||||
|
'item_no' => '5678',
|
||||||
|
'order_number' => '908',
|
||||||
|
'purchase_date' => '2024-12-05',
|
||||||
|
'purchase_cost' => '89.45',
|
||||||
|
'qty' => '10',
|
||||||
|
'min_amt' => '1',
|
||||||
|
'notes' => 'Some Notes',
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->createConsumables()->create())
|
||||||
|
->post(route('consumables.store'), $data + [
|
||||||
|
'redirect_option' => 'index',
|
||||||
|
'category_type' => 'consumable',
|
||||||
|
])
|
||||||
|
->assertRedirect(route('consumables.index'));
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('consumables', $data);
|
||||||
|
}
|
||||||
|
|
||||||
public function testPageRenders()
|
public function testPageRenders()
|
||||||
{
|
{
|
||||||
$this->actingAs(User::factory()->superuser()->create())
|
$this->actingAs(User::factory()->superuser()->create())
|
||||||
->get(route('consumables.create'))
|
->get(route('consumables.create'))
|
||||||
->assertOk();
|
->assertOk();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
45
tests/Feature/Consumables/Ui/DeleteConsumableTest.php
Normal file
45
tests/Feature/Consumables/Ui/DeleteConsumableTest.php
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Consumables\Ui;
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\Consumable;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class DeleteConsumableTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testRequiresPermissionToDeleteConsumable()
|
||||||
|
{
|
||||||
|
$this->actingAs(User::factory()->create())
|
||||||
|
->delete(route('consumables.destroy', Consumable::factory()->create()->id))
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCannotDeleteConsumableFromAnotherCompany()
|
||||||
|
{
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||||
|
|
||||||
|
$consumableForCompanyA = Consumable::factory()->for($companyA)->create();
|
||||||
|
$userForCompanyB = User::factory()->deleteConsumables()->for($companyB)->create();
|
||||||
|
|
||||||
|
$this->actingAs($userForCompanyB)
|
||||||
|
->delete(route('consumables.destroy', $consumableForCompanyA->id))
|
||||||
|
->assertRedirect(route('consumables.index'));
|
||||||
|
|
||||||
|
$this->assertNotSoftDeleted($consumableForCompanyA);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanDeleteConsumable()
|
||||||
|
{
|
||||||
|
$consumable = Consumable::factory()->create();
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->deleteConsumables()->create())
|
||||||
|
->delete(route('consumables.destroy', $consumable->id))
|
||||||
|
->assertRedirect(route('consumables.index'));
|
||||||
|
|
||||||
|
$this->assertSoftDeleted($consumable);
|
||||||
|
}
|
||||||
|
}
|
110
tests/Feature/Consumables/Ui/UpdateConsumableTest.php
Normal file
110
tests/Feature/Consumables/Ui/UpdateConsumableTest.php
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Consumables\Ui;
|
||||||
|
|
||||||
|
use App\Models\Category;
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\Consumable;
|
||||||
|
use App\Models\Location;
|
||||||
|
use App\Models\Manufacturer;
|
||||||
|
use App\Models\Supplier;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class UpdateConsumableTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testRequiresPermissionToSeeEditConsumablePage()
|
||||||
|
{
|
||||||
|
$this->actingAs(User::factory()->create())
|
||||||
|
->get(route('consumables.edit', Consumable::factory()->create()))
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDoesNotShowEditConsumablePageFromAnotherCompany()
|
||||||
|
{
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||||
|
$consumableForCompanyA = Consumable::factory()->for($companyA)->create();
|
||||||
|
$userForCompanyB = User::factory()->editConsumables()->for($companyB)->create();
|
||||||
|
|
||||||
|
$this->actingAs($userForCompanyB)
|
||||||
|
->get(route('consumables.edit', $consumableForCompanyA->id))
|
||||||
|
->assertRedirect(route('consumables.index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEditConsumablePageRenders()
|
||||||
|
{
|
||||||
|
$this->actingAs(User::factory()->editConsumables()->create())
|
||||||
|
->get(route('consumables.edit', Consumable::factory()->create()))
|
||||||
|
->assertOk()
|
||||||
|
->assertViewIs('consumables.edit');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCannotUpdateConsumableBelongingToAnotherCompany()
|
||||||
|
{
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||||
|
|
||||||
|
$consumableForCompanyA = Consumable::factory()->for($companyA)->create();
|
||||||
|
$userForCompanyB = User::factory()->editConsumables()->for($companyB)->create();
|
||||||
|
|
||||||
|
$this->actingAs($userForCompanyB)
|
||||||
|
->put(route('consumables.update', $consumableForCompanyA->id), [
|
||||||
|
//
|
||||||
|
])
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCannotSetQuantityToAmountLowerThanWhatIsCheckedOut()
|
||||||
|
{
|
||||||
|
$user = User::factory()->createConsumables()->editConsumables()->create();
|
||||||
|
$consumable = Consumable::factory()->create(['qty' => 2]);
|
||||||
|
|
||||||
|
$consumable->users()->attach($consumable->id, ['consumable_id' => $consumable->id, 'assigned_to' => $user->id]);
|
||||||
|
$consumable->users()->attach($consumable->id, ['consumable_id' => $consumable->id, 'assigned_to' => $user->id]);
|
||||||
|
|
||||||
|
$this->assertEquals(2, $consumable->numCheckedOut());
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
|
->put(route('consumables.update', $consumable->id), [
|
||||||
|
'qty' => 1,
|
||||||
|
'redirect_option' => 'index',
|
||||||
|
'category_type' => 'consumable',
|
||||||
|
])
|
||||||
|
->assertSessionHasErrors('qty');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanUpdateConsumable()
|
||||||
|
{
|
||||||
|
$consumable = Consumable::factory()->create();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'company_id' => Company::factory()->create()->id,
|
||||||
|
'name' => 'My Consumable',
|
||||||
|
'category_id' => Category::factory()->consumableInkCategory()->create()->id,
|
||||||
|
'supplier_id' => Supplier::factory()->create()->id,
|
||||||
|
'manufacturer_id' => Manufacturer::factory()->create()->id,
|
||||||
|
'location_id' => Location::factory()->create()->id,
|
||||||
|
'model_number' => '8765',
|
||||||
|
'item_no' => '5678',
|
||||||
|
'order_number' => '908',
|
||||||
|
'purchase_date' => '2024-12-05',
|
||||||
|
'purchase_cost' => '89.45',
|
||||||
|
'qty' => '9',
|
||||||
|
'min_amt' => '7',
|
||||||
|
'notes' => 'Some Notes',
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->createConsumables()->editConsumables()->create())
|
||||||
|
->put(route('consumables.update', $consumable->id), $data + [
|
||||||
|
'redirect_option' => 'index',
|
||||||
|
'category_type' => 'consumable',
|
||||||
|
])
|
||||||
|
->assertRedirect(route('consumables.index'));
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('consumables', $data);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue