diff --git a/app/Console/Commands/ResendLeadVerificationEmailsCommand.php b/app/Console/Commands/ResendLeadVerificationEmailsCommand.php new file mode 100644 index 00000000..89180534 --- /dev/null +++ b/app/Console/Commands/ResendLeadVerificationEmailsCommand.php @@ -0,0 +1,57 @@ +option('dry-run'); + + if ($isDryRun) { + $this->warn('DRY RUN — no emails will be dispatched.'); + $this->newLine(); + } + + $leads = UserLead::query()->whereNull('email_verified_at')->get(); + + if ($leads->isEmpty()) { + $this->info('No unverified leads found.'); + + return self::SUCCESS; + } + + $dispatched = 0; + + $progressBar = $this->output->createProgressBar($leads->count()); + $progressBar->start(); + + foreach ($leads as $lead) { + if (! $isDryRun) { + $lead->sendEmailVerificationNotification(); + } + + $dispatched++; + $progressBar->advance(); + } + + $progressBar->finish(); + $this->newLine(2); + + $this->table( + ['Action', 'Count'], + [ + ['dispatched'.($isDryRun ? ' (dry run)' : ''), $dispatched], + ] + ); + + return self::SUCCESS; + } +} diff --git a/tests/Feature/ResendLeadVerificationEmailsCommandTest.php b/tests/Feature/ResendLeadVerificationEmailsCommandTest.php new file mode 100644 index 00000000..ecd7d374 --- /dev/null +++ b/tests/Feature/ResendLeadVerificationEmailsCommandTest.php @@ -0,0 +1,41 @@ +count(3)->create(['email_verified_at' => null]); + UserLead::factory()->create(['email_verified_at' => now()]); + + $this->artisan('leads:resend-verification-emails') + ->assertSuccessful(); + + Notification::assertSentTo($unverified, VerifyUserLeadEmailNotification::class); + Notification::assertCount(3); +}); + +it('does not dispatch emails in dry-run mode', function () { + Notification::fake(); + + UserLead::factory()->count(2)->create(['email_verified_at' => null]); + + $this->artisan('leads:resend-verification-emails', ['--dry-run' => true]) + ->assertSuccessful(); + + Notification::assertNothingSent(); +}); + +it('exits early when there are no unverified leads', function () { + Notification::fake(); + + UserLead::factory()->create(['email_verified_at' => now()]); + + $this->artisan('leads:resend-verification-emails') + ->expectsOutput('No unverified leads found.') + ->assertSuccessful(); + + Notification::assertNothingSent(); +});