Commit 384fafc0 authored by Korko's avatar Korko
Browse files

Merge branch '1.7.x-redraw' of framagit.org:Korko/SecretSanta into 1.7.x-redraw

parents 0e28c8e1 505843b1
Pipeline #411338 failed with stages
in 11 seconds
<?php
namespace App\Mail;
use App;
use App\Models\Participant;
use DrawCrypt;
use Illuminate\Support\Facades\URL;
class SuggestRedraw extends Mailable
{
public $participantName;
public $organizerName;
public $targetName;
public $acceptLink;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(Participant $participant)
{
$this->subject = __('emails.organizer_recap_title', ['participant' => $participant->id]);
$this->participantName = $participant->name;
$this->organizerName = $participant->draw->organizer->name;
$this->targetName = $participant->target->name;
$this->acceptLink = URL::signedRoute('acceptRedraw', ['participant' => $participant->hash]).'#'.base64_encode(DrawCrypt::getKey());
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.suggest_redraw')
->text('emails.suggest_redraw_plain');
}
}
......@@ -3,7 +3,6 @@
namespace App\Models;
use App\Casts\EncryptedString;
use App\Events\DrawDeleted;
use App\Services\DrawHandler;
use DateInterval;
use DateTime;
......
<?php
use App\Jobs\ParseBounces;
use App\Mail\TargetDrawn;
use App\Models\Draw;
use App\Models\Mail as MailModel;
use App\Models\Participant;
use App\Services\DrawFormHandler;
use function Pest\Faker\faker;
......@@ -144,4 +147,59 @@ function formatParticipants($participants) : array {
}, array_keys($participants));
return $participants;
}
function assertReturnPath($prop, $status) : void {
Mail::fake();
$draw = Draw::factory()
->hasParticipants(3)
->create();
// Fake emails as bounces
$emailClient = test()->mock(EmailClient::class, function ($mock) use ($draw, $prop) {
// Get all the return path defined by the app
$links = [];
Mail::assertSent(function (TargetDrawn $mail) use (&$links, $prop) {
$links[] = $mail->$prop;
return true;
});
test()->assertEquals(count($draw->participants), count($links));
// Fake the list of "unseen mails"
$messages = [];
foreach($links as $link) {
$messages[] = test()->mock(EmailMessage::class, function ($mock) use ($link) {
$mock
->shouldReceive('getTo')
->once()
->andReturn([
(object) ['mailbox' => $link]
]);
$mock->shouldReceive('move')->once();
});
}
$mock
->shouldReceive('getUnseenMails')
->once()
->andReturn($messages);
});
// Ensure all participants are marked as bounced
foreach ($draw->participants as $participant) {
test()->assertEquals(MailModel::CREATED, $participant->mail->delivery_status);
}
// Parse bounces and mark them as bounced
$job = new ParseBounces();
$job->handle($emailClient);
// Ensure all participants are marked as bounced
foreach ($draw->participants as $participant) {
// Get the last delivery_status from DB via the "fresh" method
test()->assertEquals($status, $participant->mail->fresh()->delivery_status);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment