mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Merge pull request #14256 from marcusmoore/bug/sc-24790
Fixed accessory check in emails being sent when setting disabled
This commit is contained in:
commit
99e0b65de7
|
@ -63,34 +63,8 @@ class CheckinAccessoryNotification extends Notification
|
|||
if ($this->target instanceof User && $this->target->email != '') {
|
||||
\Log::debug('The target is a user');
|
||||
|
||||
/**
|
||||
* Send an email if the asset requires acceptance,
|
||||
* so the user can accept or decline the asset
|
||||
*/
|
||||
if (($this->item->requireAcceptance()) || ($this->item->getEula()) || ($this->item->checkin_email())) {
|
||||
$notifyBy[] = 'mail';
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an email if the asset requires acceptance,
|
||||
* so the user can accept or decline the asset
|
||||
*/
|
||||
if ($this->item->requireAcceptance()) {
|
||||
\Log::debug('This accessory requires acceptance');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an email if the item has a EULA, since the user should always receive it
|
||||
*/
|
||||
if ($this->item->getEula()) {
|
||||
\Log::debug('This accessory has a EULA');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an email if an email should be sent at checkin/checkout
|
||||
*/
|
||||
if ($this->item->checkin_email()) {
|
||||
\Log::debug('This accessory has a checkin_email()');
|
||||
$notifyBy[] = 'mail';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ use App\Models\Location;
|
|||
use App\Models\Manufacturer;
|
||||
use App\Models\Supplier;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class AccessoryFactory extends Factory
|
||||
|
@ -140,4 +141,16 @@ class AccessoryFactory extends Factory
|
|||
$accessory->category->update(['require_acceptance' => 1]);
|
||||
});
|
||||
}
|
||||
|
||||
public function checkedOutToUser(User $user = null)
|
||||
{
|
||||
return $this->afterCreating(function (Accessory $accessory) use ($user) {
|
||||
$accessory->users()->attach($accessory->id, [
|
||||
'accessory_id' => $accessory->id,
|
||||
'created_at' => Carbon::now(),
|
||||
'user_id' => 1,
|
||||
'assigned_to' => $user->id ?? User::factory()->create()->id,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
91
tests/Feature/Checkins/AccessoryCheckinTest.php
Normal file
91
tests/Feature/Checkins/AccessoryCheckinTest.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Checkins;
|
||||
|
||||
use App\Events\CheckoutableCheckedIn;
|
||||
use App\Models\Accessory;
|
||||
use App\Models\User;
|
||||
use App\Notifications\CheckinAccessoryNotification;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AccessoryCheckinTest extends TestCase
|
||||
{
|
||||
use InteractsWithSettings;
|
||||
|
||||
public function testCheckingInAccessoryRequiresCorrectPermission()
|
||||
{
|
||||
$accessory = Accessory::factory()->checkedOutToUser()->create();
|
||||
|
||||
$this->actingAs(User::factory()->create())
|
||||
->post(route('accessories.checkin.store', $accessory->users->first()->pivot->id))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testAccessoryCanBeCheckedIn()
|
||||
{
|
||||
Event::fake([CheckoutableCheckedIn::class]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
$accessory = Accessory::factory()->checkedOutToUser($user)->create();
|
||||
|
||||
$this->assertTrue($accessory->users->contains($user));
|
||||
|
||||
$this->actingAs(User::factory()->checkinAccessories()->create())
|
||||
->post(route('accessories.checkin.store', $accessory->users->first()->pivot->id));
|
||||
|
||||
$this->assertFalse($accessory->fresh()->users->contains($user));
|
||||
|
||||
Event::assertDispatched(CheckoutableCheckedIn::class, 1);
|
||||
}
|
||||
|
||||
public function testEmailSentToUserIfSettingEnabled()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
$accessory = Accessory::factory()->checkedOutToUser($user)->create();
|
||||
|
||||
$accessory->category->update(['checkin_email' => true]);
|
||||
|
||||
event(new CheckoutableCheckedIn(
|
||||
$accessory,
|
||||
$user,
|
||||
User::factory()->checkinAccessories()->create(),
|
||||
'',
|
||||
));
|
||||
|
||||
Notification::assertSentTo(
|
||||
[$user],
|
||||
function (CheckinAccessoryNotification $notification, $channels) {
|
||||
return in_array('mail', $channels);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
public function testEmailNotSentToUserIfSettingDisabled()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
$accessory = Accessory::factory()->checkedOutToUser($user)->create();
|
||||
|
||||
$accessory->category->update(['checkin_email' => false]);
|
||||
|
||||
event(new CheckoutableCheckedIn(
|
||||
$accessory,
|
||||
$user,
|
||||
User::factory()->checkinAccessories()->create(),
|
||||
'',
|
||||
));
|
||||
|
||||
Notification::assertNotSentTo(
|
||||
[$user],
|
||||
function (CheckinAccessoryNotification $notification, $channels) {
|
||||
return in_array('mail', $channels);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue