Commit 17007ee0 authored by Mahmoud Aglan's avatar Mahmoud Aglan

cool

parent a5e223fe
<?php
namespace Tests\Feature\Deliverables;
use App\Models\User;
use App\Modules\Campaigns\Models\Campaign;
use App\Modules\Companies\Models\CompanyProfile;
use App\Modules\Creators\Models\CreatorProfile;
use App\Modules\Deliverables\Models\Deliverable;
use App\Modules\Projects\Models\Project;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class DeliverablePolicyTest extends TestCase
{
use RefreshDatabase;
private User $creatorUser;
private CreatorProfile $creator;
private User $companyUser;
private CompanyProfile $company;
private User $otherCreatorUser;
private User $otherCompanyUser;
private User $admin;
private Project $project;
private Deliverable $deliverable;
protected function setUp(): void
{
parent::setUp();
$this->creatorUser = User::factory()->creator()->create();
$this->creator = CreatorProfile::factory()->create(['user_id' => $this->creatorUser->id]);
$this->companyUser = User::factory()->company()->create();
$this->company = CompanyProfile::factory()->create(['user_id' => $this->companyUser->id]);
$this->otherCreatorUser = User::factory()->creator()->create();
CreatorProfile::factory()->create(['user_id' => $this->otherCreatorUser->id]);
$this->otherCompanyUser = User::factory()->company()->create();
CompanyProfile::factory()->create(['user_id' => $this->otherCompanyUser->id]);
$this->admin = User::factory()->admin()->create();
$campaign = Campaign::factory()->create(['company_id' => $this->company->id]);
$this->project = Project::factory()->create([
'campaign_id' => $campaign->id,
'company_id' => $this->company->id,
'creator_id' => $this->creator->id,
'status' => 'in_progress',
]);
$this->deliverable = Deliverable::factory()->create([
'project_id' => $this->project->id,
'status' => 'pending',
]);
}
// ─── view ───────────────────────────────────────────────────────────
public function test_project_creator_can_view_deliverable(): void
{
$this->assertTrue($this->creatorUser->can('view', $this->deliverable));
}
public function test_project_company_can_view_deliverable(): void
{
$this->assertTrue($this->companyUser->can('view', $this->deliverable));
}
public function test_admin_can_view_any_deliverable(): void
{
$this->assertTrue($this->admin->can('view', $this->deliverable));
}
public function test_other_creator_cannot_view(): void
{
$this->assertFalse($this->otherCreatorUser->can('view', $this->deliverable));
}
public function test_other_company_cannot_view(): void
{
$this->assertFalse($this->otherCompanyUser->can('view', $this->deliverable));
}
// ─── submit ─────────────────────────────────────────────────────────
public function test_creator_can_submit_to_submittable_deliverable(): void
{
$result = $this->creatorUser->can('submit', $this->deliverable);
$this->assertEquals($this->deliverable->canBeSubmittedTo(), $result);
}
public function test_company_cannot_submit(): void
{
$this->assertFalse($this->companyUser->can('submit', $this->deliverable));
}
public function test_other_creator_cannot_submit(): void
{
$this->assertFalse($this->otherCreatorUser->can('submit', $this->deliverable));
}
public function test_admin_cannot_submit(): void
{
$this->assertFalse($this->admin->can('submit', $this->deliverable));
}
// ─── approve ────────────────────────────────────────────────────────
public function test_company_can_approve_approvable_deliverable(): void
{
$this->deliverable->update(['status' => 'submitted']);
$result = $this->companyUser->can('approve', $this->deliverable);
$this->assertEquals($this->deliverable->canBeApproved(), $result);
}
public function test_admin_can_approve(): void
{
$this->deliverable->update(['status' => 'submitted']);
$result = $this->admin->can('approve', $this->deliverable);
$this->assertEquals($this->deliverable->canBeApproved(), $result);
}
public function test_creator_cannot_approve(): void
{
$this->deliverable->update(['status' => 'submitted']);
$this->assertFalse($this->creatorUser->can('approve', $this->deliverable));
}
public function test_other_company_cannot_approve(): void
{
$this->deliverable->update(['status' => 'submitted']);
$this->assertFalse($this->otherCompanyUser->can('approve', $this->deliverable));
}
// ─── requestRevision ────────────────────────────────────────────────
public function test_company_can_request_revision_when_allowed(): void
{
$this->deliverable->update(['status' => 'submitted']);
$result = $this->companyUser->can('requestRevision', $this->deliverable);
$this->assertEquals($this->deliverable->canRequestRevision(), $result);
}
public function test_admin_can_request_revision(): void
{
$this->deliverable->update(['status' => 'submitted']);
$result = $this->admin->can('requestRevision', $this->deliverable);
$this->assertEquals($this->deliverable->canRequestRevision(), $result);
}
public function test_creator_cannot_request_revision(): void
{
$this->deliverable->update(['status' => 'submitted']);
$this->assertFalse($this->creatorUser->can('requestRevision', $this->deliverable));
}
public function test_other_company_cannot_request_revision(): void
{
$this->deliverable->update(['status' => 'submitted']);
$this->assertFalse($this->otherCompanyUser->can('requestRevision', $this->deliverable));
}
// ─── manage ─────────────────────────────────────────────────────────
public function test_company_can_manage_own_deliverable(): void
{
$this->assertTrue($this->companyUser->can('manage', $this->deliverable));
}
public function test_admin_can_manage_any_deliverable(): void
{
$this->assertTrue($this->admin->can('manage', $this->deliverable));
}
public function test_creator_cannot_manage(): void
{
$this->assertFalse($this->creatorUser->can('manage', $this->deliverable));
}
public function test_other_company_cannot_manage(): void
{
$this->assertFalse($this->otherCompanyUser->can('manage', $this->deliverable));
}
}
<?php
namespace Tests\Feature\Invitations;
use App\Models\User;
use App\Modules\Campaigns\Models\Campaign;
use App\Modules\Companies\Models\CompanyProfile;
use App\Modules\Creators\Models\CreatorProfile;
use App\Modules\Invitations\Models\Invitation;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class InvitationPolicyTest extends TestCase
{
use RefreshDatabase;
private User $companyUser;
private CompanyProfile $company;
private User $creatorUser;
private CreatorProfile $creator;
private User $otherCompanyUser;
private CompanyProfile $otherCompany;
private User $otherCreatorUser;
private CreatorProfile $otherCreator;
private User $admin;
private Campaign $campaign;
private Invitation $invitation;
protected function setUp(): void
{
parent::setUp();
$this->companyUser = User::factory()->company()->create();
$this->company = CompanyProfile::factory()->create(['user_id' => $this->companyUser->id]);
$this->creatorUser = User::factory()->creator()->create();
$this->creator = CreatorProfile::factory()->create(['user_id' => $this->creatorUser->id]);
$this->otherCompanyUser = User::factory()->company()->create();
$this->otherCompany = CompanyProfile::factory()->create(['user_id' => $this->otherCompanyUser->id]);
$this->otherCreatorUser = User::factory()->creator()->create();
$this->otherCreator = CreatorProfile::factory()->create(['user_id' => $this->otherCreatorUser->id]);
$this->admin = User::factory()->admin()->create();
$this->campaign = Campaign::factory()->create(['company_id' => $this->company->id]);
$this->invitation = Invitation::factory()->create([
'campaign_id' => $this->campaign->id,
'company_id' => $this->company->id,
'creator_id' => $this->creator->id,
'status' => 'sent',
'expires_at' => now()->addDays(7),
'resend_count' => 0,
]);
}
// ─── viewAny ────────────────────────────────────────────────────────
public function test_any_authenticated_user_can_view_any(): void
{
$this->assertTrue($this->companyUser->can('viewAny', Invitation::class));
$this->assertTrue($this->creatorUser->can('viewAny', Invitation::class));
$this->assertTrue($this->admin->can('viewAny', Invitation::class));
}
// ─── view ───────────────────────────────────────────────────────────
public function test_sending_company_can_view(): void
{
$this->assertTrue($this->companyUser->can('view', $this->invitation));
}
public function test_invited_creator_can_view(): void
{
$this->assertTrue($this->creatorUser->can('view', $this->invitation));
}
public function test_admin_can_view_any_invitation(): void
{
$this->assertTrue($this->admin->can('view', $this->invitation));
}
public function test_other_company_cannot_view(): void
{
$this->assertFalse($this->otherCompanyUser->can('view', $this->invitation));
}
public function test_other_creator_cannot_view(): void
{
$this->assertFalse($this->otherCreatorUser->can('view', $this->invitation));
}
// ─── create ─────────────────────────────────────────────────────────
public function test_company_with_profile_can_create(): void
{
$this->assertTrue($this->companyUser->can('create', Invitation::class));
}
public function test_creator_cannot_create(): void
{
$this->assertFalse($this->creatorUser->can('create', Invitation::class));
}
public function test_admin_cannot_create(): void
{
$this->assertFalse($this->admin->can('create', Invitation::class));
}
// ─── cancel ─────────────────────────────────────────────────────────
public function test_sending_company_can_cancel_pending_invitation(): void
{
$this->assertTrue($this->companyUser->can('cancel', $this->invitation));
}
public function test_sending_company_cannot_cancel_accepted_invitation(): void
{
$this->invitation->update(['status' => 'accepted']);
$this->assertFalse($this->companyUser->can('cancel', $this->invitation));
}
public function test_other_company_cannot_cancel(): void
{
$this->assertFalse($this->otherCompanyUser->can('cancel', $this->invitation));
}
public function test_creator_cannot_cancel(): void
{
$this->assertFalse($this->creatorUser->can('cancel', $this->invitation));
}
// ─── resend ─────────────────────────────────────────────────────────
public function test_sending_company_can_resend_when_allowed(): void
{
$this->assertTrue($this->companyUser->can('resend', $this->invitation));
}
public function test_sending_company_cannot_resend_after_max_resends(): void
{
$this->invitation->update(['resend_count' => 2]);
$this->assertFalse($this->companyUser->can('resend', $this->invitation));
}
public function test_sending_company_cannot_resend_accepted(): void
{
$this->invitation->update(['status' => 'accepted']);
$this->assertFalse($this->companyUser->can('resend', $this->invitation));
}
public function test_other_company_cannot_resend(): void
{
$this->assertFalse($this->otherCompanyUser->can('resend', $this->invitation));
}
public function test_creator_cannot_resend(): void
{
$this->assertFalse($this->creatorUser->can('resend', $this->invitation));
}
// ─── accept ─────────────────────────────────────────────────────────
public function test_invited_creator_can_accept_pending(): void
{
$this->assertTrue($this->creatorUser->can('accept', $this->invitation));
}
public function test_invited_creator_cannot_accept_expired(): void
{
$this->invitation->update(['expires_at' => now()->subDay()]);
$this->assertFalse($this->creatorUser->can('accept', $this->invitation));
}
public function test_invited_creator_cannot_accept_already_accepted(): void
{
$this->invitation->update(['status' => 'accepted']);
$this->assertFalse($this->creatorUser->can('accept', $this->invitation));
}
public function test_other_creator_cannot_accept(): void
{
$this->assertFalse($this->otherCreatorUser->can('accept', $this->invitation));
}
public function test_company_cannot_accept(): void
{
$this->assertFalse($this->companyUser->can('accept', $this->invitation));
}
// ─── decline ────────────────────────────────────────────────────────
public function test_invited_creator_can_decline_pending(): void
{
$this->assertTrue($this->creatorUser->can('decline', $this->invitation));
}
public function test_invited_creator_cannot_decline_already_accepted(): void
{
$this->invitation->update(['status' => 'accepted']);
$this->assertFalse($this->creatorUser->can('decline', $this->invitation));
}
public function test_other_creator_cannot_decline(): void
{
$this->assertFalse($this->otherCreatorUser->can('decline', $this->invitation));
}
public function test_company_cannot_decline(): void
{
$this->assertFalse($this->companyUser->can('decline', $this->invitation));
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment