104 lines
3.6 KiB
PHP
104 lines
3.6 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
use App\FolderRole;
|
||
|
|
use App\Models\Folder;
|
||
|
|
use App\Models\Invitation;
|
||
|
|
use App\Models\Organization;
|
||
|
|
use App\Models\User;
|
||
|
|
use App\OrganizationRole;
|
||
|
|
use Livewire\Livewire;
|
||
|
|
|
||
|
|
test('guests are redirected to login before they can accept', function () {
|
||
|
|
$invitation = Invitation::factory()->create();
|
||
|
|
|
||
|
|
$this->get(route('invitations.accept', $invitation->token))
|
||
|
|
->assertRedirect(route('login'));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('an authenticated invitee can load the accept page through its token', function () {
|
||
|
|
$invitation = Invitation::factory()->create();
|
||
|
|
|
||
|
|
$this->actingAs(User::factory()->create())
|
||
|
|
->get(route('invitations.accept', $invitation->token))
|
||
|
|
->assertOk()
|
||
|
|
->assertSee('Accept invitation');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('an authenticated user can accept a folder invitation', function () {
|
||
|
|
$owner = User::factory()->create();
|
||
|
|
$folder = Folder::factory()->for($owner)->create(['name' => 'Dir']);
|
||
|
|
$invitee = User::factory()->create();
|
||
|
|
|
||
|
|
$invitation = Invitation::factory()->forFolder($folder, FolderRole::Editor)->create();
|
||
|
|
|
||
|
|
$this->actingAs($invitee);
|
||
|
|
|
||
|
|
Livewire::test('pages::invitations.accept', ['invitation' => $invitation])
|
||
|
|
->call('accept')
|
||
|
|
->assertRedirect(route('dashboard'));
|
||
|
|
|
||
|
|
expect($folder->sharedRoleFor($invitee))->toBe(FolderRole::Editor);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('an authenticated user can accept a workspace invitation', function () {
|
||
|
|
$owner = User::factory()->create();
|
||
|
|
$organization = Organization::factory()->family()->withMember($owner)->create();
|
||
|
|
$invitee = User::factory()->create();
|
||
|
|
|
||
|
|
$invitation = Invitation::factory()->forOrganization($organization)->create();
|
||
|
|
|
||
|
|
$this->actingAs($invitee);
|
||
|
|
|
||
|
|
Livewire::test('pages::invitations.accept', ['invitation' => $invitation])
|
||
|
|
->call('accept')
|
||
|
|
->assertRedirect(route('dashboard'));
|
||
|
|
|
||
|
|
expect($organization->users()->where('users.id', $invitee->id)->exists())->toBeTrue();
|
||
|
|
expect($invitee->fresh()->current_organization_id)->toBe($organization->id);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('a full workspace refuses a workspace invitation', function () {
|
||
|
|
$owner = User::factory()->create();
|
||
|
|
$organization = Organization::factory()->family()->withMember($owner)->create();
|
||
|
|
|
||
|
|
for ($i = 0; $i < 5; $i++) {
|
||
|
|
$organization->users()->attach(User::factory()->create(), ['role' => OrganizationRole::Member->value]);
|
||
|
|
}
|
||
|
|
|
||
|
|
$invitee = User::factory()->create();
|
||
|
|
$invitation = Invitation::factory()->forOrganization($organization)->create();
|
||
|
|
|
||
|
|
$this->actingAs($invitee);
|
||
|
|
|
||
|
|
Livewire::test('pages::invitations.accept', ['invitation' => $invitation])
|
||
|
|
->call('accept')
|
||
|
|
->assertHasErrors('invitation');
|
||
|
|
|
||
|
|
expect($organization->users()->where('users.id', $invitee->id)->exists())->toBeFalse();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('an accepted invitation shows its accepted state and grants nothing new', function () {
|
||
|
|
$owner = User::factory()->create();
|
||
|
|
$folder = Folder::factory()->for($owner)->create(['name' => 'Dir']);
|
||
|
|
$invitee = User::factory()->create();
|
||
|
|
$invitation = Invitation::factory()->forFolder($folder)->accepted()->create();
|
||
|
|
|
||
|
|
$this->actingAs($invitee);
|
||
|
|
|
||
|
|
Livewire::test('pages::invitations.accept', ['invitation' => $invitation])
|
||
|
|
->assertSeeHtml('data-test="invitation-accepted"')
|
||
|
|
->call('accept');
|
||
|
|
|
||
|
|
expect($folder->sharedRoleFor($invitee))->toBeNull();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('an expired invitation shows its expired state', function () {
|
||
|
|
$invitation = Invitation::factory()->expired()->create();
|
||
|
|
$invitee = User::factory()->create();
|
||
|
|
|
||
|
|
$this->actingAs($invitee);
|
||
|
|
|
||
|
|
Livewire::test('pages::invitations.accept', ['invitation' => $invitation])
|
||
|
|
->assertSeeHtml('data-test="invitation-expired"');
|
||
|
|
});
|