Created
August 3, 2016 18:52
-
-
Save davidhemphill/bb5b6233f9551a3956280288f099fe6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Foundation\Testing\WithoutMiddleware; | |
use Illuminate\Foundation\Testing\DatabaseMigrations; | |
class RegistrationControllerTest extends TestCase | |
{ | |
use DatabaseMigrations; | |
public function setUpTeam() | |
{ | |
return factory(App\Team::class)->create(); | |
} | |
/** @test */ | |
public function a_person_can_see_the_register_page_for_an_event() | |
{ | |
$team = $this->setUpTeam(); | |
Landlord::addTenant('team_id', $team->id); | |
$event = factory(App\Event::class)->create(['team_id' => $team->id]); | |
$response = $this->get("/events/{$event->hash}/register"); | |
$this->assertResponseOk(); | |
$this->see($event->name); | |
} | |
/** @test */ | |
public function a_person_can_register_for_an_event() | |
{ | |
$this->disableExceptionHandling(); | |
$event = factory(App\Event::class)->create(); | |
// Save first Ticket/Pass | |
$first_ticket = factory(App\Ticket::class)->make([ | |
'event_id' => $event->id | |
]); | |
$pass = factory(App\Pass::class)->create(); | |
$pass->ticket()->save($first_ticket); | |
// Now let's create a Workshop | |
$second_ticket = factory(App\Ticket::class)->make([ | |
'event_id' => $event->id | |
]); | |
$workshop = factory(App\Workshop::class)->create(); | |
$workshop->ticket()->save($second_ticket); | |
// Save these Tickets to the Event | |
$first_product = factory(App\Product::class)->make(); | |
$first_ticket->product()->save($first_product); | |
$second_product = factory(App\Product::class)->make(); | |
$second_ticket->product()->save($second_product); | |
$event->products()->save($first_ticket); | |
$event->products()->save($second_ticket); | |
$user = factory(App\User::class)->create(); | |
auth()->login($user); | |
$this->post("/events/{$event->hash}/register", [ | |
'event' => $event->hash, | |
'user_id' => 1, | |
'tickets' => [1 => 2], | |
'first_name' => 'Darius', | |
'last_name' => 'Rucker', | |
'email' => '[email protected]', | |
]); | |
// Assert | |
$order = App\Order::first(); | |
$this->seeInDatabase('carts', [ | |
'event_id' => $event->id, | |
'user_id' => 1, | |
]); | |
$this->seeInDatabase('orders', [ | |
'event_id' => $event->id, | |
'user_id' => 1, | |
]); | |
$this->seeInDatabase('registrations', [ | |
'event_id' => $event->id, | |
'user_id' => 1, | |
]); | |
$this->assertEquals(2, App\Registration::whereUserId(1) | |
->whereEventId($event->id) | |
->get() | |
->count()); | |
$this->assertRedirectedToRoute('events.register.confirmation', [$event->hash, $order->hash]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment