refactor(tests): convert AgentApiKey tests to Pest functional syntax
- Convert AgentApiKeyTest from PHPUnit class-based syntax to Pest functional syntax - Add tests/Pest.php configuration with helper functions (createWorkspace, createApiKey) - Organise tests using describe() blocks for better structure - Add additional test coverage for key rotation and security edge cases - Update TODO.md to reflect Pest syntax usage Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c432a45ca9
commit
e70e078bcb
3 changed files with 650 additions and 616 deletions
6
TODO.md
6
TODO.md
|
|
@ -53,9 +53,11 @@ Production-quality task list for the AI agent orchestration package.
|
||||||
### Test Coverage (Critical Gap)
|
### Test Coverage (Critical Gap)
|
||||||
|
|
||||||
- [x] **TEST-001: Add AgentApiKey model tests** (FIXED 2026-01-29)
|
- [x] **TEST-001: Add AgentApiKey model tests** (FIXED 2026-01-29)
|
||||||
- Created `tests/Feature/AgentApiKeyTest.php`
|
- Created `tests/Feature/AgentApiKeyTest.php` using Pest functional syntax
|
||||||
|
- Created `tests/Pest.php` for Pest configuration with helper functions
|
||||||
- Covers: key generation with Argon2id, validation, permissions, rate limiting, IP restrictions
|
- Covers: key generation with Argon2id, validation, permissions, rate limiting, IP restrictions
|
||||||
- 65+ test cases for comprehensive model coverage
|
- Additional coverage: key rotation, security edge cases
|
||||||
|
- 70+ test cases for comprehensive model coverage
|
||||||
|
|
||||||
- [x] **TEST-002: Add AgentApiKeyService tests** (FIXED 2026-01-29)
|
- [x] **TEST-002: Add AgentApiKeyService tests** (FIXED 2026-01-29)
|
||||||
- Created `tests/Feature/AgentApiKeyServiceTest.php`
|
- Created `tests/Feature/AgentApiKeyServiceTest.php`
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
74
tests/Pest.php
Normal file
74
tests/Pest.php
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Pest Configuration
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Configure Pest testing framework for the core-agentic package.
|
||||||
|
| This file binds test traits to test cases and provides helper functions.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Core\Mod\Agentic\Models\AgentApiKey;
|
||||||
|
use Core\Tenant\Models\Workspace;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Test Case
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The closure passed to the "uses()" method binds an abstract test case
|
||||||
|
| to all Feature and Unit tests. The TestCase class provides a bridge
|
||||||
|
| between Laravel's testing utilities and Pest's expressive syntax.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
uses(TestCase::class)->in('Feature', 'Unit', 'UseCase');
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Database Refresh
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Apply RefreshDatabase to Feature tests that need a clean database state.
|
||||||
|
| Unit tests typically don't require database access.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class)->in('Feature');
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Helper Functions
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Custom helper functions for agent-related tests.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a workspace for testing.
|
||||||
|
*/
|
||||||
|
function createWorkspace(array $attributes = []): Workspace
|
||||||
|
{
|
||||||
|
return Workspace::factory()->create($attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an API key for testing.
|
||||||
|
*/
|
||||||
|
function createApiKey(
|
||||||
|
Workspace|int|null $workspace = null,
|
||||||
|
string $name = 'Test Key',
|
||||||
|
array $permissions = [],
|
||||||
|
int $rateLimit = 100
|
||||||
|
): AgentApiKey {
|
||||||
|
$workspace ??= createWorkspace();
|
||||||
|
|
||||||
|
return AgentApiKey::generate($workspace, $name, $permissions, $rateLimit);
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue