218 lines
9.0 KiB
PHP
218 lines
9.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Sponsor;
|
|
use App\Models\User;
|
|
use App\Models\EmployerProfile;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Tests\TestCase;
|
|
|
|
class SponsorAuthWebTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
/**
|
|
* Test successful multi-step web employer registration with Emirates ID upload.
|
|
*/
|
|
public function test_employer_web_registration_with_emirates_id()
|
|
{
|
|
Storage::fake('public');
|
|
|
|
$emiratesIdFile = UploadedFile::fake()->create('emirates_id.pdf', 500, 'application/pdf');
|
|
|
|
// Step 1: Registration Form Submission
|
|
$responseStep1 = $this->post('/employer/register', [
|
|
'name' => 'Abdullah Ahmed',
|
|
'email' => 'abdullah@example.com',
|
|
'phone' => '501234567',
|
|
'address' => 'Villa 14, Al Safa, Dubai',
|
|
]);
|
|
|
|
$responseStep1->assertRedirect(route('employer.verify-email'));
|
|
|
|
// Verify session data
|
|
$pendingReg = session('pending_employer_registration');
|
|
$this->assertNotNull($pendingReg);
|
|
$this->assertEquals('Abdullah Ahmed', $pendingReg['name']);
|
|
|
|
// Step 2: OTP Verification (using local environment dummy code)
|
|
$responseStep2 = $this->post('/employer/verify-email', [
|
|
'otp' => '000000',
|
|
]);
|
|
|
|
$responseStep2->assertRedirect(route('employer.upload-emirates-id'));
|
|
$this->assertTrue(session('employer_email_verified'));
|
|
|
|
// Step 3: Emirates ID Upload
|
|
$responseStep3 = $this->post('/employer/upload-emirates-id', [
|
|
'emirates_id_file' => $emiratesIdFile,
|
|
]);
|
|
|
|
$responseStep3->assertRedirect(route('employer.register-payment'));
|
|
$this->assertTrue(session('employer_emirates_id_uploaded'));
|
|
|
|
$pendingRegAfterId = session('pending_employer_registration');
|
|
$this->assertNotNull($pendingRegAfterId['emirates_id_number']);
|
|
$this->assertNotNull($pendingRegAfterId['emirates_id_expiry']);
|
|
$this->assertNull($pendingRegAfterId['emirates_id_file']);
|
|
|
|
// Step 4: Payment Choice
|
|
$responseStep4 = $this->post('/employer/register-payment', [
|
|
'plan_id' => 'premium',
|
|
'amount_aed' => 199.00,
|
|
'paytabs_transaction_id' => 'TRAN_ABC_123',
|
|
]);
|
|
|
|
$responseStep4->assertJson(['message' => 'Payment processed successfully.']);
|
|
|
|
// Step 5: Create Password & Create Records
|
|
$responseStep5 = $this->post('/employer/create-password', [
|
|
'password' => 'SecurePass123!',
|
|
'password_confirmation' => 'SecurePass123!',
|
|
]);
|
|
|
|
$responseStep5->assertRedirect(route('employer.dashboard'));
|
|
|
|
// Verify Database Records
|
|
$this->assertDatabaseHas('users', [
|
|
'email' => 'abdullah@example.com',
|
|
'role' => 'employer',
|
|
'name' => 'Mohammad Jobaier Mohammad Abul Kalam',
|
|
]);
|
|
|
|
$this->assertDatabaseHas('employer_profiles', [
|
|
'phone' => '501234567',
|
|
'company_name' => 'Mohammad Jobaier Mohammad Abul Kalam Household',
|
|
'emirates_id_front' => null, // File is not stored
|
|
'address' => 'Villa 14, Al Safa, Dubai',
|
|
]);
|
|
|
|
$profile = EmployerProfile::where('phone', '501234567')->first();
|
|
$this->assertEquals('784-1987-5493842-5', $profile->emirates_id_number);
|
|
$this->assertEquals('2027-12-11', $profile->emirates_id_expiry);
|
|
$this->assertEquals('Mohammad Jobaier Mohammad Abul Kalam', $profile->emirates_id_name);
|
|
$this->assertEquals('1987-04-14', $profile->emirates_id_dob);
|
|
$this->assertEquals('Bangladesh', $profile->nationality);
|
|
$this->assertEquals('2025-12-12', $profile->emirates_id_issue_date);
|
|
$this->assertEquals('Msj International Technical Services L.L.C UAE', $profile->emirates_id_employer);
|
|
$this->assertEquals('Dubai', $profile->emirates_id_issue_place);
|
|
$this->assertEquals('Electrician', $profile->emirates_id_occupation);
|
|
|
|
$this->assertDatabaseHas('sponsors', [
|
|
'email' => 'abdullah@example.com',
|
|
'mobile' => '501234567',
|
|
'emirates_id_file' => null, // File is not stored
|
|
'address' => 'Villa 14, Al Safa, Dubai',
|
|
'emirates_id' => '784-1987-5493842-5',
|
|
'full_name' => 'Mohammad Jobaier Mohammad Abul Kalam',
|
|
'emirates_id_name' => 'Mohammad Jobaier Mohammad Abul Kalam',
|
|
'emirates_id_dob' => '1987-04-14',
|
|
'nationality' => 'Bangladesh',
|
|
'emirates_id_issue_date' => '2025-12-12',
|
|
'emirates_id_expiry' => '2027-12-11',
|
|
'emirates_id_employer' => 'Msj International Technical Services L.L.C UAE',
|
|
'emirates_id_issue_place' => 'Dubai',
|
|
'emirates_id_occupation' => 'Electrician',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Test successful multi-step web employer registration with two-sided Emirates ID upload.
|
|
*/
|
|
public function test_employer_web_registration_with_two_sided_emirates_id()
|
|
{
|
|
Storage::fake('public');
|
|
|
|
$frontFile = UploadedFile::fake()->create('front.jpg', 500, 'image/jpeg');
|
|
$backFile = UploadedFile::fake()->create('back.jpg', 500, 'image/jpeg');
|
|
|
|
// Step 1: Registration Form Submission
|
|
$responseStep1 = $this->post('/employer/register', [
|
|
'name' => 'Fatima Al-Mansoori',
|
|
'email' => 'fatima@example.com',
|
|
'phone' => '509876543',
|
|
'address' => 'Apartment 402, Al Nahda, Sharjah',
|
|
]);
|
|
|
|
$responseStep1->assertRedirect(route('employer.verify-email'));
|
|
|
|
// Verify session data
|
|
$pendingReg = session('pending_employer_registration');
|
|
$this->assertNotNull($pendingReg);
|
|
$this->assertEquals('Fatima Al-Mansoori', $pendingReg['name']);
|
|
|
|
// Step 2: OTP Verification
|
|
$responseStep2 = $this->post('/employer/verify-email', [
|
|
'otp' => '000000',
|
|
]);
|
|
|
|
$responseStep2->assertRedirect(route('employer.upload-emirates-id'));
|
|
$this->assertTrue(session('employer_email_verified'));
|
|
|
|
// Step 3: Emirates ID Front and Back Upload
|
|
$responseStep3 = $this->post('/employer/upload-emirates-id', [
|
|
'emirates_id_front' => $frontFile,
|
|
'emirates_id_back' => $backFile,
|
|
]);
|
|
|
|
$responseStep3->assertRedirect(route('employer.register-payment'));
|
|
$this->assertTrue(session('employer_emirates_id_uploaded'));
|
|
|
|
$pendingRegAfterId = session('pending_employer_registration');
|
|
$this->assertEquals('784-1987-5493842-5', $pendingRegAfterId['emirates_id_number']); // Mock fallback value
|
|
$this->assertEquals('2027-12-11', $pendingRegAfterId['emirates_id_expiry']); // Mock fallback value
|
|
|
|
// Step 4: Payment Choice
|
|
$responseStep4 = $this->post('/employer/register-payment', [
|
|
'plan_id' => 'premium',
|
|
'amount_aed' => 199.00,
|
|
'paytabs_transaction_id' => 'TRAN_XYZ_789',
|
|
]);
|
|
|
|
$responseStep4->assertJson(['message' => 'Payment processed successfully.']);
|
|
|
|
// Step 5: Create Password & Create Records
|
|
$responseStep5 = $this->post('/employer/create-password', [
|
|
'password' => 'SecurePass123!',
|
|
'password_confirmation' => 'SecurePass123!',
|
|
]);
|
|
|
|
$responseStep5->assertRedirect(route('employer.dashboard'));
|
|
|
|
// Verify Database Records
|
|
$this->assertDatabaseHas('users', [
|
|
'email' => 'fatima@example.com',
|
|
'role' => 'employer',
|
|
'name' => 'Mohammad Jobaier Mohammad Abul Kalam',
|
|
]);
|
|
|
|
$this->assertDatabaseHas('employer_profiles', [
|
|
'phone' => '509876543',
|
|
'company_name' => 'Mohammad Jobaier Mohammad Abul Kalam Household',
|
|
'address' => 'Apartment 402, Al Nahda, Sharjah',
|
|
]);
|
|
|
|
$this->assertDatabaseHas('sponsors', [
|
|
'email' => 'fatima@example.com',
|
|
'mobile' => '509876543',
|
|
'full_name' => 'Mohammad Jobaier Mohammad Abul Kalam',
|
|
]);
|
|
|
|
$profile = EmployerProfile::where('phone', '509876543')->first();
|
|
$this->assertNotNull($profile);
|
|
$this->assertEquals('784-1987-5493842-5', $profile->emirates_id_number);
|
|
$this->assertEquals('2027-12-11', $profile->emirates_id_expiry);
|
|
$this->assertEquals('Mohammad Jobaier Mohammad Abul Kalam', $profile->emirates_id_name);
|
|
$this->assertEquals('1987-04-14', $profile->emirates_id_dob);
|
|
$this->assertEquals('Bangladesh', $profile->nationality);
|
|
$this->assertEquals('2025-12-12', $profile->emirates_id_issue_date);
|
|
$this->assertEquals('Msj International Technical Services L.L.C UAE', $profile->emirates_id_employer);
|
|
$this->assertEquals('Dubai', $profile->emirates_id_issue_place);
|
|
$this->assertEquals('Electrician', $profile->emirates_id_occupation);
|
|
$this->assertEquals('Apartment 402, Al Nahda, Sharjah', $profile->address);
|
|
}
|
|
}
|