employer = User::create([ 'name' => 'Jane Sponsor', 'email' => 'sponsor@example.com', 'password' => bcrypt('password'), 'role' => 'employer', ]); } /** * 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'); } }