Skip to content

A free open source IT asset/license management system

Add failing test

Marcus Moorebccd65e2fc46
diff --git a/app/Listeners/CheckoutablesCheckedOutInBulkListener.php b/app/Listeners/CheckoutablesCheckedOutInBulkListener.php
index ab1d343397..1899076b70 100644
--- a/app/Listeners/CheckoutablesCheckedOutInBulkListener.php
+++ b/app/Listeners/CheckoutablesCheckedOutInBulkListener.php
@@ -72,12 +72,9 @@ class CheckoutablesCheckedOutInBulkListener
return false;
}
- // @todo: how to handle assets having eula?
-
- // todo: add from CheckoutableListener:
- // if ($this->checkoutableCategoryShouldSendEmail($checkoutable)) {
- // return true;
- // }
+ if ($this->hasAssetWithEula($assets)) {
+ return true;
+ }
return $this->requiresAcceptance($assets);
}
@@ -101,6 +98,18 @@ class CheckoutablesCheckedOutInBulkListener
return (bool) $setting->admin_cc_email;
}
+ private function hasAssetWithEula(Collection $assets): bool
+ {
+ foreach ($assets as $asset) {
+ // todo: this doesn't work yet
+ if ($asset->eula) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
private function requiresAcceptance(Collection $assets): bool
{
return (bool) $assets->reduce(
diff --git a/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php b/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
index 73a6a87173..f8516f57f0 100644
--- a/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
+++ b/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
@@ -5,6 +5,7 @@ namespace Tests\Feature\Notifications\Email;
use App\Mail\BulkAssetCheckoutMail;
use App\Mail\CheckoutAssetMail;
use App\Models\Asset;
+use App\Models\Category;
use App\Models\Location;
use App\Models\User;
use Illuminate\Support\Facades\Mail;
@@ -108,12 +109,49 @@ class BulkCheckoutEmailTest extends TestCase
public function test_email_is_sent_when_assets_do_not_require_acceptance_but_have_a_eula()
{
- $this->markTestIncomplete();
+ // $this->markTestIncomplete();
+
+ $this->assets = Asset::factory()->doesNotRequireAcceptance()->count(2)->create();
+
+ $category = Category::factory()->doesNotRequireAcceptance()->create([
+ 'use_default_eula' => false,
+ 'eula_text' => 'Some EULA text here',
+ ]);
+
+ $this->assets->first()->model->category()->associate($category)->save();
+
+ $this->sendRequest();
+
+ Mail::assertNotSent(CheckoutAssetMail::class);
+
+ Mail::assertSent(BulkAssetCheckoutMail::class, 1);
+
+ Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) {
+ return $mail->hasTo($this->target->email)
+ && $mail->assertSeeInText('Assets have been checked out to you')
+ // todo: test this properly
+ && $mail->assertDontSeeInText('Click here to review the terms of use and accept');
+ });
+
}
public function test_email_is_sent_when_assets_do_not_require_acceptance_but_category_is_set_to_send_email()
{
$this->markTestIncomplete();
+
+ $this->assets = Asset::factory()->doesNotRequireAcceptance()->count(2)->create();
+
+ $this->sendRequest();
+
+ Mail::assertNotSent(CheckoutAssetMail::class);
+
+ Mail::assertSent(BulkAssetCheckoutMail::class, 1);
+
+ Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) {
+ return $mail->hasTo($this->target->email)
+ && $mail->assertSeeInText('Assets have been checked out to you');
+ });
+
}
public function test_email_is_sent_to_cc_address()