mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 11:14:06 +00:00
149 - Viewing Used or Invalid Invitations
This commit is contained in:
@@ -11,6 +11,8 @@ class InvitationsController extends Controller
|
||||
{
|
||||
$invitation = Invitation::findByCode($code);
|
||||
|
||||
abort_if($invitation->hasBeenUsed(), 404);
|
||||
|
||||
return view('invitations.show', [
|
||||
'invitation' => $invitation,
|
||||
]);
|
||||
|
||||
@@ -8,6 +8,11 @@ class Invitation extends Model
|
||||
{
|
||||
public static function findByCode($code)
|
||||
{
|
||||
return self::where('code', $code)->first();
|
||||
return self::where('code', $code)->firstOrFail();
|
||||
}
|
||||
|
||||
public function hasBeenUsed()
|
||||
{
|
||||
return $this->user_id !== null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ class CreateInvitationsTable extends Migration
|
||||
{
|
||||
Schema::create('invitations', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->unsignedInteger('user_id')->nullable();
|
||||
$table->string('code');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\User;
|
||||
use App\Invitation;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
@@ -17,6 +18,7 @@ class AcceptInvitationTest extends TestCase
|
||||
$this->withoutExceptionHandling();
|
||||
|
||||
$invitation = factory(Invitation::class)->create([
|
||||
'user_id' => null,
|
||||
'code' => 'TESTCODE1234',
|
||||
]);
|
||||
|
||||
@@ -26,4 +28,25 @@ class AcceptInvitationTest extends TestCase
|
||||
$response->assertViewIs('invitations.show');
|
||||
$this->assertTrue($response->data('invitation')->is($invitation));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function viewing_a_used_invitation()
|
||||
{
|
||||
$invitation = factory(Invitation::class)->create([
|
||||
'user_id' => factory(User::class)->create(),
|
||||
'code' => 'TESTCODE1234',
|
||||
]);
|
||||
|
||||
$response = $this->get('/invitations/TESTCODE1234');
|
||||
|
||||
$response->assertStatus(404);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function viewing_an_invitation_that_does_not_exist()
|
||||
{
|
||||
$response = $this->get('/invitations/TESTCODE1234');
|
||||
|
||||
$response->assertStatus(404);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user