mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 11:14:06 +00:00
154 - Sending Promoters an Invitation Email
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\Mail\InvitationEmail;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Invitation extends Model
|
||||
@@ -22,4 +24,9 @@ class Invitation extends Model
|
||||
{
|
||||
return $this->user_id !== null;
|
||||
}
|
||||
|
||||
public function send()
|
||||
{
|
||||
Mail::to($this->email)->send(new InvitationEmail($this));
|
||||
}
|
||||
}
|
||||
|
||||
35
app/Mail/InvitationEmail.php
Normal file
35
app/Mail/InvitationEmail.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class InvitationEmail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public $invitation;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($invitation)
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->view('view.name');
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Invitation;
|
||||
use App\Mail\InvitationEmail;
|
||||
use App\Facades\InvitationCode;
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
|
||||
@@ -16,8 +17,8 @@ use Illuminate\Foundation\Inspiring;
|
||||
*/
|
||||
|
||||
Artisan::command('invite-promoter {email}', function ($email) {
|
||||
$invitation = Invitation::create([
|
||||
Invitation::create([
|
||||
'email' => $email,
|
||||
'code' => InvitationCode::generate(),
|
||||
]);
|
||||
])->send();
|
||||
})->describe('Invite a new promoter to create an account.');
|
||||
|
||||
@@ -4,7 +4,9 @@ namespace Tests\Feature;
|
||||
|
||||
use App\Invitation;
|
||||
use Tests\TestCase;
|
||||
use App\Mail\InvitationEmail;
|
||||
use App\Facades\InvitationCode;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
@@ -15,6 +17,7 @@ class InvitePromoterTest extends TestCase
|
||||
/** @test */
|
||||
function inviting_a_promoter_via_the_cli()
|
||||
{
|
||||
Mail::fake();
|
||||
InvitationCode::shouldReceive('generate')->andReturn('TESTCODE1234');
|
||||
|
||||
$this->artisan('invite-promoter', ['email' => 'john@example.com']);
|
||||
@@ -23,5 +26,10 @@ class InvitePromoterTest extends TestCase
|
||||
$invitation = Invitation::first();
|
||||
$this->assertEquals('john@example.com', $invitation->email);
|
||||
$this->assertEquals('TESTCODE1234', $invitation->code);
|
||||
|
||||
Mail::assertSent(InvitationEmail::class, function ($mail) use ($invitation) {
|
||||
return $mail->hasTo('john@example.com')
|
||||
&& $mail->invitation->is($invitation);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user