checkedOutToUser()->create(); $this->actingAs(User::factory()->create()) ->post(route('accessories.checkin.store', $accessory->checkouts->first()->id)) ->assertForbidden(); } public function testAccessoryCanBeCheckedIn() { Event::fake([CheckoutableCheckedIn::class]); $user = User::factory()->create(); $accessory = Accessory::factory()->checkedOutToUser($user)->create(); $this->assertTrue($accessory->checkouts()->where('assigned_type', User::class)->where('assigned_to', $user->id)->count() > 0); $this->actingAs(User::factory()->checkinAccessories()->create()) ->post(route('accessories.checkin.store', $accessory->checkouts->first()->id)); $this->assertFalse($accessory->fresh()->checkouts()->where('assigned_type', User::class)->where('assigned_to', $user->id)->count() > 0); 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); }, ); } }