wowowowowo
Some checks failed
CI / Lint (push) Failing after 22s
CI / Tests (push) Failing after 33s

This commit is contained in:
2026-05-28 15:15:41 +01:00
parent 8f603122e2
commit 5b977c1f41
129 changed files with 9943 additions and 722 deletions

View File

@@ -0,0 +1,116 @@
<?php
use App\Enums\OrganisationRole;
use App\Models\Organisation;
use App\Models\OrganisationInvitation;
use App\Models\User;
use Inertia\Testing\AssertableInertia;
it('lists organisation members', function () {
$owner = User::factory()->create();
$organisation = Organisation::factory()->create(['owner_id' => $owner->id]);
$member = User::factory()->create();
$organisation->members()->attach($member, ['role' => OrganisationRole::MEMBER]);
$this->actingAs($owner)
->get(route('organisation-members.index', $organisation))
->assertOk()
->assertInertia(fn (AssertableInertia $page) => $page
->component('organisation-members/Index', false)
->has('organisation.members', 1)
->has('organisation.invitations', 0));
});
it('adds updates and removes organisation members', function () {
$owner = User::factory()->create();
$organisation = Organisation::factory()->create(['owner_id' => $owner->id]);
$member = User::factory()->create(['email' => 'member@example.com']);
$this->actingAs($owner)
->post(route('organisation-members.store', $organisation), [
'email' => 'member@example.com',
'role' => OrganisationRole::MEMBER->value,
])
->assertRedirect(route('organisation-members.index', $organisation));
expect($organisation->members()->whereKey($member->id)->exists())->toBeTrue();
$this->actingAs($owner)
->put(route('organisation-members.update', [
'organisation' => $organisation->id,
'member' => $member->id,
]), [
'role' => OrganisationRole::ADMIN->value,
])
->assertRedirect(route('organisation-members.index', $organisation));
expect($organisation->members()->whereKey($member->id)->first()->membership->role)
->toBe(OrganisationRole::ADMIN);
$this->actingAs($owner)
->delete(route('organisation-members.destroy', [
'organisation' => $organisation->id,
'member' => $member->id,
]))
->assertRedirect(route('organisation-members.index', $organisation));
expect($organisation->members()->whereKey($member->id)->exists())->toBeFalse();
});
it('creates updates and cancels pending organisation invitations', function () {
$owner = User::factory()->create();
$organisation = Organisation::factory()->create(['owner_id' => $owner->id]);
$this->actingAs($owner)
->post(route('organisation-members.store', $organisation), [
'email' => 'pending@example.com',
'role' => OrganisationRole::MEMBER->value,
])
->assertRedirect(route('organisation-members.index', $organisation));
$invitation = $organisation->invitations()->where('email', 'pending@example.com')->firstOrFail();
expect($invitation->role)->toBe(OrganisationRole::MEMBER)
->and($invitation->token)->not->toBeEmpty()
->and($invitation->invited_by_user_id)->toBe($owner->id);
$this->actingAs($owner)
->get(route('organisation-members.index', $organisation))
->assertOk()
->assertInertia(fn (AssertableInertia $page) => $page
->component('organisation-members/Index', false)
->where('organisation.invitations.0.email', 'pending@example.com'));
$this->actingAs($owner)
->put(route('organisation-invitations.update', [
'organisation' => $organisation->id,
'invitation' => $invitation->id,
]), [
'role' => OrganisationRole::ADMIN->value,
])
->assertRedirect(route('organisation-members.index', $organisation));
expect($invitation->refresh()->role)->toBe(OrganisationRole::ADMIN);
$this->actingAs($owner)
->delete(route('organisation-invitations.destroy', [
'organisation' => $organisation->id,
'invitation' => $invitation->id,
]))
->assertRedirect(route('organisation-members.index', $organisation));
expect(OrganisationInvitation::query()->whereKey($invitation->id)->exists())->toBeFalse();
});
it('does not remove the organisation owner', function () {
$owner = User::factory()->create();
$organisation = Organisation::factory()->create(['owner_id' => $owner->id]);
$organisation->members()->attach($owner, ['role' => OrganisationRole::ADMIN]);
$this->actingAs($owner)
->delete(route('organisation-members.destroy', [
'organisation' => $organisation->id,
'member' => $owner->id,
]))
->assertUnprocessable();
});