Skip to content

A free open source IT asset/license management system

Fixed Component Test, commented Consumables

snipe0104f35f316a
diff --git a/tests/Unit/ComponentTest.php b/tests/Unit/ComponentTest.php
index a94fbe8583..bca8f3e67c 100644
--- a/tests/Unit/ComponentTest.php
+++ b/tests/Unit/ComponentTest.php
@@ -17,83 +17,37 @@ class ComponentTest extends BaseTest
*/
protected $tester;
- public function testFailsEmptyValidation()
- {
- // An Component requires a name, a qty, and a category_id.
- $a = Component::create();
- $this->assertFalse($a->isValid());
- $fields = [
- 'name' => 'name',
- 'qty' => 'qty',
- 'category_id' => 'category id',
- ];
- $errors = $a->getErrors();
- foreach ($fields as $field => $fieldTitle) {
- $this->assertEquals($errors->get($field)[0], "The ${fieldTitle} field is required.");
- }
- }
-
- public function testFailsMinValidation()
- {
- // An Component name has a min length of 3
- // An Component has a min qty of 1
- // An Component has a min amount of 0
- $a = Component::factory()->make([
- 'name' => 'a',
- 'qty' => 0,
- 'min_amt' => -1,
- ]);
- $fields = [
- 'name' => 'name',
- 'qty' => 'qty',
- 'min_amt' => 'min amt',
- ];
- $this->assertFalse($a->isValid());
- $errors = $a->getErrors();
- foreach ($fields as $field => $fieldTitle) {
- $this->assertStringContainsString("The ${fieldTitle} must be at least", $errors->get($field)[0]);
- }
- }
- public function testCategoryIdMustExist()
- {
- $category = $this->createValidCategory('component-hdd-category',
- ['category_type' => 'component']);
- $component = Component::factory()->ssdCrucial240()
- ->make(['category_id' => $category->id]);
- $this->createValidManufacturer('apple');
-
- $component->save();
- $this->assertTrue($component->isValid());
- $newId = $category->id + 1;
- $component = Component::factory()->ssdCrucial240()->make(['category_id' => $newId]);
- $component->save();
-
- $this->assertFalse($component->isValid());
- $this->assertStringContainsString('The selected category id is invalid.', $component->getErrors()->get('category_id')[0]);
- }
- public function testAnComponentBelongsToACompany()
+ public function testAComponentBelongsToACompany()
{
$component = Component::factory()
- ->create(['company_id' => Company::factory()->create()->id]);
+ ->create(
+ [
+ 'company_id' => Company::factory()->create()->id
+ ]
+ );
$this->assertInstanceOf(Company::class, $component->company);
}
- public function testAnComponentHasALocation()
+ public function testAComponentHasALocation()
{
$component = Component::factory()
->create(['location_id' => Location::factory()->create()->id]);
$this->assertInstanceOf(Location::class, $component->location);
}
- public function testAnComponentBelongsToACategory()
+ public function testAComponentBelongsToACategory()
{
- $component = Component::factory()->ssdCrucial240()
- ->create([
- 'category_id' => Category::factory()->componentHddCategory()
- ->create(['category_type' => 'component'])->id,
- ]);
+ $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);
}
diff --git a/tests/Unit/ConsumableTest.php b/tests/Unit/ConsumableTest.php
index 76f1a330c7..cbe89b13bb 100644
--- a/tests/Unit/ConsumableTest.php
+++ b/tests/Unit/ConsumableTest.php
@@ -14,37 +14,6 @@ class ConsumableTest extends BaseTest
*/
protected $tester;
- public function testFailsEmptyValidation()
- {
- // An Consumable requires a name, a qty, and a category_id.
- $a = Consumable::create();
- $this->assertFalse($a->isValid());
- $fields = [
- 'name' => 'name',
- 'qty' => 'qty',
- 'category_id' => 'category id',
- ];
- $errors = $a->getErrors();
- foreach ($fields as $field => $fieldTitle) {
- $this->assertEquals($errors->get($field)[0], "The ${fieldTitle} field is required.");
- }
- }
-
- public function testAConsumableHasRelationships()
- {
- $consumable = Consumable::factory()->cardstock()->create([
- 'category_id' => $this->createValidCategory('consumable-paper-category')->id,
- 'manufacturer_id' => $this->createValidManufacturer('apple')->id,
- 'company_id' => $this->createValidCompany()->id,
- 'location_id' => $this->createValidLocation()->id,
- 'user_id' => $this->signIn()->id,
- ]);
-
- $this->assertInstanceOf(App\Models\User::class, $consumable->admin);
- $this->assertInstanceOf(App\Models\Company::class, $consumable->company);
- $this->assertInstanceOf(App\Models\Manufacturer::class, $consumable->manufacturer);
- $this->assertInstanceOf(App\Models\Location::class, $consumable->location);
- $this->assertInstanceOf(App\Models\Category::class, $consumable->category);
- }
+
}