mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-24 04:03:34 -08:00
Ensure accessory check in emails are not sent when the setting is disabled
This commit is contained in:
parent
095a7d9b34
commit
728aaaab20
|
@ -67,30 +67,8 @@ class CheckinAccessoryNotification extends Notification
|
|||
* 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';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -142,14 +142,16 @@ class AccessoryFactory extends Factory
|
|||
});
|
||||
}
|
||||
|
||||
public function checkedOut()
|
||||
public function checkedOut(User $user = null)
|
||||
{
|
||||
return $this->afterCreating(function (Accessory $accessory) {
|
||||
return $this->afterCreating(function (Accessory $accessory) use ($user) {
|
||||
$accessory->decrement('qty');
|
||||
|
||||
$accessory->users()->attach($accessory->id, [
|
||||
'accessory_id' => $accessory->id,
|
||||
'created_at' => Carbon::now(),
|
||||
'user_id' => 1,
|
||||
'assigned_to' => User::factory()->create()->id,
|
||||
'assigned_to' => $user->id ?? User::factory()->create()->id,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,8 +2,13 @@
|
|||
|
||||
namespace Tests\Feature\Checkins;
|
||||
|
||||
use App\Events\CheckoutableCheckedIn;
|
||||
use App\Models\Accessory;
|
||||
use App\Models\User;
|
||||
use App\Notifications\CheckinAccessoryNotification;
|
||||
use App\Notifications\CheckinAssetNotification;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
@ -20,16 +25,66 @@ class AccessoryCheckinTest extends TestCase
|
|||
|
||||
public function testAccessoryCanBeCheckedIn()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
Event::fake([CheckoutableCheckedIn::class]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
$accessory = Accessory::factory()->checkedOut($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()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
$accessory = Accessory::factory()->checkedOut($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()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
$accessory = Accessory::factory()->checkedOut($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