Skip to content

Update PersonApiTest to use sanctum guard #128

@kevalyq

Description

@kevalyq

🎯 Objective

Update tests/Feature/PersonApiTest.php to create permissions with guard_name='sanctum' instead of defaulting to 'web' guard.

📋 Changes Required

Location

File: tests/Feature/PersonApiTest.php
Lines: ~30-40 (beforeEach hook)

Current Code

beforeEach(function (): void {
    $this->tenant = Tenant::factory()->create();
    $this->user = User::factory()->create(['tenant_id' => $this->tenant->id]);
    $this->token = $this->user->createToken('test')->plainTextToken;

    // Create test permissions (implicit 'web' guard)
    Permission::create(['name' => 'employees.create']);
    Permission::create(['name' => 'employees.read']);
});

Target Code

beforeEach(function (): void {
    $this->tenant = Tenant::factory()->create();
    $this->user = User::factory()->create(['tenant_id' => $this->tenant->id]);
    $this->token = $this->user->createToken('test')->plainTextToken;

    // Create test permissions (explicit 'sanctum' guard)
    Permission::create(['name' => 'employees.create', 'guard_name' => 'sanctum']);
    Permission::create(['name' => 'employees.read', 'guard_name' => 'sanctum']);
});

✅ Acceptance Criteria

  • All Permission::create() calls include 'guard_name' => 'sanctum'
  • Tests pass locally after change
  • PHPStan Level Max: 0 errors
  • Laravel Pint: Clean
  • No other test files affected

📊 Expected Impact

Before: All 13 tests failing with 403 Forbidden errors
After: All 13 tests pass

🔗 Related

⏱️ Effort Estimate

Time: 15-20 minutes
Complexity: Low (mechanical change, well-defined scope)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions