A free open source IT asset/license management system
Add failing tests
Marcus Moore7dcf405f1242
diff --git a/tests/Unit/Mail/CheckinAccessoryMailTest.php b/tests/Unit/Mail/CheckinAccessoryMailTest.phpnew file mode 100644index 0000000000..d90f2c137f--- /dev/null+++ b/tests/Unit/Mail/CheckinAccessoryMailTest.php@@ -0,0 +1,43 @@+<?php++namespace Tests\Unit\Mail;++use App\Mail\CheckinAccessoryMail;+use App\Models\Accessory;+use App\Models\User;+use PHPUnit\Framework\Attributes\Test;+use Tests\TestCase;++class CheckinAccessoryMailTest extends TestCase+{+ #[Test]+ public function shows_accessory_storage_location_instead_of_users_location()+ {+ $luke = User::factory()+ ->forLocation(['name' => 'Tatooine'])+ ->create();++ $lightsaber = Accessory::factory()+ ->forLocation(['name' => 'Jedi Temple'])+ ->create();++ $mail = new CheckinAccessoryMail($lightsaber, $luke, User::factory()->create(), null);++ $mail->assertSeeInOrderInText([trans('general.location'), 'Jedi Temple']);+ $mail->assertDontSeeInText('Tatooine');+ }++ #[Test]+ public function does_not_show_location_when_accessory_has_no_location()+ {+ $luke = User::factory()+ ->forLocation(['name' => 'Tatooine'])+ ->create();++ $lightsaber = Accessory::factory()->create(['location_id' => null]);++ $mail = new CheckinAccessoryMail($lightsaber, $luke, User::factory()->create(), null);++ $mail->assertDontSeeInText(trans('general.location'));+ }+}diff --git a/tests/Unit/Mail/CheckinAssetMailTest.php b/tests/Unit/Mail/CheckinAssetMailTest.phpnew file mode 100644index 0000000000..f820a330cf--- /dev/null+++ b/tests/Unit/Mail/CheckinAssetMailTest.php@@ -0,0 +1,42 @@+<?php++namespace Tests\Unit\Mail;++use App\Mail\CheckinAssetMail;+use App\Models\Asset;+use App\Models\User;+use PHPUnit\Framework\Attributes\Test;+use Tests\TestCase;++class CheckinAssetMailTest extends TestCase+{+ #[Test]+ public function shows_location_asset_landed_at_instead_of_users_location()+ {+ $luke = User::factory()+ ->forLocation(['name' => 'Tatooine'])+ ->create();++ $r2d2 = Asset::factory()+ ->forLocation(['name' => 'Dagobah'])+ ->create();++ $mail = new CheckinAssetMail($r2d2, $luke, User::factory()->create(), null);++ $mail->assertSeeInOrderInText([trans('general.location'), 'Dagobah']);+ $mail->assertDontSeeInText('Tatooine');+ }++ #[Test]+ public function does_not_show_location_when_asset_has_no_location()+ {+ $luke = User::factory()+ ->forLocation(['name' => 'Tatooine'])+ ->create();+ $r2d2 = Asset::factory()->create(['location_id' => null]);++ $mail = new CheckinAssetMail($r2d2, $luke, User::factory()->create(), null);++ $mail->assertDontSeeInText(trans('general.location'));+ }+}diff --git a/tests/Unit/Mail/CheckinComponentMailTest.php b/tests/Unit/Mail/CheckinComponentMailTest.phpnew file mode 100644index 0000000000..7d45fdc602--- /dev/null+++ b/tests/Unit/Mail/CheckinComponentMailTest.php@@ -0,0 +1,50 @@+<?php++namespace Tests\Unit\Mail;++use App\Mail\CheckinComponentMail;+use App\Models\Asset;+use App\Models\Component;+use App\Models\User;+use PHPUnit\Framework\Attributes\Test;+use Tests\TestCase;++class CheckinComponentMailTest extends TestCase+{+ #[Test]+ public function shows_component_storage_location_instead_of_assets_location()+ {+ $han = User::factory()->create();++ $millenniumFalcon = Asset::factory()+ ->forLocation(['name' => 'Cloud City'])+ ->assignedToUser($han)+ ->create();++ $hyperdriveMotivator = Component::factory()+ ->forLocation(['name' => 'Mos Eisley'])+ ->create();++ $mail = new CheckinComponentMail($hyperdriveMotivator, $millenniumFalcon, User::factory()->create(), null);++ $mail->assertSeeInOrderInText([trans('general.location'), 'Mos Eisley']);+ $mail->assertDontSeeInText('Cloud City');+ }++ #[Test]+ public function does_not_show_location_when_component_has_no_location()+ {+ $han = User::factory()->create();++ $millenniumFalcon = Asset::factory()+ ->forLocation(['name' => 'Cloud City'])+ ->assignedToUser($han)+ ->create();++ $hyperdriveMotivator = Component::factory()->create(['location_id' => null]);++ $mail = new CheckinComponentMail($hyperdriveMotivator, $millenniumFalcon, User::factory()->create(), null);++ $mail->assertDontSeeInText(trans('general.location'));+ }+}diff --git a/tests/Unit/Mail/CheckoutAccessoryMailTest.php b/tests/Unit/Mail/CheckoutAccessoryMailTest.phpnew file mode 100644index 0000000000..4775ebdb5d--- /dev/null+++ b/tests/Unit/Mail/CheckoutAccessoryMailTest.php@@ -0,0 +1,80 @@+<?php++namespace Tests\Unit\Mail;++use App\Mail\CheckoutAccessoryMail;+use App\Models\Accessory;+use App\Models\Asset;+use App\Models\Location;+use App\Models\User;+use PHPUnit\Framework\Attributes\DataProvider;+use PHPUnit\Framework\Attributes\Test;+use Tests\TestCase;++class CheckoutAccessoryMailTest extends TestCase+{+ public static function checkoutTargetsWithLocation()+ {+ yield 'User' => [+ function () {+ return [+ 'target' => User::factory()+ ->forLocation(['name' => 'Tatooine'])+ ->create(),+ 'expected_location_name' => 'Tatooine',+ ];+ },+ ];++ yield 'Asset' => [+ function () {+ return [+ 'target' => Asset::factory()+ ->forLocation(['name' => 'Hoth'])+ ->create(),+ 'expected_location_name' => 'Hoth',+ ];+ },+ ];++ yield 'Location' => [+ function () {+ $leia = User::factory()->create();++ return [+ 'target' => Location::factory()->create(['name' => 'Echo Base', 'manager_id' => $leia->id]),+ 'expected_location_name' => 'Echo Base',+ ];+ },+ ];+ }++ #[DataProvider('checkoutTargetsWithLocation')]+ #[Test]+ public function shows_location_of_checkout_target($data)+ {+ ['target' => $target, 'expected_location_name' => $expectedLocationName] = $data();++ $lightsaber = Accessory::factory()+ ->forLocation(['name' => 'Jedi Temple'])+ ->create();++ $mail = new CheckoutAccessoryMail($lightsaber, $target, User::factory()->create(), null, null);++ $mail->assertSeeInOrderInText([trans('general.location'), $expectedLocationName]);+ $mail->assertDontSeeInText('Jedi Temple');+ }++ #[Test]+ public function does_not_show_location_when_user_has_no_location()+ {+ $han = User::factory()->create(['location_id' => null]);+ $lightsaber = Accessory::factory()+ ->forLocation(['name' => 'Jedi Temple'])+ ->create();++ $mail = new CheckoutAccessoryMail($lightsaber, $han, User::factory()->create(), null, null);++ $mail->assertDontSeeInText(trans('general.location'));+ }+}diff --git a/tests/Unit/Mail/CheckoutAssetMailTest.php b/tests/Unit/Mail/CheckoutAssetMailTest.phpindex 41708d5931..9e0db43287 100644--- a/tests/Unit/Mail/CheckoutAssetMailTest.php+++ b/tests/Unit/Mail/CheckoutAssetMailTest.php@@ -5,8 +5,10 @@ namespace Tests\Unit\Mail;use App\Mail\CheckoutAssetMail;use App\Models\Asset;use App\Models\CheckoutAcceptance;+use App\Models\Location;use App\Models\User;use PHPUnit\Framework\Attributes\DataProvider;+use PHPUnit\Framework\Attributes\Test;use Tests\TestCase;class CheckoutAssetMailTest extends TestCase@@ -55,7 +57,8 @@ class CheckoutAssetMailTest extends TestCase}#[DataProvider('data')]- public function test_subject_line_and_opening($data)+ #[Test]+ public function subject_line_and_opening($data){['asset' => $asset,@@ -75,4 +78,62 @@ class CheckoutAssetMailTest extends TestCase))->assertHasSubject($expectedSubject)->assertSeeInText($expectedOpening);}++ public static function checkoutTargetsWithLocation()+ {+ yield 'User' => [+ function () {+ return [+ 'target' => User::factory()+ ->forLocation(['name' => 'Tatooine'])+ ->create(),+ 'expected_location_name' => 'Tatooine',+ ];+ },+ ];++ yield 'Asset' => [+ function () {+ return [+ 'target' => Asset::factory()+ ->forLocation(['name' => 'Hoth'])+ ->create(),+ 'expected_location_name' => 'Hoth',+ ];+ },+ ];++ yield 'Location' => [+ function () {+ return [+ 'target' => Location::factory()->create(['name' => 'Echo Base']),+ 'expected_location_name' => 'Echo Base',+ ];+ },+ ];+ }++ #[DataProvider('checkoutTargetsWithLocation')]+ #[Test]+ public function shows_location_of_checkout_target($data)+ {+ ['target' => $target, 'expected_location_name' => $expectedLocationName] = $data();++ $r2d2 = Asset::factory()->create();++ $mail = new CheckoutAssetMail($r2d2, $target, User::factory()->create(), null, null);++ $mail->assertSeeInOrderInText([trans('general.location'), $expectedLocationName]);+ }++ #[Test]+ public function does_not_show_location_when_user_has_no_location()+ {+ $han = User::factory()->create(['location_id' => null]);+ $r2d2 = Asset::factory()->create();++ $mail = new CheckoutAssetMail($r2d2, $han, User::factory()->create(), null, null);++ $mail->assertDontSeeInText(trans('general.location'));+ }}diff --git a/tests/Unit/Mail/CheckoutComponentMailTest.php b/tests/Unit/Mail/CheckoutComponentMailTest.phpnew file mode 100644index 0000000000..db6ae8b162--- /dev/null+++ b/tests/Unit/Mail/CheckoutComponentMailTest.php@@ -0,0 +1,51 @@+<?php++namespace Tests\Unit\Mail;++use App\Mail\CheckoutComponentMail;+use App\Models\Asset;+use App\Models\Component;+use App\Models\User;+use PHPUnit\Framework\Attributes\Test;+use Tests\TestCase;++class CheckoutComponentMailTest extends TestCase+{+ #[Test]+ public function shows_location_of_asset_component_was_checked_out_to()+ {+ $han = User::factory()->create();++ $millenniumFalcon = Asset::factory()+ ->forLocation(['name' => 'Cloud City'])+ ->assignedToUser($han)+ ->create();++ $hyperdriveMotivator = Component::factory()+ ->forLocation(['name' => 'Mos Eisley'])+ ->create();++ $mail = new CheckoutComponentMail($hyperdriveMotivator, $millenniumFalcon, User::factory()->create(), null, null);++ $mail->assertSeeInOrderInText([trans('general.location'), 'Cloud City']);+ $mail->assertDontSeeInText('Mos Eisley');+ }++ #[Test]+ public function does_not_show_location_when_asset_has_no_location()+ {+ $han = User::factory()->create();++ $millenniumFalcon = Asset::factory()+ ->assignedToUser($han)+ ->create(['location_id' => null]);++ $hyperdriveMotivator = Component::factory()+ ->forLocation(['name' => 'Mos Eisley'])+ ->create();++ $mail = new CheckoutComponentMail($hyperdriveMotivator, $millenniumFalcon, User::factory()->create(), null, null);++ $mail->assertDontSeeInText(trans('general.location'));+ }+}diff --git a/tests/Unit/Mail/CheckoutConsumableMailTest.php b/tests/Unit/Mail/CheckoutConsumableMailTest.phpnew file mode 100644index 0000000000..e5261d96d8--- /dev/null+++ b/tests/Unit/Mail/CheckoutConsumableMailTest.php@@ -0,0 +1,37 @@+<?php++namespace Tests\Unit\Mail;++use App\Mail\CheckoutConsumableMail;+use App\Models\Consumable;+use App\Models\User;+use PHPUnit\Framework\Attributes\Test;+use Tests\TestCase;++class CheckoutConsumableMailTest extends TestCase+{+ #[Test]+ public function shows_location_of_user_consumable_was_checked_out_to()+ {+ $luke = User::factory()+ ->forLocation(['name' => 'Tatooine'])+ ->create();++ $rationPack = Consumable::factory()->create();++ $mail = new CheckoutConsumableMail($rationPack, $luke, User::factory()->create(), null, null);++ $mail->assertSeeInOrderInText([trans('general.location'), 'Tatooine']);+ }++ #[Test]+ public function does_not_show_location_when_user_has_no_location()+ {+ $han = User::factory()->create(['location_id' => null]);+ $rationPack = Consumable::factory()->create();++ $mail = new CheckoutConsumableMail($rationPack, $han, User::factory()->create(), null, null);++ $mail->assertDontSeeInText(trans('general.location'));+ }+}