From baa6fff4592b376ef883da360a2e2297b1b6b37d Mon Sep 17 00:00:00 2001 From: root Date: Wed, 24 Jun 2026 00:56:12 -0400 Subject: [PATCH] fix tests isssues --- routes/api.php | 2 +- tests/Feature/Api/V1/AssignmentApiTest.php | 15 +++++----- .../V1/AttendanceCommentTemplateApiTest.php | 29 +++++++++++++------ 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/routes/api.php b/routes/api.php index 633a4c74..58652f1a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -539,7 +539,7 @@ Route::prefix('v1')->group(function () { Route::post('/save-notification-note', [AttendanceTrackingController::class, 'saveNotificationNote']); }); - Route::middleware(['auth:api', 'school_year.editable'])->prefix('attendance-comment-templates')->group(function () { + Route::middleware(['auth:sanctum', 'school_year.editable'])->prefix('attendance-comment-templates')->group(function () { Route::get('/', [AttendanceCommentTemplateController::class, 'index'])->name('api.v1.attendance-comment-templates.index'); Route::get('list-data', [AttendanceCommentTemplateController::class, 'listData']) ->name('api.v1.attendance-comment-templates.list-data'); diff --git a/tests/Feature/Api/V1/AssignmentApiTest.php b/tests/Feature/Api/V1/AssignmentApiTest.php index 64c3f6a1..63640d15 100644 --- a/tests/Feature/Api/V1/AssignmentApiTest.php +++ b/tests/Feature/Api/V1/AssignmentApiTest.php @@ -77,10 +77,9 @@ class AssignmentApiTest extends TestCase 'semester' => 'Fall', 'school_year' => '2025-2026', 'description' => 'Student assigned', - 'is_active' => 1, // remove if your table doesn’t have this column ]); - $response = $this->getJson('/api/assignments'); + $response = $this->getJson('/api/v1/assignments'); $response->assertOk() ->assertJsonStructure([ @@ -137,7 +136,7 @@ class AssignmentApiTest extends TestCase 'school_year' => '2025-2026', ]); - $response = $this->getJson('/api/assignments?school_year=2025-2026'); + $response = $this->getJson('/api/v1/assignments?school_year=2025-2026'); $response->assertOk(); @@ -165,7 +164,7 @@ class AssignmentApiTest extends TestCase 'description' => 'Moved after placement review', ]; - $response = $this->postJson('/api/assignments', $payload); + $response = $this->postJson('/api/v1/assignments', $payload); $response->assertCreated() ->assertJsonPath('message', 'Assignment saved successfully.'); @@ -183,7 +182,7 @@ class AssignmentApiTest extends TestCase { Sanctum::actingAs($this->user); - $response = $this->postJson('/api/assignments', []); + $response = $this->postJson('/api/v1/assignments', []); $response->assertStatus(422) ->assertJsonValidationErrors([ @@ -202,7 +201,7 @@ class AssignmentApiTest extends TestCase $sectionB = ClassSection::factory()->create(); // First create - $this->postJson('/api/assignments', [ + $this->postJson('/api/v1/assignments', [ 'student_id' => $student->id, 'class_section_id' => $sectionA->class_section_id, 'semester' => 'Fall', @@ -210,7 +209,7 @@ class AssignmentApiTest extends TestCase ])->assertCreated(); // Second call same unique key should update (per service updateOrCreate) - $this->postJson('/api/assignments', [ + $this->postJson('/api/v1/assignments', [ 'student_id' => $student->id, 'class_section_id' => $sectionA->class_section_id, 'semester' => 'Fall', @@ -238,7 +237,7 @@ class AssignmentApiTest extends TestCase #[Test] public function guest_cannot_access_assignment_api_when_auth_is_required(): void { - $response = $this->getJson('/api/assignments'); + $response = $this->getJson('/api/v1/assignments'); $response->assertStatus(401); } diff --git a/tests/Feature/Api/V1/AttendanceCommentTemplateApiTest.php b/tests/Feature/Api/V1/AttendanceCommentTemplateApiTest.php index 511a4de6..7ce49a56 100644 --- a/tests/Feature/Api/V1/AttendanceCommentTemplateApiTest.php +++ b/tests/Feature/Api/V1/AttendanceCommentTemplateApiTest.php @@ -2,15 +2,26 @@ namespace Tests\Feature\Api; +use App\Models\User; use App\Services\AttendanceCommentTemplateService; +use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; +use Laravel\Sanctum\Sanctum; use Mockery; use Tests\TestCase; class AttendanceCommentTemplateApiTest extends TestCase { + use RefreshDatabase; use WithFaker; + protected function setUp(): void + { + parent::setUp(); + $user = User::factory()->create(); + Sanctum::actingAs($user); + } + protected function tearDown(): void { Mockery::close(); @@ -42,7 +53,7 @@ class AttendanceCommentTemplateApiTest extends TestCase $this->app->instance(AttendanceCommentTemplateService::class, $mock); - $response = $this->getJson('/api/attendance-comment-templates'); + $response = $this->getJson('/api/v1/attendance-comment-templates'); $response->assertOk() ->assertJson([ @@ -63,7 +74,7 @@ class AttendanceCommentTemplateApiTest extends TestCase $this->app->instance(AttendanceCommentTemplateService::class, $mock); - $response = $this->getJson('/api/attendance-comment-templates?active_only=1'); + $response = $this->getJson('/api/v1/attendance-comment-templates?active_only=1'); $response->assertOk() ->assertJson([ @@ -100,7 +111,7 @@ class AttendanceCommentTemplateApiTest extends TestCase $this->app->instance(AttendanceCommentTemplateService::class, $mock); - $response = $this->postJson('/api/attendance-comment-templates', $payload); + $response = $this->postJson('/api/v1/attendance-comment-templates', $payload); $response->assertCreated() ->assertJsonPath('status', 'success') @@ -118,7 +129,7 @@ class AttendanceCommentTemplateApiTest extends TestCase 'is_active' => true, ]; - $response = $this->postJson('/api/attendance-comment-templates', $payload); + $response = $this->postJson('/api/v1/attendance-comment-templates', $payload); $response->assertStatus(422) ->assertJsonValidationErrors(['max_score']); @@ -140,7 +151,7 @@ class AttendanceCommentTemplateApiTest extends TestCase $this->app->instance(AttendanceCommentTemplateService::class, $mock); - $response = $this->getJson('/api/attendance-comment-templates/5'); + $response = $this->getJson('/api/v1/attendance-comment-templates/5'); $response->assertOk() ->assertJsonPath('status', 'success') @@ -171,7 +182,7 @@ class AttendanceCommentTemplateApiTest extends TestCase $this->app->instance(AttendanceCommentTemplateService::class, $mock); - $response = $this->putJson('/api/attendance-comment-templates/7', $payload); + $response = $this->putJson('/api/v1/attendance-comment-templates/7', $payload); $response->assertOk() ->assertJsonPath('status', 'success') @@ -186,7 +197,7 @@ class AttendanceCommentTemplateApiTest extends TestCase 'max_score' => 20, ]; - $response = $this->putJson('/api/attendance-comment-templates/7', $payload); + $response = $this->putJson('/api/v1/attendance-comment-templates/7', $payload); $response->assertStatus(422) ->assertJsonValidationErrors(['max_score']); @@ -201,7 +212,7 @@ class AttendanceCommentTemplateApiTest extends TestCase $this->app->instance(AttendanceCommentTemplateService::class, $mock); - $response = $this->deleteJson('/api/attendance-comment-templates/12'); + $response = $this->deleteJson('/api/v1/attendance-comment-templates/12'); $response->assertOk() ->assertJsonPath('status', 'success') @@ -226,7 +237,7 @@ class AttendanceCommentTemplateApiTest extends TestCase $this->app->instance(AttendanceCommentTemplateService::class, $mock); - $response = $this->getJson('/api/attendance-comment-templates/list-data'); + $response = $this->getJson('/api/v1/attendance-comment-templates/list-data'); $response->assertOk() ->assertJsonCount(1, 'templates')