Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Modules/HR/Tests/Feature/CopyForAiEvaluationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Modules\HR\Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Modules\HR\Entities\Applicant;
use Modules\HR\Entities\Application;
use Modules\HR\Entities\Job;
use Tests\TestCase;

class CopyForAiEvaluationTest extends TestCase
{
use RefreshDatabase;

public function test_clipboard_text_includes_applied_for_job_title()
{
$applicant = Applicant::factory()->create(['name' => 'Jane Doe']);
$job = Job::factory()->create(['title' => 'Senior Laravel Developer']);
$application = Application::factory()->create([
'hr_applicant_id' => $applicant->id,
'hr_job_id' => $job->id,
]);

$html = view('hr.application.copy-for-ai-evaluation', [
'applicant' => $applicant,
'application' => $application,
])->render();

$this->assertStringContainsString('Applied for: ' . $job->title, $html);
}
Comment on lines +15 to +30

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Test should also verify behavior when job is null.

The test verifies the happy path (job title present), but does not test the guard logic (optional() on line 6 of the template). A second test case should verify that the 'Applied for:' line does not appear when $application->job is null.

Consider adding a complementary test:

public function test_clipboard_text_omits_applied_for_when_no_job()
{
    $applicant = Applicant::factory()->create(['name' => 'John Doe']);
    $application = Application::factory()->create([
        'hr_applicant_id' => $applicant->id,
        'hr_job_id' => null,
    ]);

    $html = view('hr.application.copy-for-ai-evaluation', [
        'applicant' => $applicant,
        'application' => $application,
        'applicationFormDetails' => null, // Add missing variable
    ])->render();

    $this->assertStringNotContainsString('Applied for:', $html);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Modules/HR/Tests/Feature/CopyForAiEvaluationTest.php` around lines 15 - 30,
Add a complementary test method to cover the null job scenario that the existing
test does not address. Create a new test method in the CopyForAiEvaluationTest
class that creates an Application with hr_job_id set to null (similar to the
existing test_clipboard_text_includes_applied_for_job_title method), passes the
required view variables including applicant and application to the view render
call, and then verifies using assertStringNotContainsString that the "Applied
for:" text does not appear in the rendered HTML output when no job is associated
with the application.

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
$clipboardLines[] = 'Candidate to evaluate:';
$clipboardLines[] = $applicant->name . ', applied on ' . $application->created_at->format(config('constants.display_date_format'));

$appliedForJobTitle = optional($application->job)->title;
if (!empty($appliedForJobTitle)) {
$clipboardLines[] = 'Applied for: ' . $appliedForJobTitle;
}

if (!empty($applicant->graduation_year)) {
$clipboardLines[] = 'Graduation Year: ' . $applicant->graduation_year;
}
Expand Down
Loading