admin = User::create([ 'name' => 'System Admin', 'email' => 'admin@marketplace.com', 'password' => bcrypt('password'), 'role' => 'admin', ]); $this->worker = Worker::create([ 'name' => 'Jane Helper', 'phone' => '+971520000000', 'email' => 'jane@helper.com', 'password' => bcrypt('password'), 'salary' => 1500, 'experience' => '2 years', 'nationality' => 'Philippine', 'gender' => 'Female', 'age' => 25, 'in_country' => true, 'visa_status' => 'Tourist Visa', 'preferred_job_type' => 'live-in', 'live_in_out' => 'live_in', 'preferred_location' => 'Dubai Marina', 'language' => 'English, Tagalog', 'availability' => 'Available Now', 'status' => 'active', 'religion' => 'Christian', 'bio' => 'Experienced helper', ]); } /** * Test admin can list workers. */ public function test_admin_can_list_workers() { $response = $this->actingAs($this->admin) ->withSession(['user' => $this->admin]) ->get('/admin/workers'); $response->assertStatus(200); $response->assertSee('Jane Helper'); } /** * Test admin can update worker profile with full registration fields. */ public function test_admin_can_update_worker_profile() { $skill1 = Skill::create(['name' => 'cooking']); $response = $this->actingAs($this->admin) ->withSession(['user' => $this->admin]) ->post("/admin/workers/{$this->worker->id}/update-profile", [ 'name' => 'Jane Helper Edited', 'phone' => '+971529999999', 'salary' => 1800, 'experience' => '4 years', 'nationality' => 'Philippine', 'gender' => 'Female', 'age' => 27, 'in_country' => 'false', 'visa_status' => null, 'preferred_job_type' => 'part-time', 'live_in_out' => 'live_out', 'preferred_location' => 'JLT', 'language' => 'English, Tagalog, Arabic', 'skills' => 'cooking, cleaning, childcare', ]); $response->assertStatus(302); $worker = $this->worker->fresh(); $this->assertEquals('Jane Helper Edited', $worker->name); $this->assertEquals('+971529999999', $worker->phone); $this->assertEquals(1800, (int)$worker->salary); $this->assertEquals('4 years', $worker->experience); $this->assertEquals(27, $worker->age); $this->assertFalse((bool)$worker->in_country); $this->assertEquals('live_out', $worker->live_in_out); $this->assertEquals('JLT', $worker->preferred_location); $this->assertEquals('English, Tagalog, Arabic', $worker->language); // Assert skills were synced $this->assertEquals(3, $worker->skills()->count()); $this->assertTrue($worker->skills->contains('name', 'cooking')); $this->assertTrue($worker->skills->contains('name', 'cleaning')); $this->assertTrue($worker->skills->contains('name', 'childcare')); } /** * Test validation on worker update profile. */ public function test_admin_cannot_update_worker_with_invalid_fields() { $response = $this->actingAs($this->admin) ->withSession(['user' => $this->admin]) ->post("/admin/workers/{$this->worker->id}/update-profile", [ 'name' => '', // Name is required 'phone' => '+971529999999', 'experience' => '', // Experience is required ]); $response->assertSessionHasErrors(['name', 'experience']); } /** * Test admin can view worker with passport and visa OCR data. */ public function test_admin_can_view_worker_with_document_ocr_data() { // Create a passport document with full OCR data $this->worker->documents()->create([ 'type' => 'passport', 'number' => 'Y34B67890', 'issue_date' => '2017-07-05', 'expiry_date' => '2022-07-05', 'ocr_accuracy' => 99.0, 'file_path' => null, 'ocr_data' => [ 'authority' => 'Issuing Authority', 'date_of_birth' => '14/05/1990', 'date_of_expiry' => '05/07/2022', 'date_of_issue' => '05/07/2017', 'document_type' => 'P', 'given_names' => 'KHALED', 'issuing_country' => 'ARE', 'nationality' => 'ARE', 'passport_number' => 'Y34B67890', 'personal_number' => '', 'place_of_birth' => 'SHARJAH', 'sex' => 'M', 'surname' => 'AL-HASHIMI', ], ]); // Create a visa document with full OCR data $this->worker->documents()->create([ 'type' => 'visa', 'number' => '201/2021/2840233', 'issue_date' => '2022-02-16', 'expiry_date' => '2024-02-15', 'ocr_accuracy' => 99.0, 'file_path' => null, 'ocr_data' => [ 'accompanied_by' => '9', 'expiry_date' => '2024-02-15', 'file_number' => '201/2021/2840233', 'id_number' => '784198839607839', 'issue_date' => '2022-02-16', 'name' => 'KHALED AL-HASHIMI', 'passport_number' => 'Y34B67890', 'place_of_issue' => 'Dubai', 'profession' => 'CLEANER', 'sponsor' => 'Sponsor Company LLC', ], ]); $response = $this->actingAs($this->admin) ->withSession(['user' => $this->admin]) ->get('/admin/workers'); $response->assertStatus(200); // Verify documents are present in the page data $worker = \App\Models\Worker::with('documents')->find($this->worker->id); $passportDoc = $worker->documents->firstWhere('type', 'passport'); $visaDoc = $worker->documents->firstWhere('type', 'visa'); $this->assertNotNull($passportDoc); $this->assertEquals('Y34B67890', $passportDoc->number); $this->assertEquals('KHALED', $passportDoc->ocr_data['given_names']); $this->assertEquals('AL-HASHIMI', $passportDoc->ocr_data['surname']); $this->assertEquals('ARE', $passportDoc->ocr_data['nationality']); $this->assertEquals('ARE', $passportDoc->ocr_data['issuing_country']); $this->assertEquals('SHARJAH', $passportDoc->ocr_data['place_of_birth']); $this->assertEquals('M', $passportDoc->ocr_data['sex']); $this->assertEquals('P', $passportDoc->ocr_data['document_type']); $this->assertNotNull($visaDoc); $this->assertEquals('201/2021/2840233', $visaDoc->number); $this->assertEquals('784198839607839', $visaDoc->ocr_data['id_number']); $this->assertEquals('CLEANER', $visaDoc->ocr_data['profession']); $this->assertEquals('Sponsor Company LLC', $visaDoc->ocr_data['sponsor']); $this->assertEquals('Dubai', $visaDoc->ocr_data['place_of_issue']); } }