190 lines
5.9 KiB
PHP
190 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use App\Models\JobPost;
|
|
use App\Models\JobApplication;
|
|
use App\Models\Worker;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class EmployerJobTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected $employer;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->employer = User::create([
|
|
'name' => 'Jane Sponsor',
|
|
'email' => 'sponsor@example.com',
|
|
'password' => bcrypt('password'),
|
|
'role' => 'employer',
|
|
]);
|
|
|
|
// Create an active premium subscription so Jane can post/view jobs
|
|
\Illuminate\Support\Facades\DB::table('subscriptions')->insert([
|
|
'user_id' => $this->employer->id,
|
|
'plan_id' => 'premium',
|
|
'amount_aed' => 199.00,
|
|
'starts_at' => now(),
|
|
'expires_at' => now()->addDays(30),
|
|
'paytabs_transaction_id' => 'TEST_TXN_ID',
|
|
'status' => 'active',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Test displaying the employer jobs list with basic plan.
|
|
*/
|
|
public function test_employer_with_basic_plan_cannot_view_jobs_list()
|
|
{
|
|
// Update subscription to basic
|
|
\Illuminate\Support\Facades\DB::table('subscriptions')
|
|
->where('user_id', $this->employer->id)
|
|
->update(['plan_id' => 'basic']);
|
|
|
|
$response = $this->actingAs($this->employer)
|
|
->withSession(['user' => $this->employer])
|
|
->get('/employer/jobs');
|
|
|
|
$response->assertRedirect('/employer/subscription');
|
|
$response->assertSessionHas('error');
|
|
}
|
|
|
|
/**
|
|
* Test displaying the employer jobs list.
|
|
*/
|
|
public function test_employer_can_view_jobs_list()
|
|
{
|
|
$job = JobPost::create([
|
|
'employer_id' => $this->employer->id,
|
|
'title' => 'Experienced Mason',
|
|
'workers_needed' => 5,
|
|
'job_type' => 'Full Time',
|
|
'location' => 'Dubai Marina',
|
|
'salary' => 2800,
|
|
'start_date' => '2026-07-01',
|
|
'description' => 'Looking for experienced masons for a residential project.',
|
|
'requirements' => '5+ years experience, basic English.',
|
|
'status' => 'active',
|
|
]);
|
|
|
|
$response = $this->actingAs($this->employer)
|
|
->withSession(['user' => $this->employer])
|
|
->get('/employer/jobs');
|
|
|
|
$response->assertStatus(200);
|
|
$response->assertSee('Experienced Mason');
|
|
}
|
|
|
|
/**
|
|
* Test displaying the create job form.
|
|
*/
|
|
public function test_employer_can_view_create_job_form()
|
|
{
|
|
$response = $this->actingAs($this->employer)
|
|
->withSession(['user' => $this->employer])
|
|
->get('/employer/jobs/create');
|
|
|
|
$response->assertStatus(200);
|
|
}
|
|
|
|
/**
|
|
* Test storing a new job posting.
|
|
*/
|
|
public function test_employer_can_post_job()
|
|
{
|
|
$response = $this->actingAs($this->employer)
|
|
->withSession(['user' => $this->employer])
|
|
->post('/employer/jobs/create', [
|
|
'title' => 'Villa Cleaner',
|
|
'workers_needed' => 2,
|
|
'job_type' => 'Part Time',
|
|
'location' => 'Al Barsha',
|
|
'salary' => 1800,
|
|
'start_date' => '2026-07-10',
|
|
'description' => 'Need part-time villa cleaners for daily housekeeping tasks.',
|
|
'requirements' => 'Housekeeping experience is a plus.',
|
|
]);
|
|
|
|
$response->assertRedirect('/employer/jobs');
|
|
$response->assertSessionHas('success');
|
|
|
|
$this->assertDatabaseHas('job_posts', [
|
|
'employer_id' => $this->employer->id,
|
|
'title' => 'Villa Cleaner',
|
|
'workers_needed' => 2,
|
|
'job_type' => 'Part Time',
|
|
'location' => 'Al Barsha',
|
|
'salary' => 1800,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Test validation during job posting.
|
|
*/
|
|
public function test_job_posting_requires_fields()
|
|
{
|
|
$response = $this->actingAs($this->employer)
|
|
->withSession(['user' => $this->employer])
|
|
->post('/employer/jobs/create', [
|
|
'title' => '',
|
|
'workers_needed' => 0,
|
|
'salary' => -100,
|
|
]);
|
|
|
|
$response->assertSessionHasErrors(['title', 'workers_needed', 'location', 'salary', 'job_type', 'start_date', 'description']);
|
|
}
|
|
|
|
/**
|
|
* Test viewing job applicants.
|
|
*/
|
|
public function test_employer_can_view_applicants()
|
|
{
|
|
$job = JobPost::create([
|
|
'employer_id' => $this->employer->id,
|
|
'title' => 'Mason for Project',
|
|
'workers_needed' => 3,
|
|
'job_type' => 'Contract',
|
|
'location' => 'Sharjah',
|
|
'salary' => 3000,
|
|
'start_date' => '2026-07-15',
|
|
'description' => 'Contract mason project.',
|
|
'status' => 'active',
|
|
]);
|
|
|
|
$worker = Worker::create([
|
|
'name' => 'John Worker',
|
|
'email' => 'worker@example.com',
|
|
'phone' => '+971500000001',
|
|
'nationality' => 'Indian',
|
|
'age' => 30,
|
|
'salary' => 2500,
|
|
'availability' => 'Available',
|
|
'experience' => '4 Years',
|
|
'religion' => 'Christian',
|
|
'bio' => 'Vetted domestic worker with great experience.',
|
|
]);
|
|
|
|
$application = JobApplication::create([
|
|
'job_id' => $job->id,
|
|
'worker_id' => $worker->id,
|
|
'status' => 'applied',
|
|
]);
|
|
|
|
$response = $this->actingAs($this->employer)
|
|
->withSession(['user' => $this->employer])
|
|
->get("/employer/jobs/{$job->id}/applicants");
|
|
|
|
$response->assertStatus(200);
|
|
$response->assertSee('John Worker');
|
|
}
|
|
}
|