Skip to content

A free open source IT asset/license management system

Added/updated tests

snipe3de5f5882cd8
diff --git a/tests/Feature/Categories/Api/CreateCategoriesTest.php b/tests/Feature/Categories/Api/CreateCategoriesTest.php
index fc464242af..2a4a0661a6 100644
--- a/tests/Feature/Categories/Api/CreateCategoriesTest.php
+++ b/tests/Feature/Categories/Api/CreateCategoriesTest.php
@@ -27,6 +27,7 @@ class CreateCategoriesTest extends TestCase
'name' => 'Test Category',
'eula_text' => 'Test EULA',
'category_type' => 'accessory',
+ 'notes' => 'Test Note',
])
->assertOk()
->assertStatusMessageIs('success')
@@ -38,6 +39,7 @@ class CreateCategoriesTest extends TestCase
$category = Category::find($response['payload']['id']);
$this->assertEquals('Test Category', $category->name);
$this->assertEquals('Test EULA', $category->eula_text);
+ $this->assertEquals('Test Note', $category->notes);
$this->assertEquals('accessory', $category->category_type);
}
diff --git a/tests/Feature/Categories/Api/UpdateCategoriesTest.php b/tests/Feature/Categories/Api/UpdateCategoriesTest.php
index 1a784c1179..6d6bc8da10 100644
--- a/tests/Feature/Categories/Api/UpdateCategoriesTest.php
+++ b/tests/Feature/Categories/Api/UpdateCategoriesTest.php
@@ -17,6 +17,7 @@ class UpdateCategoriesTest extends TestCase
->patchJson(route('api.categories.update', $category), [
'name' => 'Test Category',
'eula_text' => 'Test EULA',
+ 'notes' => 'Test Note',
])
->assertOk()
->assertStatusMessageIs('success')
@@ -27,6 +28,7 @@ class UpdateCategoriesTest extends TestCase
$category->refresh();
$this->assertEquals('Test Category', $category->name, 'Name was not updated');
$this->assertEquals('Test EULA', $category->eula_text, 'EULA was not updated');
+ $this->assertEquals('Test Note', $category->notes, 'Note was not updated');
}
@@ -39,6 +41,7 @@ class UpdateCategoriesTest extends TestCase
'name' => 'Test Category',
'eula_text' => 'Test EULA',
'category_type' => 'accessory',
+ 'note' => 'Test Note',
])
->assertOk()
->assertStatusMessageIs('error')
@@ -48,6 +51,7 @@ class UpdateCategoriesTest extends TestCase
$category->refresh();
$this->assertNotEquals('Test Category', $category->name, 'Name was not updated');
$this->assertNotEquals('Test EULA', $category->eula_text, 'EULA was not updated');
+ $this->assertNotEquals('Test Note', $category->notes, 'Note was not updated');
$this->assertNotEquals('accessory', $category->category_type, 'EULA was not updated');
}
diff --git a/tests/Feature/Categories/Ui/CreateCategoriesTest.php b/tests/Feature/Categories/Ui/CreateCategoriesTest.php
index 45e821d9d9..694b61c613 100644
--- a/tests/Feature/Categories/Ui/CreateCategoriesTest.php
+++ b/tests/Feature/Categories/Ui/CreateCategoriesTest.php
@@ -33,11 +33,12 @@ class CreateCategoriesTest extends TestCase
$this->actingAs(User::factory()->superuser()->create())
->post(route('categories.store'), [
'name' => 'Test Category',
- 'category_type' => 'asset'
+ 'category_type' => 'asset',
+ 'notes' => 'Test Note',
])
->assertRedirect(route('categories.index'));
- $this->assertTrue(Category::where('name', 'Test Category')->exists());
+ $this->assertTrue(Category::where('name', 'Test Category')->where('notes', 'Test Note')->exists());
}
public function testUserCannotCreateCategoriesWithInvalidType()
@@ -48,7 +49,7 @@ class CreateCategoriesTest extends TestCase
->from(route('categories.create'))
->post(route('categories.store'), [
'name' => 'Test Category',
- 'category_type' => 'invalid'
+ 'category_type' => 'invalid',
])
->assertRedirect(route('categories.create'));
diff --git a/tests/Feature/Categories/Ui/UpdateCategoriesTest.php b/tests/Feature/Categories/Ui/UpdateCategoriesTest.php
index 901b779582..7e61097793 100644
--- a/tests/Feature/Categories/Ui/UpdateCategoriesTest.php
+++ b/tests/Feature/Categories/Ui/UpdateCategoriesTest.php
@@ -32,7 +32,7 @@ class UpdateCategoriesTest extends TestCase
$this->actingAs(User::factory()->superuser()->create())
->post(route('categories.store'), [
'name' => 'Test Category',
- 'category_type' => 'asset'
+ 'category_type' => 'asset',
])
->assertStatus(302)
->assertSessionHasNoErrors()
@@ -49,13 +49,14 @@ class UpdateCategoriesTest extends TestCase
$response = $this->actingAs(User::factory()->superuser()->create())
->put(route('categories.update', ['category' => $category]), [
'name' => 'Test Category Edited',
+ 'notes' => 'Test Note Edited',
])
->assertStatus(302)
->assertSessionHasNoErrors()
->assertRedirect(route('categories.index'));
$this->followRedirects($response)->assertSee('Success');
- $this->assertTrue(Category::where('name', 'Test Category Edited')->exists());
+ $this->assertTrue(Category::where('name', 'Test Category Edited')->where('notes', 'Test Note Edited')->exists());
}
@@ -69,13 +70,14 @@ class UpdateCategoriesTest extends TestCase
->put(route('categories.update', ['category' => $category]), [
'name' => 'Test Category Edited',
'category_type' => 'accessory',
+ 'notes' => 'Test Note Edited',
])
->assertSessionHasNoErrors()
->assertStatus(302)
->assertRedirect(route('categories.index'));
$this->followRedirects($response)->assertSee('Success');
- $this->assertTrue(Category::where('name', 'Test Category Edited')->exists());
+ $this->assertTrue(Category::where('name', 'Test Category Edited')->where('notes', 'Test Note Edited')->exists());
}
@@ -89,6 +91,7 @@ class UpdateCategoriesTest extends TestCase
->put(route('categories.update', ['category' => $category]), [
'name' => 'Test Category Edited',
'category_type' => 'accessory',
+ 'notes' => 'Test Note Edited',
])
->assertSessionHasErrors(['category_type'])
->assertInvalid(['category_type'])
@@ -96,7 +99,7 @@ class UpdateCategoriesTest extends TestCase
->assertRedirect(route('categories.edit', ['category' => $category->id]));
$this->followRedirects($response)->assertSee(trans('general.error'));
- $this->assertFalse(Category::where('name', 'Test Category Edited')->exists());
+ $this->assertFalse(Category::where('name', 'Test Category Edited')->where('notes', 'Test Note Edited')->exists());
}
diff --git a/tests/Feature/Departments/Api/CreateDepartmentsTest.php b/tests/Feature/Departments/Api/CreateDepartmentsTest.php
index a8725c5ff2..e0f975dd7f 100644
--- a/tests/Feature/Departments/Api/CreateDepartmentsTest.php
+++ b/tests/Feature/Departments/Api/CreateDepartmentsTest.php
@@ -20,4 +20,23 @@ class CreateDepartmentsTest extends TestCase
->assertForbidden();
}
+ public function testCanCreateDepartment()
+ {
+ $response = $this->actingAsForApi(User::factory()->superuser()->create())
+ ->postJson(route('api.departments.store'), [
+ 'name' => 'Test Department',
+ 'notes' => 'Test Note',
+ ])
+ ->assertOk()
+ ->assertStatusMessageIs('success')
+ ->assertStatus(200)
+ ->json();
+
+ $this->assertTrue(Department::where('name', 'Test Department')->exists());
+
+ $department = Department::find($response['payload']['id']);
+ $this->assertEquals('Test Department', $department->name);
+ $this->assertEquals('Test Note', $department->notes);
+ }
+
}
diff --git a/tests/Feature/Departments/Api/UpdateDepartmentsTest.php b/tests/Feature/Departments/Api/UpdateDepartmentsTest.php
index 2a6401e7f1..b4eb38301a 100644
--- a/tests/Feature/Departments/Api/UpdateDepartmentsTest.php
+++ b/tests/Feature/Departments/Api/UpdateDepartmentsTest.php
@@ -25,6 +25,7 @@ class UpdateDepartmentsTest extends TestCase
$this->actingAsForApi(User::factory()->superuser()->create())
->patchJson(route('api.departments.update', $department), [
'name' => 'Test Department',
+ 'notes' => 'Test Note',
])
->assertOk()
->assertStatusMessageIs('success')
@@ -33,6 +34,7 @@ class UpdateDepartmentsTest extends TestCase
$department->refresh();
$this->assertEquals('Test Department', $department->name, 'Name was not updated');
+ $this->assertEquals('Test Note', $department->notes, 'Note was not updated');
}
diff --git a/tests/Feature/Departments/Ui/CreateDepartmentsTest.php b/tests/Feature/Departments/Ui/CreateDepartmentsTest.php
index 08dc12ba09..f20a2c7b6a 100644
--- a/tests/Feature/Departments/Ui/CreateDepartmentsTest.php
+++ b/tests/Feature/Departments/Ui/CreateDepartmentsTest.php
@@ -34,11 +34,12 @@ class CreateDepartmentsTest extends TestCase
$this->actingAs(User::factory()->superuser()->create())
->post(route('departments.store'), [
'name' => 'Test Department',
- 'company_id' => Company::factory()->create()->id
+ 'company_id' => Company::factory()->create()->id,
+ 'notes' => 'Test Note',
])
->assertRedirect(route('departments.index'));
- $this->assertTrue(Department::where('name', 'Test Department')->exists());
+ $this->assertTrue(Department::where('name', 'Test Department')->where('notes', 'Test Note')->exists());
}
diff --git a/tests/Feature/Departments/Ui/UpdateDepartmentsTest.php b/tests/Feature/Departments/Ui/UpdateDepartmentsTest.php
index 71f7cfe477..bb5fc27e14 100644
--- a/tests/Feature/Departments/Ui/UpdateDepartmentsTest.php
+++ b/tests/Feature/Departments/Ui/UpdateDepartmentsTest.php
@@ -34,13 +34,14 @@ class UpdateDepartmentsTest extends TestCase
$response = $this->actingAs(User::factory()->superuser()->create())
->put(route('departments.update', ['department' => $department]), [
'name' => 'Test Department Edited',
+ 'notes' => 'Test Note Edited',
])
->assertStatus(302)
->assertSessionHasNoErrors()
->assertRedirect(route('departments.index'));
$this->followRedirects($response)->assertSee('Success');
- $this->assertTrue(Department::where('name', 'Test Department Edited')->exists());
+ $this->assertTrue(Department::where('name', 'Test Department Edited')->where('notes', 'Test Note Edited')->exists());
}
diff --git a/tests/Feature/Groups/Api/StoreGroupTest.php b/tests/Feature/Groups/Api/StoreGroupTest.php
index ebcbff71c5..484c921a6c 100644
--- a/tests/Feature/Groups/Api/StoreGroupTest.php
+++ b/tests/Feature/Groups/Api/StoreGroupTest.php
@@ -21,6 +21,7 @@ class StoreGroupTest extends TestCase
$this->actingAsForApi(User::factory()->superuser()->create())
->postJson(route('api.groups.store'), [
'name' => 'My Awesome Group',
+ 'notes' => 'My Awesome Note',
'permissions' => [
'admin' => '1',
'import' => '1',
@@ -29,7 +30,7 @@ class StoreGroupTest extends TestCase
])
->assertOk();
- $group = Group::where('name', 'My Awesome Group')->first();
+ $group = Group::where('name', 'My Awesome Group')->where('notes', 'My Awesome Note')->first();
$this->assertNotNull($group);
$this->assertEquals('1', $group->decodePermissions()['admin']);
diff --git a/tests/Feature/Groups/Ui/CreateGroupTest.php b/tests/Feature/Groups/Ui/CreateGroupTest.php
index 56b3a76053..796905c50f 100644
--- a/tests/Feature/Groups/Ui/CreateGroupTest.php
+++ b/tests/Feature/Groups/Ui/CreateGroupTest.php
@@ -2,6 +2,7 @@
namespace Tests\Feature\Groups\Ui;
+use App\Models\Group;
use App\Models\User;
use Tests\TestCase;
@@ -13,4 +14,18 @@ class CreateGroupTest extends TestCase
->get(route('groups.create'))
->assertOk();
}
+
+ public function testUserCanCreateGroup()
+ {
+ $this->assertFalse(Group::where('name', 'Test Group')->exists());
+
+ $this->actingAs(User::factory()->superuser()->create())
+ ->post(route('groups.store'), [
+ 'name' => 'Test Group',
+ 'notes' => 'Test Note',
+ ])
+ ->assertRedirect(route('groups.index'));
+
+ $this->assertTrue(Group::where('name', 'Test Group')->where('notes', 'Test Note')->exists());
+ }
}
diff --git a/tests/Feature/Groups/Ui/UpdateGroupTest.php b/tests/Feature/Groups/Ui/UpdateGroupTest.php
index c68d7cb84b..edb2368726 100644
--- a/tests/Feature/Groups/Ui/UpdateGroupTest.php
+++ b/tests/Feature/Groups/Ui/UpdateGroupTest.php
@@ -14,4 +14,22 @@ class UpdateGroupTest extends TestCase
->get(route('groups.edit', Group::factory()->create()->id))
->assertOk();
}
+
+ public function testUserCanEditGroups()
+ {
+ $group = Group::factory()->create(['name' => 'Test Group']);
+ $this->assertTrue(Group::where('name', 'Test Group')->exists());
+
+ $response = $this->actingAs(User::factory()->superuser()->create())
+ ->put(route('groups.update', ['group' => $group]), [
+ 'name' => 'Test Group Edited',
+ 'notes' => 'Test Note Edited',
+ ])
+ ->assertStatus(302)
+ ->assertSessionHasNoErrors()
+ ->assertRedirect(route('groups.index'));
+
+ $this->followRedirects($response)->assertSee('Success');
+ $this->assertTrue(Group::where('name', 'Test Group Edited')->where('notes', 'Test Note Edited')->exists());
+ }
}
diff --git a/tests/Feature/Locations/Api/CreateLocationsTest.php b/tests/Feature/Locations/Api/CreateLocationsTest.php
index 171508b725..0a75517f31 100644
--- a/tests/Feature/Locations/Api/CreateLocationsTest.php
+++ b/tests/Feature/Locations/Api/CreateLocationsTest.php
@@ -16,6 +16,26 @@ class CreateLocationsTest extends TestCase
->assertForbidden();
}
+
+ public function testCanCreateLocation()
+ {
+ $response = $this->actingAsForApi(User::factory()->superuser()->create())
+ ->postJson(route('api.locations.store'), [
+ 'name' => 'Test Location',
+ 'notes' => 'Test Note',
+ ])
+ ->assertOk()
+ ->assertStatusMessageIs('success')
+ ->assertStatus(200)
+ ->json();
+
+ $this->assertTrue(Location::where('name', 'Test Location')->exists());
+
+ $department = Location::find($response['payload']['id']);
+ $this->assertEquals('Test Location', $department->name);
+ $this->assertEquals('Test Note', $department->notes);
+ }
+
public function testCannotCreateNewLocationsWithTheSameName()
{
$location = Location::factory()->create();
diff --git a/tests/Feature/Locations/Api/UpdateLocationsTest.php b/tests/Feature/Locations/Api/UpdateLocationsTest.php
index a3dd8c228c..a169ba87bf 100644
--- a/tests/Feature/Locations/Api/UpdateLocationsTest.php
+++ b/tests/Feature/Locations/Api/UpdateLocationsTest.php
@@ -22,7 +22,8 @@ class UpdateLocationsTest extends TestCase
$this->actingAsForApi(User::factory()->superuser()->create())
->patchJson(route('api.locations.update', $location), [
- 'name' => 'Test Location',
+ 'name' => 'Test Updated Location',
+ 'notes' => 'Test Updated Note',
])
->assertOk()
->assertStatusMessageIs('success')
@@ -30,7 +31,8 @@ class UpdateLocationsTest extends TestCase
->json();
$location->refresh();
- $this->assertEquals('Test Location', $location->name, 'Name was not updated');
+ $this->assertEquals('Test Updated Location', $location->name, 'Name was not updated');
+ $this->assertEquals('Test Updated Note', $location->notes, 'Note was not updated');
}
diff --git a/tests/Feature/Locations/Ui/CreateLocationsTest.php b/tests/Feature/Locations/Ui/CreateLocationsTest.php
index 2e2e1e0aa9..794ee06c67 100644
--- a/tests/Feature/Locations/Ui/CreateLocationsTest.php
+++ b/tests/Feature/Locations/Ui/CreateLocationsTest.php
@@ -33,11 +33,11 @@ class CreateLocationsTest extends TestCase
$this->actingAs(User::factory()->superuser()->create())
->post(route('locations.store'), [
'name' => 'Test Location',
- 'company_id' => Company::factory()->create()->id
+ 'notes' => 'Test Note',
])
->assertRedirect(route('locations.index'));
- $this->assertTrue(Location::where('name', 'Test Location')->exists());
+ $this->assertTrue(Location::where('name', 'Test Location')->where('notes', 'Test Note')->exists());
}
public function testUserCannotCreateLocationsWithInvalidParent()
diff --git a/tests/Feature/Locations/Ui/UpdateLocationsTest.php b/tests/Feature/Locations/Ui/UpdateLocationsTest.php
index 6cead815bc..c38ee25f8e 100644
--- a/tests/Feature/Locations/Ui/UpdateLocationsTest.php
+++ b/tests/Feature/Locations/Ui/UpdateLocationsTest.php
@@ -33,13 +33,14 @@ class UpdateLocationsTest extends TestCase
$response = $this->actingAs(User::factory()->superuser()->create())
->put(route('locations.update', ['location' => $location]), [
'name' => 'Test Location Edited',
+ 'notes' => 'Test Note Edited',
])
->assertStatus(302)
->assertSessionHasNoErrors()
->assertRedirect(route('locations.index'));
$this->followRedirects($response)->assertSee('Success');
- $this->assertTrue(Location::where('name', 'Test Location Edited')->exists());
+ $this->assertTrue(Location::where('name', 'Test Location Edited')->where('notes', 'Test Note Edited')->exists());
}
public function testUserCannotEditLocationsToMakeThemTheirOwnParent()
diff --git a/tests/Feature/Manufacturers/Api/CreateManufacturersTest.php b/tests/Feature/Manufacturers/Api/CreateManufacturersTest.php
new file mode 100644
index 0000000000..9dc953148e
--- /dev/null
+++ b/tests/Feature/Manufacturers/Api/CreateManufacturersTest.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Tests\Feature\Manufacturers\Api;
+
+use App\Models\Manufacturer;
+use App\Models\User;
+use Tests\TestCase;
+
+class CreateManufacturersTest extends TestCase
+{
+
+
+ public function testRequiresPermissionToCreateDepartment()
+ {
+ $this->actingAsForApi(User::factory()->create())
+ ->postJson(route('api.departments.store'))
+ ->assertForbidden();
+ }
+
+ public function testCanCreateManufacturer()
+ {
+ $response = $this->actingAsForApi(User::factory()->superuser()->create())
+ ->postJson(route('api.manufacturers.store'), [
+ 'name' => 'Test Manufacturer',
+ 'notes' => 'Test Note',
+ ])
+ ->assertOk()
+ ->assertStatusMessageIs('success')
+ ->assertStatus(200)
+ ->json();
+
+ $this->assertTrue(Manufacturer::where('name', 'Test Manufacturer')->where('notes', 'Test Note')->exists());
+
+ $manufacturer = Manufacturer::find($response['payload']['id']);
+ $this->assertEquals('Test Manufacturer', $manufacturer->name);
+ $this->assertEquals('Test Note', $manufacturer->notes);
+ }
+
+}
diff --git a/tests/Feature/Manufacturers/Api/UpdateManufacturersTest.php b/tests/Feature/Manufacturers/Api/UpdateManufacturersTest.php
new file mode 100644
index 0000000000..d3ab461b4f
--- /dev/null
+++ b/tests/Feature/Manufacturers/Api/UpdateManufacturersTest.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Tests\Feature\Manufacturers\Ui;
+
+use App\Models\Manufacturer;
+use App\Models\Category;
+use App\Models\User;
+use Tests\TestCase;
+
+class UpdateManufacturersTest extends TestCase
+{
+ public function testPermissionRequiredToStoreManufacturer()
+ {
+ $this->actingAs(User::factory()->create())
+ ->post(route('manufacturers.store'), [
+ 'name' => 'Test Manufacturer',
+ ])
+ ->assertStatus(403)
+ ->assertForbidden();
+ }
+
+ public function testPageRenders()
+ {
+ $this->actingAs(User::factory()->superuser()->create())
+ ->get(route('manufacturers.edit', Manufacturer::factory()->create()->id))
+ ->assertOk();
+ }
+
+ public function testUserCanEditManufacturers()
+ {
+ $department = Manufacturer::factory()->create(['name' => 'Test Manufacturer']);
+ $this->assertTrue(Manufacturer::where('name', 'Test Manufacturer')->exists());
+
+ $response = $this->actingAs(User::factory()->superuser()->create())
+ ->put(route('manufacturers.update', ['manufacturer' => $department]), [
+ 'name' => 'Test Manufacturer Edited',
+ 'notes' => 'Test Note Edited',
+ ])
+ ->assertStatus(302)
+ ->assertSessionHasNoErrors()
+ ->assertRedirect(route('manufacturers.index'));
+
+ $this->followRedirects($response)->assertSee('Success');
+ $this->assertTrue(Manufacturer::where('name', 'Test Manufacturer Edited')->where('notes', 'Test Note Edited')->exists());
+
+ }
+
+
+
+}
diff --git a/tests/Feature/Manufacturers/Ui/CreateManufacturerTest.php b/tests/Feature/Manufacturers/Ui/CreateManufacturerTest.php
index 133b271ea3..4eb9d4fb7e 100644
--- a/tests/Feature/Manufacturers/Ui/CreateManufacturerTest.php
+++ b/tests/Feature/Manufacturers/Ui/CreateManufacturerTest.php
@@ -3,6 +3,7 @@
namespace Tests\Feature\Manufacturers\Ui;
use App\Models\User;
+use App\Models\Manufacturer;
use Tests\TestCase;
class CreateManufacturerTest extends TestCase
@@ -13,4 +14,19 @@ class CreateManufacturerTest extends TestCase
->get(route('manufacturers.create'))
->assertOk();
}
+
+ public function testUserCanCreateManufacturer()
+ {
+ $this->assertFalse(Manufacturer::where('name', 'Test Manufacturer')->exists());
+
+ $this->actingAs(User::factory()->superuser()->create())
+ ->post(route('manufacturers.store'), [
+ 'name' => 'Test Manufacturer',
+ 'notes' => 'Test Note',
+ ])
+ ->assertRedirect(route('manufacturers.index'));
+
+ $this->assertTrue(Manufacturer::where('name', 'Test Manufacturer')->where('notes', 'Test Note')->exists());
+ }
+
}
diff --git a/tests/Feature/Manufacturers/Ui/UpdateManufacturerTest.php b/tests/Feature/Manufacturers/Ui/UpdateManufacturerTest.php
index e2f7724fa3..398b7fe239 100644
--- a/tests/Feature/Manufacturers/Ui/UpdateManufacturerTest.php
+++ b/tests/Feature/Manufacturers/Ui/UpdateManufacturerTest.php
@@ -14,4 +14,23 @@ class UpdateManufacturerTest extends TestCase
->get(route('manufacturers.edit', Manufacturer::factory()->create()->id))
->assertOk();
}
+
+ public function testUserCanEditManufacturers()
+ {
+ $manufacturer = Manufacturer::factory()->create(['name' => 'Test Manufacturer']);
+ $this->assertTrue(Manufacturer::where('name', 'Test Manufacturer')->exists());
+
+ $response = $this->actingAs(User::factory()->superuser()->create())
+ ->put(route('manufacturers.update', ['manufacturer' => $manufacturer]), [
+ 'name' => 'Test Manufacturer Edited',
+ 'notes' => 'Test Note Edited',
+ ])
+ ->assertStatus(302)
+ ->assertSessionHasNoErrors()
+ ->assertRedirect(route('manufacturers.index'));
+
+ $this->followRedirects($response)->assertSee('Success');
+ $this->assertTrue(Manufacturer::where('name', 'Test Manufacturer Edited')->where('notes', 'Test Note Edited')->exists());
+ }
+
}