mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-15 22:53:31 +00:00
154 - Sending Promoters an Invitation Email
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
|
use App\Mail\InvitationEmail;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Invitation extends Model
|
class Invitation extends Model
|
||||||
@@ -22,4 +24,9 @@ class Invitation extends Model
|
|||||||
{
|
{
|
||||||
return $this->user_id !== null;
|
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
|
<?php
|
||||||
|
|
||||||
use App\Invitation;
|
use App\Invitation;
|
||||||
|
use App\Mail\InvitationEmail;
|
||||||
use App\Facades\InvitationCode;
|
use App\Facades\InvitationCode;
|
||||||
use Illuminate\Foundation\Inspiring;
|
use Illuminate\Foundation\Inspiring;
|
||||||
|
|
||||||
@@ -16,8 +17,8 @@ use Illuminate\Foundation\Inspiring;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Artisan::command('invite-promoter {email}', function ($email) {
|
Artisan::command('invite-promoter {email}', function ($email) {
|
||||||
$invitation = Invitation::create([
|
Invitation::create([
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
'code' => InvitationCode::generate(),
|
'code' => InvitationCode::generate(),
|
||||||
]);
|
])->send();
|
||||||
})->describe('Invite a new promoter to create an account.');
|
})->describe('Invite a new promoter to create an account.');
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ namespace Tests\Feature;
|
|||||||
|
|
||||||
use App\Invitation;
|
use App\Invitation;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
use App\Mail\InvitationEmail;
|
||||||
use App\Facades\InvitationCode;
|
use App\Facades\InvitationCode;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
use Illuminate\Foundation\Testing\WithFaker;
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
||||||
@@ -15,6 +17,7 @@ class InvitePromoterTest extends TestCase
|
|||||||
/** @test */
|
/** @test */
|
||||||
function inviting_a_promoter_via_the_cli()
|
function inviting_a_promoter_via_the_cli()
|
||||||
{
|
{
|
||||||
|
Mail::fake();
|
||||||
InvitationCode::shouldReceive('generate')->andReturn('TESTCODE1234');
|
InvitationCode::shouldReceive('generate')->andReturn('TESTCODE1234');
|
||||||
|
|
||||||
$this->artisan('invite-promoter', ['email' => 'john@example.com']);
|
$this->artisan('invite-promoter', ['email' => 'john@example.com']);
|
||||||
@@ -23,5 +26,10 @@ class InvitePromoterTest extends TestCase
|
|||||||
$invitation = Invitation::first();
|
$invitation = Invitation::first();
|
||||||
$this->assertEquals('john@example.com', $invitation->email);
|
$this->assertEquals('john@example.com', $invitation->email);
|
||||||
$this->assertEquals('TESTCODE1234', $invitation->code);
|
$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