File manager - Edit - /var/www/html/homologBancodetalentos/tests/Feature/TalentBank/ApplicationNotificationTest.php
Back
<?php namespace Tests\Feature\TalentBank; use App\Events\TalentBank\ApplicationLifecycleEvent; use App\Http\Services\TalentBank\EmailService; use App\Jobs\TalentBank\SendTalentBankEmailJob; use App\Mail\TalentBank\ApplicationEventMail; use App\Models\TalentBank\Candidate; use App\Models\TalentBank\Company; use App\Models\TalentBank\EmailSendLog; use App\Models\TalentBank\JobListing; use App\Models\TalentBank\ContractType; use App\Models\TalentBank\Occupation; use App\Models\TalentBank\SalaryRange; use App\Support\TalentBank\ApplicationNotificationType; use App\Support\TalentBank\JobApplicationStatus; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Queue; use Tests\TestCase; class ApplicationNotificationTest extends TestCase { use DatabaseTransactions; private function seedMinimalApplication(): array { // Gera sufixo numérico de 4 dígitos único por execução para evitar conflito de unique keys $n = rand(1000, 9999); $company = Company::create([ 'cnpj' => sprintf('1234%06d99', $n), // 14 dígitos 'corporate_name' => "Empresa Teste LTDA {$n}", 'trading_name' => "Empresa Teste {$n}", 'email' => "empresa{$n}@test.com", 'email_notifications_enabled' => true, 'active' => true, ]); $candidate = Candidate::create([ 'cpf' => sprintf('1234567%04d', $n), // 11 dígitos 'name' => 'Candidato Teste', 'email' => "candidato{$n}@test.com", 'email_notifications_enabled' => true, 'active' => true, ]); $occupationId = Occupation::value('id') ?? 1; $salaryRangeId = SalaryRange::value('id') ?? 1; $contractTypeId = ContractType::value('id') ?? 1; $job = JobListing::create([ 'company_id' => $company->id, 'occupation_id' => $occupationId, 'salary_range_id' => $salaryRangeId, 'contract_type_id' => $contractTypeId, 'spots_total' => 1, 'description' => 'Vaga teste', 'is_hiring' => true, ]); return compact('company', 'candidate', 'job'); } public function test_application_submitted_dispatches_lifecycle_event(): void { Queue::fake(); ['company' => $company, 'candidate' => $candidate, 'job' => $job] = $this->seedMinimalApplication(); app(\App\Http\Services\TalentBank\JobService::class)->storeApplication($job, $candidate); $this->assertDatabaseHas('job_listing_candidate', [ 'job_listing_id' => $job->id, 'candidate_id' => $candidate->id, 'status' => JobApplicationStatus::ENROLLED, ]); } public function test_listener_creates_in_app_notifications(): void { ['company' => $company, 'candidate' => $candidate, 'job' => $job] = $this->seedMinimalApplication(); $listener = app(\App\Listeners\TalentBank\HandleApplicationLifecycleEvent::class); $listener->handle(new ApplicationLifecycleEvent( ApplicationNotificationType::APPLICATION_SUBMITTED, $job, $candidate, null, JobApplicationStatus::ENROLLED, )); $this->assertDatabaseHas('candidate_notifications', [ 'candidate_id' => $candidate->id, 'type' => ApplicationNotificationType::APPLICATION_SUBMITTED, ]); $this->assertDatabaseHas('company_notifications', [ 'company_id' => $company->id, 'type' => ApplicationNotificationType::NEW_APPLICANT, ]); } public function test_status_change_records_history(): void { ['candidate' => $candidate, 'job' => $job] = $this->seedMinimalApplication(); $job->candidates()->attach($candidate->id, ['status' => JobApplicationStatus::ENROLLED]); app(\App\Http\Services\TalentBank\JobService::class) ->updateApplicationStatus($job, $candidate, JobApplicationStatus::PENDING); $listener = app(\App\Listeners\TalentBank\HandleApplicationLifecycleEvent::class); $listener->handle(new ApplicationLifecycleEvent( ApplicationNotificationType::STATUS_CHANGED, $job->fresh(), $candidate, JobApplicationStatus::ENROLLED, JobApplicationStatus::PENDING, )); $this->assertDatabaseHas('job_application_status_histories', [ 'to_status' => JobApplicationStatus::PENDING, ]); } public function test_email_deduplication(): void { Queue::fake(); $emailService = app(EmailService::class); $mailable = new ApplicationEventMail( ApplicationNotificationType::APPLICATION_SUBMITTED, 'candidate', JobListing::make(['description' => 'x']), Candidate::make(['name' => 'Test', 'email' => 'a@b.com']), ); $key = 'test:dedupe:' . uniqid('', true); $emailService->queue(ApplicationNotificationType::APPLICATION_SUBMITTED, 'candidate', 1, 'test@example.com', $mailable, $key); $emailService->queue(ApplicationNotificationType::APPLICATION_SUBMITTED, 'candidate', 1, 'test@example.com', $mailable, $key); $this->assertEquals(1, EmailSendLog::where('dedupe_key', $key)->where('status', EmailSendLog::STATUS_QUEUED)->count()); $this->assertEquals(1, EmailSendLog::where('dedupe_key', $key)->where('status', EmailSendLog::STATUS_SKIPPED_DUPLICATE)->count()); Queue::assertPushed(SendTalentBankEmailJob::class, 1); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings