159 lines
5.1 KiB
PHP
159 lines
5.1 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use Livewire\Livewire;
|
|
|
|
test('guests are redirected from the lifetime access page', function () {
|
|
$this->get(route('admin.lifetime-access'))
|
|
->assertRedirect(route('login'));
|
|
});
|
|
|
|
test('non-admins cannot access the lifetime access page', function () {
|
|
$this->actingAs(User::factory()->create());
|
|
|
|
$this->get(route('admin.lifetime-access'))->assertForbidden();
|
|
});
|
|
|
|
test('workspace admins are not site admins and cannot access the lifetime access page', function () {
|
|
$workspaceAdmin = User::factory()->create();
|
|
|
|
$this->actingAs($workspaceAdmin);
|
|
|
|
$this->get(route('admin.lifetime-access'))->assertForbidden();
|
|
});
|
|
|
|
test('a non-admin cannot toggle lifetime access through a direct action call', function () {
|
|
$admin = User::factory()->asAdmin()->create();
|
|
$this->actingAs($admin);
|
|
|
|
$member = User::factory()->create();
|
|
|
|
$component = Livewire::test('pages::admin.lifetime-access');
|
|
|
|
$this->actingAs($member);
|
|
|
|
$component->call('toggleLifetimeAccess', $member->id)->assertForbidden();
|
|
|
|
expect($member->fresh()->currentOrganization->lifetime_access)->toBeFalse();
|
|
});
|
|
|
|
test('non-admins do not see the lifetime access navigation item', function () {
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
$this->get(route('dashboard'))
|
|
->assertOk()
|
|
->assertDontSee('Lifetime access');
|
|
});
|
|
|
|
test('admins see the lifetime access navigation item', function () {
|
|
$user = User::factory()->asAdmin()->create();
|
|
$this->actingAs($user);
|
|
|
|
$this->get(route('dashboard'))
|
|
->assertOk()
|
|
->assertSee('Lifetime access');
|
|
});
|
|
|
|
test('site admins see the site admin navigation group', function () {
|
|
$user = User::factory()->asAdmin()->create();
|
|
$this->actingAs($user);
|
|
|
|
$this->get(route('dashboard'))
|
|
->assertOk()
|
|
->assertSee('Site admin');
|
|
});
|
|
|
|
test('workspace admins do not see the site admin navigation group', function () {
|
|
$workspaceAdmin = User::factory()->create();
|
|
|
|
$this->actingAs($workspaceAdmin);
|
|
|
|
$this->get(route('dashboard'))
|
|
->assertOk()
|
|
->assertDontSee('Site admin');
|
|
});
|
|
|
|
test('admins can view the lifetime access page', function () {
|
|
$user = User::factory()->asAdmin()->create();
|
|
$this->actingAs($user);
|
|
|
|
$this->get(route('admin.lifetime-access'))->assertOk();
|
|
});
|
|
|
|
test('the lifetime access page lists users with their status', function () {
|
|
$admin = User::factory()->asAdmin()->create();
|
|
$this->actingAs($admin);
|
|
|
|
$lifetimeUser = User::factory()->create(['name' => 'Lifetime User']);
|
|
$lifetimeUser->currentOrganization->update(['lifetime_access' => true]);
|
|
|
|
$regularUser = User::factory()->create(['name' => 'Regular User']);
|
|
|
|
Livewire::test('pages::admin.lifetime-access')
|
|
->assertSee('Lifetime User')
|
|
->assertSee('Regular User')
|
|
->assertSee('Lifetime')
|
|
->assertSee('None');
|
|
});
|
|
|
|
test('admins can enable lifetime access for a user', function () {
|
|
$admin = User::factory()->asAdmin()->create();
|
|
$this->actingAs($admin);
|
|
|
|
$member = User::factory()->create(['name' => 'Member One']);
|
|
|
|
expect($member->fresh()->currentOrganization->lifetime_access)->toBeFalse();
|
|
|
|
Livewire::test('pages::admin.lifetime-access')
|
|
->call('toggleLifetimeAccess', $member->id)
|
|
->assertSet('showLimitForm', false);
|
|
|
|
expect($member->fresh()->currentOrganization->lifetime_access)->toBeTrue();
|
|
});
|
|
|
|
test('admins can disable lifetime access for a user', function () {
|
|
$admin = User::factory()->asAdmin()->create();
|
|
$this->actingAs($admin);
|
|
|
|
$member = User::factory()->create(['name' => 'Member Two']);
|
|
$member->currentOrganization->update(['lifetime_access' => true]);
|
|
|
|
expect($member->fresh()->currentOrganization->lifetime_access)->toBeTrue();
|
|
|
|
Livewire::test('pages::admin.lifetime-access')
|
|
->call('toggleLifetimeAccess', $member->id);
|
|
|
|
expect($member->fresh()->currentOrganization->lifetime_access)->toBeFalse();
|
|
});
|
|
|
|
test('admins can search users by name or email', function () {
|
|
$admin = User::factory()->asAdmin()->create();
|
|
$this->actingAs($admin);
|
|
|
|
$match = User::factory()->create(['name' => 'Ada Lovelace', 'email' => 'ada@example.com']);
|
|
$emailMatch = User::factory()->create(['name' => 'Grace Hopper', 'email' => 'grace@searchable.test']);
|
|
$other = User::factory()->create(['name' => 'Alan Turing', 'email' => 'alan@example.com']);
|
|
|
|
Livewire::test('pages::admin.lifetime-access')
|
|
->set('search', 'lovelace')
|
|
->assertSee('Ada Lovelace')
|
|
->assertDontSee('Alan Turing')
|
|
->set('search', 'searchable.test')
|
|
->assertSee('Grace Hopper')
|
|
->assertDontSee($match->name)
|
|
->assertDontSee($other->name);
|
|
});
|
|
|
|
test('the lifetime access list is paginated', function () {
|
|
$admin = User::factory()->asAdmin()->create();
|
|
$this->actingAs($admin);
|
|
|
|
User::factory()->count(12)->create();
|
|
|
|
$component = Livewire::test('pages::admin.lifetime-access');
|
|
|
|
expect($component->instance()->users->perPage())->toBe(10)
|
|
->and($component->instance()->users->total())->toBe(13);
|
|
});
|