72 خطوط
2.7 KiB
PHP
72 خطوط
2.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Taxonomy;
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Identity\Domain\Enums\UserRole;
|
|
use App\Modules\Taxonomy\Domain\Enums\TaxonomyStatus;
|
|
use App\Modules\Taxonomy\Domain\TaxonomyNode;
|
|
use App\Modules\Taxonomy\Domain\TaxonomyType;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
class TaxonomyWorkspaceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_designer_can_build_a_competency_framework_and_read_coverage(): void
|
|
{
|
|
$designer = User::factory()->create(['role' => UserRole::CourseDesigner]);
|
|
$type = TaxonomyType::query()->create([
|
|
'organization_id' => $designer->organization_id,
|
|
'key' => 'skill',
|
|
'name' => 'مهارت',
|
|
'status' => TaxonomyStatus::Active,
|
|
]);
|
|
$node = TaxonomyNode::query()->create([
|
|
'organization_id' => $designer->organization_id,
|
|
'taxonomy_type_id' => $type->getKey(),
|
|
'name' => 'حل مسئله',
|
|
'status' => TaxonomyStatus::Active,
|
|
]);
|
|
Sanctum::actingAs($designer);
|
|
|
|
$frameworkId = $this->postJson('/api/v1/competency-frameworks', [
|
|
'name' => 'مدیران خط اول',
|
|
'description' => 'انتظارات نقش مدیریتی',
|
|
'audienceType' => 'organization',
|
|
'audienceValue' => null,
|
|
])->assertCreated()->assertJsonPath('data.name', 'مدیران خط اول')->json('data.id');
|
|
|
|
$this->putJson('/api/v1/competency-frameworks/'.$frameworkId.'/items', [
|
|
'items' => [[
|
|
'taxonomyNodeId' => $node->getKey(),
|
|
'masteryLevel' => 'advanced',
|
|
'required' => true,
|
|
]],
|
|
])->assertOk()
|
|
->assertJsonPath('data.items.0.name', 'حل مسئله')
|
|
->assertJsonPath('data.items.0.masteryLevel', 'advanced');
|
|
|
|
$this->getJson('/api/v1/taxonomy-workspace')->assertOk()
|
|
->assertJsonPath('data.overview.active', 1)
|
|
->assertJsonPath('data.overview.uncovered', 1)
|
|
->assertJsonPath('data.frameworks.0.id', $frameworkId)
|
|
->assertJsonPath('data.coverage.0.nodeId', $node->getKey())
|
|
->assertJsonPath('data.coverage.0.courseCount', 0);
|
|
}
|
|
|
|
public function test_manager_can_view_workspace_but_cannot_mutate_frameworks(): void
|
|
{
|
|
$manager = User::factory()->create(['role' => UserRole::Manager]);
|
|
Sanctum::actingAs($manager);
|
|
|
|
$this->getJson('/api/v1/taxonomy-workspace')->assertOk();
|
|
$this->postJson('/api/v1/competency-frameworks', [
|
|
'name' => 'Restricted',
|
|
'audienceType' => 'organization',
|
|
])->assertForbidden();
|
|
}
|
|
}
|