create(); $share = Share::factory()->for($user)->create(['recipient_email' => 'client@example.com']); $this->actingAs($user) ->get(route('shares.index')) ->assertOk() ->assertSee('client@example.com'); }); test('shares from other users are hidden', function () { Share::factory()->create(['recipient_email' => 'client@example.com']); $this->actingAs(User::factory()->create()) ->get(route('shares.index')) ->assertOk() ->assertDontSee('client@example.com'); }); test('a share can be revoked', function () { $user = User::factory()->create(); $share = Share::factory()->for($user)->create(); $this->actingAs($user); Livewire::test('pages::shares.index') ->call('revoke', $share->id); expect($share->refresh()->revoked_at)->not->toBeNull(); }); test('a share can be deleted', function () { $user = User::factory()->create(); $share = Share::factory()->for($user)->create(); $this->actingAs($user); Livewire::test('pages::shares.index') ->call('delete', $share->id); expect(Share::withoutGlobalScopes()->count())->toBe(0); }); test('another user cannot revoke a share they do not own', function () { $share = Share::factory()->create(); $this->actingAs(User::factory()->create()); expect(fn () => Livewire::test('pages::shares.index')->call('revoke', $share->id)) ->toThrow(ModelNotFoundException::class); expect($share->refresh()->revoked_at)->toBeNull(); }); test('guests are redirected to login', function () { $this->get(route('shares.index'))->assertRedirect(route('login')); });