mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 11:14:06 +00:00
112 lines
3.0 KiB
PHP
112 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\User;
|
|
use App\Invitation;
|
|
use Tests\TestCase;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
class AcceptInvitationTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
/** @test */
|
|
function viewing_an_unused_invitation()
|
|
{
|
|
$this->withoutExceptionHandling();
|
|
|
|
$invitation = factory(Invitation::class)->create([
|
|
'user_id' => null,
|
|
'code' => 'TESTCODE1234',
|
|
]);
|
|
|
|
$response = $this->get('/invitations/TESTCODE1234');
|
|
|
|
$response->assertStatus(200);
|
|
$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);
|
|
}
|
|
|
|
/** @test */
|
|
function registering_with_a_valid_invitation_code()
|
|
{
|
|
$this->withoutExceptionHandling();
|
|
|
|
$invitation = factory(Invitation::class)->create([
|
|
'user_id' => null,
|
|
'code' => 'TESTCODE1234',
|
|
]);
|
|
|
|
$response = $this->post('/register', [
|
|
'email' => 'john@example.com',
|
|
'password' => 'secret',
|
|
'invitation_code' => 'TESTCODE1234',
|
|
]);
|
|
|
|
$response->assertRedirect('/backstage/concerts');
|
|
|
|
$this->assertEquals(1, User::count());
|
|
$user = User::first();
|
|
$this->assertAuthenticatedAs($user);
|
|
$this->assertEquals('john@example.com', $user->email);
|
|
$this->assertTrue(Hash::check('secret', $user->password));
|
|
$this->assertTrue($invitation->fresh()->user->is($user));
|
|
}
|
|
|
|
/** @test */
|
|
function registering_with_a_used_invitation_code()
|
|
{
|
|
$invitation = factory(Invitation::class)->create([
|
|
'user_id' => factory(User::class)->create(),
|
|
'code' => 'TESTCODE1234',
|
|
]);
|
|
$this->assertEquals(1, User::count());
|
|
|
|
$response = $this->post('/register', [
|
|
'email' => 'john@example.com',
|
|
'password' => 'secret',
|
|
'invitation_code' => 'TESTCODE1234',
|
|
]);
|
|
|
|
$response->assertStatus(404);
|
|
$this->assertEquals(1, User::count());
|
|
}
|
|
|
|
/** @test */
|
|
function registering_with_an_invitation_code_that_does_not_exist()
|
|
{
|
|
$response = $this->post('/register', [
|
|
'email' => 'john@example.com',
|
|
'password' => 'secret',
|
|
'invitation_code' => 'TESTCODE1234',
|
|
]);
|
|
|
|
$response->assertStatus(404);
|
|
$this->assertEquals(0, User::count());
|
|
}
|
|
}
|