Skip to content

A free open source IT asset/license management system

Added some tests around license seat changes

Brady Wetheringtona7a597d6095a
diff --git a/tests/Feature/Licenses/Ui/CreateLicenseTest.php b/tests/Feature/Licenses/Ui/CreateLicenseTest.php
index 33f825bf95..535f0b3dba 100644
--- a/tests/Feature/Licenses/Ui/CreateLicenseTest.php
+++ b/tests/Feature/Licenses/Ui/CreateLicenseTest.php
@@ -2,7 +2,6 @@
namespace Tests\Feature\Licenses\Ui;
-use App\Models\AssetModel;
use App\Models\Category;
use App\Models\License;
use App\Models\Depreciation;
@@ -41,7 +40,48 @@ class CreateLicenseTest extends TestCase
$response->assertInvalid(['purchase_date']);
$response->assertSessionHasErrors(['purchase_date']);
$this->followRedirects($response)->assertSee(trans('general.error'));
- $this->assertFalse(AssetModel::where('name', 'Test Invalid License')->exists());
+ $this->assertFalse(License::where('name', 'Test Invalid License')->exists());
}
+
+ public function testLicenseCreate()
+ {
+ $response = $this->actingAs(User::factory()->superuser()->create())
+ ->from(route('licenses.create'))
+ ->post(route('licenses.store'), [
+ 'name' => 'Test Valid License',
+ 'seats' => '10',
+ 'category_id' => Category::factory()->forLicenses()->create()->id,
+ ]);
+ $response->assertStatus(302);
+ $license = License::where('name', 'Test Valid License')->sole();
+ $this->assertNotNull($license);
+ //$license->assetlog()->has_one_of_();
+ $this->assertDatabaseHas('action_logs', ['action_type' => 'create', 'item_id' => $license->id, 'item_type' => License::class]);
+ $this->assertDatabaseHas('action_logs', ['action_type' => 'add seats', 'item_id' => $license->id, 'item_type' => License::class]);
+ $this->assertEquals($license->licenseseats()->count(), 10);
+ //test log entries? Sure.
+
+ }
+
+ public function testTooManySeatsLicenseCreate()
+ {
+ $response = $this->actingAs(User::factory()->superuser()->create())
+ ->from(route('licenses.create'))
+ ->post(route('licenses.store'), [
+ 'name' => 'Test Valid License',
+ 'seats' => '100000',
+ 'category_id' => Category::factory()->forLicenses()->create()->id,
+ ]);
+ $response->assertStatus(302);
+ $license = License::where('name', 'Test Valid License')->first();
+ $this->assertNull($license);
+ //$license->assetlog()->has_one_of_();
+// $this->assertDatabaseMissing('action_logs', ['action_type' => 'create', 'item_id' => $license->id, 'item_type' => License::class]);
+// $this->assertDatabaseMissing('action_logs', ['action_type' => 'add seats', 'item_id' => $license->id, 'item_type' => License::class]);
+ //test log entries? Sure.
+
+ }
+
+
}
diff --git a/tests/Feature/Licenses/Ui/UpdateLicenseTest.php b/tests/Feature/Licenses/Ui/UpdateLicenseTest.php
index 7b1b5b29e3..46c4f70785 100644
--- a/tests/Feature/Licenses/Ui/UpdateLicenseTest.php
+++ b/tests/Feature/Licenses/Ui/UpdateLicenseTest.php
@@ -2,6 +2,7 @@
namespace Tests\Feature\Licenses\Ui;
+use App\Models\Category;
use App\Models\License;
use App\Models\User;
use Tests\TestCase;
@@ -14,4 +15,90 @@ class UpdateLicenseTest extends TestCase
->get(route('licenses.edit', License::factory()->create()->id))
->assertOk();
}
+
+ public function testCanUpdateLicenseSeats()
+ {
+ $admin = User::factory()->superuser()->create();
+ $license_category = Category::factory()->forLicenses()->create()->id;
+ $response = $this->actingAs($admin)
+ ->from(route('licenses.create'))
+ ->post(route('licenses.store'), [
+ 'name' => 'Test Update License',
+ 'seats' => '9999',
+ 'category_id' => $license_category,
+ ]);
+ $response->assertStatus(302);
+ $license = License::where('name', 'Test Update License')->sole();
+ $this->assertNotNull($license);
+
+ $this->actingAs($admin)
+ ->put(route('licenses.update', $license->id), [
+ 'name' => 'Test Update License',
+ 'seats' => '19999',
+ 'category_id' => $license_category,
+ ])
+ ->assertStatus(302);
+
+ $license->refresh();
+ $this->assertEquals($license->licenseseats()->count(), $license->seats);
+ $this->assertEquals($license->licenseseats()->count(), 19999);
+ }
+
+ public function testCannotUpdateLicenseSeatsTooMuch()
+ {
+ $admin = User::factory()->superuser()->create();
+ $license_category = Category::factory()->forLicenses()->create()->id;
+ $response = $this->actingAs($admin)
+ ->from(route('licenses.create'))
+ ->post(route('licenses.store'), [
+ 'name' => 'Test Update License',
+ 'seats' => '9999',
+ 'category_id' => $license_category,
+ ]);
+ $response->assertStatus(302);
+ $license = License::where('name', 'Test Update License')->sole();
+ $this->assertNotNull($license);
+
+ $this->actingAs($admin)
+ ->put(route('licenses.update', $license->id), [
+ 'name' => 'Test Update License',
+ 'seats' => '29999',
+ 'category_id' => $license_category,
+ ])
+ ->assertStatus(302);
+
+ $license->refresh();
+ $this->assertEquals($license->licenseseats()->count(), $license->seats);
+ $this->assertEquals($license->licenseseats()->count(), 9999);
+ }
+
+ public function testCanRemoveLicenseSeats()
+ {
+ $admin = User::factory()->superuser()->create();
+ $license_category = Category::factory()->forLicenses()->create()->id;
+ $response = $this->actingAs($admin)
+ ->from(route('licenses.create'))
+ ->post(route('licenses.store'), [
+ 'name' => 'Test Remove License Seats',
+ 'seats' => '9999',
+ 'category_id' => $license_category,
+ ]);
+ $response->assertStatus(302);
+ $license = License::where('name', 'Test Remove License Seats')->sole();
+ $this->assertNotNull($license);
+
+ $this->actingAs($admin)
+ ->put(route('licenses.update', $license->id), [
+ 'name' => 'Test Remove License Seats',
+ 'seats' => '5000',
+ 'category_id' => $license_category,
+ ])
+ ->assertStatus(302);
+
+ $license->refresh();
+ $this->assertEquals($license->licenseseats()->count(), $license->seats);
+ $this->assertEquals($license->licenseseats()->count(), 5000);
+ }
+
+
}