Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADVAPP-1163]: Fix tests and logic for Interaction confidentiality #1279

Merged
merged 14 commits into from
Feb 11, 2025
Merged
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,55 +35,92 @@
*/

use AdvisingApp\Authorization\Enums\LicenseType;
use AdvisingApp\Interaction\Filament\Resources\InteractionResource\Pages\ListInteractions;
use AdvisingApp\Interaction\Models\Interaction;
use AdvisingApp\Interaction\Models\Scopes\InteractionConfidentialScope;
use AdvisingApp\Team\Models\Team;
use App\Models\User;

use function Pest\Laravel\actingAs;
use function Pest\Livewire\livewire;
use function Tests\asSuperAdmin;

test('ListInteration with display data using the is_confidential field', function () {
test('Interaction model has applied global scope', function () {
Interaction::factory()->create();
Orrison marked this conversation as resolved.
Show resolved Hide resolved

expect(Interaction::hasGlobalScope(InteractionConfidentialScope::class))->toBeTrue();
});

test('Interactions model with fetch data count for created user', function () {
$user = User::factory()->licensed(LicenseType::cases())->create();
$user->givePermissionTo('interaction.view-any');

$userWithoutAttach = User::factory()->licensed(LicenseType::cases())->create();
$userWithoutAttach->givePermissionTo('interaction.view-any');
actingAs($user);
Interaction::factory()->count(10)->create([
'is_confidential' => true,
'user_id' => $user,
]);

Interaction::factory()->count(10)->create([
'is_confidential' => true,
]);

Interaction::factory()->count(10)->create([
'is_confidential' => false,
]);

expect(Interaction::query()->count())->toBe(20);
Orrison marked this conversation as resolved.
Show resolved Hide resolved
});

test('Interactions model with fetch data count for team user', function () {
$teamUser = User::factory()->licensed(LicenseType::cases())->create();
$teamUser->givePermissionTo('interaction.view-any');
Orrison marked this conversation as resolved.
Show resolved Hide resolved

$team = Team::factory()->hasAttached($teamUser, [], 'users')->create();

$confidentialInteraction = Interaction::factory()->hasAttached($user, [], 'confidentialAccessUsers')->hasAttached($team, [], 'confidentialAccessTeams')->count(10)->create([
actingAs($teamUser);
Interaction::factory()->hasAttached($team, [], 'confidentialAccessTeams')->count(10)->create([
'is_confidential' => true,
]);

$nonConfidentialInteraction = Interaction::factory()->count(10)->create([
Interaction::factory()->count(10)->create([
'is_confidential' => true,
]);

Interaction::factory()->count(10)->create([
'is_confidential' => false,
]);

$allInteractions = $confidentialInteraction->merge($nonConfidentialInteraction);
expect(Interaction::query()->count())->toBe(20);
Orrison marked this conversation as resolved.
Show resolved Hide resolved
});

test('Interactions model with fetch data count for assigned user', function () {
$user = User::factory()->licensed(LicenseType::cases())->create();
$user->givePermissionTo('interaction.view-any');

actingAs($user);
livewire(ListInteractions::class)
->set('tableRecordsPerPage', 20)
->assertCanSeeTableRecords($allInteractions);
Interaction::factory()->hasAttached($user, [], 'confidentialAccessUsers')->count(10)->create([
'is_confidential' => true,
]);

actingAs($userWithoutAttach);
livewire(ListInteractions::class)
->set('tableRecordsPerPage', 10)
->assertCanSeeTableRecords($nonConfidentialInteraction)
->assertCanNotSeeTableRecords($confidentialInteraction);
Interaction::factory()->count(10)->create([
'is_confidential' => true,
]);

actingAs($teamUser);
livewire(ListInteractions::class)
->set('tableRecordsPerPage', 20)
->assertCanSeeTableRecords($allInteractions);
Interaction::factory()->count(10)->create([
'is_confidential' => false,
]);

expect(Interaction::query()->count())->toBe(20);
Orrison marked this conversation as resolved.
Show resolved Hide resolved
});

test('Interactions model with fetch data count for superadmin user', function () {
asSuperAdmin();
livewire(ListInteractions::class)
->set('tableRecordsPerPage', 20)
->assertCanSeeTableRecords($allInteractions);
Interaction::factory()->count(10)->create([
'is_confidential' => true,
]);

Interaction::factory()->count(10)->create([
'is_confidential' => false,
]);

expect(Interaction::query()->count())->toBe(20);
Orrison marked this conversation as resolved.
Show resolved Hide resolved
});