fix: consolidate purchase confirmation emails
This commit is contained in:
@@ -142,7 +142,7 @@ class NotificationMailServiceTest extends TestCase
|
||||
});
|
||||
}
|
||||
|
||||
public function test_it_sends_purchase_and_ticket_emails_to_the_purchase_recipient(): void
|
||||
public function test_it_sends_one_purchase_confirmation_with_generated_tickets_attached(): void
|
||||
{
|
||||
$this->useWebsiteTypeBranding();
|
||||
$purchase = Purchase::query()->create([
|
||||
@@ -175,30 +175,23 @@ class NotificationMailServiceTest extends TestCase
|
||||
$ticket = Ticket::query()->create([
|
||||
'tenant_code' => $this->tenant->codigo,
|
||||
'ticket' => fake()->uuid(),
|
||||
'source_purchase_id' => $purchase->id,
|
||||
'source_catalog_item_id' => $catalogItem->id,
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
$service = app(NotificationMailService::class);
|
||||
|
||||
$service->sendPurchasePaid($purchase->id);
|
||||
$service->sendTicketsAvailable($purchase->id, [$ticket->id]);
|
||||
$service->sendPurchaseConfirmed($purchase->id);
|
||||
|
||||
Mail::assertSent(Mailable::class, 2);
|
||||
Mail::assertSent(Mailable::class, function (Mailable $mail) use ($purchase): bool {
|
||||
$mail->assertTo('checkout@example.com');
|
||||
|
||||
return $mail->subject === "Pago confirmado - Compra #{$purchase->id}"
|
||||
&& str_contains($mail->render(), 'Total pagado')
|
||||
&& str_contains($mail->render(), 'border-top: 4px solid #112233')
|
||||
&& ! str_contains($mail->render(), 'border-top: 4px solid #ff7006');
|
||||
});
|
||||
Mail::assertSent(Mailable::class, function (Mailable $mail) use ($ticket): bool {
|
||||
Mail::assertSent(Mailable::class, 1);
|
||||
Mail::assertSent(Mailable::class, function (Mailable $mail) use ($purchase, $ticket): bool {
|
||||
$mail->assertTo('checkout@example.com');
|
||||
$attachment = collect($mail->rawAttachments)->firstWhere('name', "tickets_{$ticket->id}.pdf");
|
||||
|
||||
return $mail->subject === 'Tus tickets ya están disponibles'
|
||||
&& str_contains($mail->render(), 'Entrada general')
|
||||
&& str_contains($mail->render(), 'El ticket está adjunto')
|
||||
return $mail->subject === "Compra confirmada - Compra #{$purchase->id}"
|
||||
&& str_contains($mail->render(), '¡Compra realizada con éxito!')
|
||||
&& str_contains($mail->render(), 'Total pagado')
|
||||
&& str_contains($mail->render(), 'Tus tickets ya están disponibles')
|
||||
&& $attachment !== null
|
||||
&& $attachment['options'] === ['mime' => 'application/pdf']
|
||||
&& str_starts_with($attachment['data'], '%PDF-')
|
||||
@@ -207,6 +200,26 @@ class NotificationMailServiceTest extends TestCase
|
||||
});
|
||||
}
|
||||
|
||||
public function test_purchase_confirmation_omits_ticket_content_and_attachment_without_tickets(): void
|
||||
{
|
||||
$purchase = Purchase::query()->create([
|
||||
'tenant_codigo' => $this->tenant->codigo,
|
||||
'user_id' => $this->user->id,
|
||||
'status' => Purchase::STATUS_PAID,
|
||||
'payment_method' => 'transfer',
|
||||
'total' => 25,
|
||||
]);
|
||||
|
||||
app(NotificationMailService::class)->sendPurchaseConfirmed($purchase->id);
|
||||
|
||||
Mail::assertSent(Mailable::class, function (Mailable $mail) use ($purchase): bool {
|
||||
return $mail->subject === "Compra confirmada - Compra #{$purchase->id}"
|
||||
&& str_contains($mail->render(), '¡Compra realizada con éxito!')
|
||||
&& ! str_contains($mail->render(), 'Tus tickets ya están disponibles')
|
||||
&& $mail->rawAttachments === [];
|
||||
});
|
||||
}
|
||||
|
||||
private function useWebsiteTypeBranding(): void
|
||||
{
|
||||
$websiteType = WebsiteType::query()->create([
|
||||
|
||||
Reference in New Issue
Block a user