mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Scaffold additional failed tests
This commit is contained in:
parent
374812f8fe
commit
0aff35b622
|
@ -21,7 +21,7 @@ class ComponentsCheckoutTest extends TestCase
|
|||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testCannotCheckoutAcrossCompaniesWhenFullCompanySupportEnabled()
|
||||
public function test_cannot_checkout_across_companies_when_full_company_support_enabled()
|
||||
{
|
||||
Event::fake([CheckoutableCheckedOut::class]);
|
||||
|
||||
|
@ -36,9 +36,6 @@ class ComponentsCheckoutTest extends TestCase
|
|||
->post(route('components.checkout.store', $component), [
|
||||
'asset_id' => $asset->id,
|
||||
'assigned_qty' => '1',
|
||||
// @todo:
|
||||
'note' => null,
|
||||
// @todo:
|
||||
'redirect_option' => 'index',
|
||||
]);
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
<?php
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\Category;
|
||||
use App\Models\Company;
|
||||
use App\Models\Component;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ComponentTest extends TestCase
|
||||
|
@ -41,4 +43,58 @@ class ComponentTest extends TestCase
|
|||
$this->assertInstanceOf(Category::class, $component->category);
|
||||
$this->assertEquals('component', $component->category->category_type);
|
||||
}
|
||||
|
||||
public function test_num_checked_out_takes_does_not_scope_by_company()
|
||||
{
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||
|
||||
$componentForCompanyA = Component::factory()->for($companyA)->create(['qty' => 5]);
|
||||
$assetForCompanyB = Asset::factory()->for($companyB)->create();
|
||||
|
||||
// Ideally, we shouldn't have a component attached to an
|
||||
// asset from a different company but alas...
|
||||
$componentForCompanyA->assets()->attach($componentForCompanyA->id, [
|
||||
'component_id' => $componentForCompanyA->id,
|
||||
'assigned_qty' => 4,
|
||||
'asset_id' => $assetForCompanyB->id,
|
||||
]);
|
||||
|
||||
$this->actingAs(User::factory()->superuser()->create());
|
||||
$this->assertEquals(4, $componentForCompanyA->fresh()->numCheckedOut());
|
||||
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
$this->assertEquals(4, $componentForCompanyA->fresh()->numCheckedOut());
|
||||
|
||||
$this->actingAs(User::factory()->for($companyA)->create());
|
||||
$this->assertEquals(4, $componentForCompanyA->fresh()->numCheckedOut());
|
||||
}
|
||||
|
||||
public function test_num_remaining_takes_company_scoping_into_account()
|
||||
{
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||
|
||||
$componentForCompanyA = Component::factory()->for($companyA)->create(['qty' => 5]);
|
||||
$assetForCompanyB = Asset::factory()->for($companyB)->create();
|
||||
|
||||
// Ideally, we shouldn't have a component attached to an
|
||||
// asset from a different company but alas...
|
||||
$componentForCompanyA->assets()->attach($componentForCompanyA->id, [
|
||||
'component_id' => $componentForCompanyA->id,
|
||||
'assigned_qty' => 4,
|
||||
'asset_id' => $assetForCompanyB->id,
|
||||
]);
|
||||
|
||||
$this->actingAs(User::factory()->superuser()->create());
|
||||
$this->assertEquals(1, $componentForCompanyA->fresh()->numRemaining());
|
||||
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
$this->assertEquals(1, $componentForCompanyA->fresh()->numRemaining());
|
||||
|
||||
$this->actingAs(User::factory()->for($companyA)->create());
|
||||
$this->assertEquals(1, $componentForCompanyA->fresh()->numRemaining());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue