Merge pull request #15057 from spencerrlongg/bug/sc-23212-2

Fixes Potential Exception
This commit is contained in:
snipe 2024-07-10 08:27:59 +01:00 committed by GitHub
commit fb10c1439a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View file

@ -70,7 +70,7 @@ class CheckoutAcceptance extends Model
*/
public function isCheckedOutTo(User $user)
{
return $this->assignedTo->is($user);
return $this->assignedTo?->is($user);
}
/**

View file

@ -3,7 +3,9 @@
namespace Tests\Feature\CheckoutAcceptances\Ui;
use App\Models\Accessory;
use App\Models\Asset;
use App\Models\CheckoutAcceptance;
use App\Models\User;
use App\Notifications\AcceptanceAssetAcceptedNotification;
use App\Notifications\AcceptanceAssetDeclinedNotification;
use Notification;
@ -76,4 +78,22 @@ class AccessoryAcceptanceTest extends TestCase
}
);
}
public function testUserIsNotAbleToAcceptAnAssetAssignedToADifferentUser()
{
Notification::fake();
$otherUser = User::factory()->create();
$acceptance = CheckoutAcceptance::factory()
->pending()
->for(Asset::factory()->laptopMbp(), 'checkoutable')
->create();
$this->actingAs($otherUser)
->post(route('account.store-acceptance', $acceptance), ['asset_acceptance' => 'accepted'])
->assertSessionHas(['error' => trans('admin/users/message.error.incorrect_user_accepted')]);
$this->assertNull($acceptance->fresh()->accepted_at);
}
}