Skip to content

Update RoleManagementApiTest to use sanctum guard #126

@kevalyq

Description

@kevalyq

🎯 Objective

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

📋 Changes Required

Location

File: tests/Feature/RoleManagementApiTest.php
Lines: ~50-56 (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' => 'roles.read']);
    Permission::create(['name' => 'roles.create']);
    Permission::create(['name' => 'roles.update']);
    Permission::create(['name' => 'roles.delete']);
    // ... more permissions
});

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' => 'roles.read', 'guard_name' => 'sanctum']);
    Permission::create(['name' => 'roles.create', 'guard_name' => 'sanctum']);
    Permission::create(['name' => 'roles.update', 'guard_name' => 'sanctum']);
    Permission::create(['name' => 'roles.delete', 'guard_name' => 'sanctum']);
    // ... more permissions
});

✅ 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: 3 tests failing with PermissionDoesNotExist errors
After: All 26 tests pass

🔗 Related

⏱️ Effort Estimate

Time: 20-30 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