mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-10 18:51:45 +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);
|
$invitation = Invitation::findByCode($code);
|
||||||
|
|
||||||
|
abort_if($invitation->hasBeenUsed(), 404);
|
||||||
|
|
||||||
return view('invitations.show', [
|
return view('invitations.show', [
|
||||||
'invitation' => $invitation,
|
'invitation' => $invitation,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ class Invitation extends Model
|
|||||||
{
|
{
|
||||||
public static function findByCode($code)
|
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) {
|
Schema::create('invitations', function (Blueprint $table) {
|
||||||
$table->increments('id');
|
$table->increments('id');
|
||||||
|
$table->unsignedInteger('user_id')->nullable();
|
||||||
$table->string('code');
|
$table->string('code');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
use Tests\TestCase;
|
use App\User;
|
||||||
use App\Invitation;
|
use App\Invitation;
|
||||||
|
use Tests\TestCase;
|
||||||
use Illuminate\Foundation\Testing\WithFaker;
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ class AcceptInvitationTest extends TestCase
|
|||||||
$this->withoutExceptionHandling();
|
$this->withoutExceptionHandling();
|
||||||
|
|
||||||
$invitation = factory(Invitation::class)->create([
|
$invitation = factory(Invitation::class)->create([
|
||||||
|
'user_id' => null,
|
||||||
'code' => 'TESTCODE1234',
|
'code' => 'TESTCODE1234',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -26,4 +28,25 @@ class AcceptInvitationTest extends TestCase
|
|||||||
$response->assertViewIs('invitations.show');
|
$response->assertViewIs('invitations.show');
|
||||||
$this->assertTrue($response->data('invitation')->is($invitation));
|
$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