forked from grokability/snipe-it
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponentTest.php
More file actions
100 lines (82 loc) · 3.64 KB
/
Copy pathComponentTest.php
File metadata and controls
100 lines (82 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?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
{
public function testAComponentBelongsToACompany()
{
$component = Component::factory()
->create(
[
'company_id' => Company::factory()->create()->id
]
);
$this->assertInstanceOf(Company::class, $component->company);
}
public function testAComponentHasALocation()
{
$component = Component::factory()
->create(['location_id' => Location::factory()->create()->id]);
$this->assertInstanceOf(Location::class, $component->location);
}
public function testAComponentBelongsToACategory()
{
$component = Component::factory()->ramCrucial4()
->create(
[
'category_id' =>
Category::factory()->create(
[
'category_type' => 'component'
]
)->id]);
$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());
}
}