Skip to content

A free open source IT asset/license management system

Partial fix for license+category tests

snipeaab190423f84
diff --git a/app/Models/License.php b/app/Models/License.php
index 162bea4c3e..5959819c22 100755
--- a/app/Models/License.php
+++ b/app/Models/License.php
@@ -49,7 +49,7 @@ class License extends Depreciable
'license_email' => 'email|nullable|max:120',
'license_name' => 'string|nullable|max:100',
'notes' => 'string|nullable',
- 'category_id' => 'integer',
+ 'category_id' => 'required|exists:categories,id',
'company_id' => 'integer|nullable',
);
diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.php
index b7fe01baa7..26b59ffac2 100644
--- a/database/factories/CategoryFactory.php
+++ b/database/factories/CategoryFactory.php
@@ -114,3 +114,18 @@ $factory->state(App\Models\Category::class, 'consumable-ink-category', function
];
});
+
+$factory->state(App\Models\Category::class, 'license-graphics-category', function ($faker) {
+ return [
+ 'name' => 'Graphics Software',
+ 'category_type' => 'license',
+ ];
+});
+
+
+$factory->state(App\Models\Category::class, 'license-office-category', function ($faker) {
+ return [
+ 'name' => 'Office Software',
+ 'category_type' => 'license',
+ ];
+});
diff --git a/database/factories/LicenseFactory.php b/database/factories/LicenseFactory.php
index 32155fdce1..b4b440f45c 100644
--- a/database/factories/LicenseFactory.php
+++ b/database/factories/LicenseFactory.php
@@ -34,7 +34,8 @@ $factory->state(App\Models\License::class, 'photoshop', function ($faker) {
'purchase_cost' => '299.99',
'seats' => 10,
'purchase_order' => '13503Q',
- 'maintained' => true
+ 'maintained' => true,
+ 'category_id' => 14,
];
return $data;
@@ -49,6 +50,7 @@ $factory->state(App\Models\License::class, 'acrobat', function ($faker) {
'manufacturer_id' => 9,
'purchase_cost' => '29.99',
'seats' => 10,
+ 'category_id' => 14,
];
@@ -62,6 +64,7 @@ $factory->state(App\Models\License::class, 'indesign', function ($faker) {
'manufacturer_id' => 9,
'purchase_cost' => '199.99',
'seats' => 10,
+ 'category_id' => 14,
];
@@ -76,6 +79,7 @@ $factory->state(App\Models\License::class, 'office', function ($faker) {
'manufacturer_id' => 2,
'purchase_cost' => '49.99',
'seats' => 20,
+ 'category_id' => 15,
];
diff --git a/database/seeds/CategorySeeder.php b/database/seeds/CategorySeeder.php
index 728143ca34..dbf4dfca1e 100755
--- a/database/seeds/CategorySeeder.php
+++ b/database/seeds/CategorySeeder.php
@@ -21,6 +21,8 @@ class CategorySeeder extends Seeder
factory(Category::class, 1)->states('consumable-ink-category')->create(); // 11
factory(Category::class, 1)->states('component-hdd-category')->create(); // 12
factory(Category::class, 1)->states('component-ram-category')->create(); // 13
+ factory(Category::class, 1)->states('license-graphics-category')->create(); // 14
+ factory(Category::class, 1)->states('license-office-category')->create(); // 15
}
}
diff --git a/tests/functional/LicensesCest.php b/tests/functional/LicensesCest.php
index e6542c7d41..85c90232c1 100644
--- a/tests/functional/LicensesCest.php
+++ b/tests/functional/LicensesCest.php
@@ -31,6 +31,7 @@ class LicensesCest
$I->seeElement('.alert-danger');
$I->see('The name field is required.', '.alert-msg');
$I->see('The seats field is required.', '.alert-msg');
+ $I->see('The category id field is required.', '.alert-msg');
}
public function failsShortValidation(FunctionalTester $I)
@@ -58,6 +59,7 @@ class LicensesCest
'license_name' => $license->license_name,
'maintained' => true,
'manufacturer_id' => $license->manufacturer_id,
+ 'category_id' => $license->category_id,
'name' => $license->name,
'notes' => $license->notes,
'order_number' => $license->order_number,
diff --git a/tests/unit/ImporterTest.php b/tests/unit/ImporterTest.php
index 7a2803f33e..d020998563 100644
--- a/tests/unit/ImporterTest.php
+++ b/tests/unit/ImporterTest.php
@@ -488,8 +488,8 @@ EOT;
{
$this->signIn();
$csv = <<<'EOT'
-Name,Email,Username,Item name,serial,manufacturer,purchase date,purchase cost,purchase order,order number,Licensed To Name,Licensed to Email,expiration date,maintained,reassignable,seats,company,supplier,notes
-Helen Anderson,[email protected],cspencer0,Argentum Malachite Athletes Foot Relief,1aa5b0eb-79c5-40b2-8943-5472a6893c3c,"Beer, Leannon and Lubowitz",07/13/2012,$79.66,53008,386436062-5,Cynthia Spencer,[email protected],01/27/2016,false,no,80,"Haag, Schmidt and Farrell","Hegmann, Mohr and Cremin",Sed ante. Vivamus tortor. Duis mattis egestas metus.
+Name,Email,Username,Item name,serial,manufacturer,purchase date,purchase cost,purchase order,order number,Licensed To Name,Licensed to Email,expiration date,maintained,reassignable,seats,company,supplier,category,notes
+Helen Anderson,[email protected],cspencer0,Argentum Malachite Athletes Foot Relief,1aa5b0eb-79c5-40b2-8943-5472a6893c3c,"Beer, Leannon and Lubowitz",07/13/2012,$79.66,53008,386436062-5,Cynthia Spencer,[email protected],01/27/2016,false,no,80,"Haag, Schmidt and Farrell","Hegmann, Mohr and Cremin",Graphics Software,Sed ante. Vivamus tortor. Duis mattis egestas metus.
EOT;
$this->import(new LicenseImporter($csv));
// dd($this->tester->grabRecord('licenses'));
@@ -522,6 +522,10 @@ EOT;
'name' => 'Haag, Schmidt and Farrell'
]);
+ $this->tester->seeRecord('categories', [
+ 'name' => 'Graphics Software'
+ ]);
+
$this->tester->seeNumRecords(80, 'license_seats');
}