start Events test
This commit is contained in:
@@ -209,8 +209,6 @@ class EventsTest extends TestCase
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** @test */
|
||||
public function a_user_can_create_an_event()
|
||||
{
|
||||
@@ -220,14 +218,7 @@ class EventsTest extends TestCase
|
||||
app(\DatabaseSeeder::class)->call(\EventCategorySeeder::class);
|
||||
|
||||
//dd(EventCategory::all());
|
||||
$response = $this->post('/api/events', [
|
||||
'name' => 'Test name event',
|
||||
'description' => 'Test description event',
|
||||
'category_id' => 1,
|
||||
'start_date' => '2020-07-20 09:00:00',
|
||||
'end_date' => '2020-07-26 09:00:00',
|
||||
'location' => 'Marcillac',
|
||||
])->assertStatus(201);
|
||||
$response = $this->post('/api/events', $this->data())->assertStatus(201);
|
||||
|
||||
$event = Event::first();
|
||||
|
||||
@@ -262,4 +253,69 @@ class EventsTest extends TestCase
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function event_name_are_required()
|
||||
{
|
||||
$this->actingAs($user = factory(\App\User::class)->create(), 'api');
|
||||
$response = $this->post('/api/events', array_merge($this->data(), ['name' => '']));
|
||||
|
||||
$response->assertSessionHasErrors('name');
|
||||
$this->assertCount(0, EventCategory::all());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function event_start_date_are_required()
|
||||
{
|
||||
$this->actingAs($user = factory(\App\User::class)->create(), 'api');
|
||||
$response = $this->post('/api/events', array_merge($this->data(), ['start_date' => '']));
|
||||
|
||||
$response->assertSessionHasErrors('start_date');
|
||||
$this->assertCount(0, EventCategory::all());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_event_can_be_retrieved()
|
||||
{
|
||||
$this->actingAs($user = factory(User::class)->create(), 'api');
|
||||
app(\DatabaseSeeder::class)->call(\EventCategorySeeder::class);
|
||||
|
||||
$event = $user->events()->create($this->data());
|
||||
|
||||
$response = $this->get('/api/events/' . $event->id );
|
||||
|
||||
$response->assertJson([
|
||||
'data' => [
|
||||
'type' => 'events',
|
||||
'event_id' => $event->id,
|
||||
'attributes' => [
|
||||
'data' => [
|
||||
'name' => $event->name,
|
||||
'description' => $event->description,
|
||||
'start_date' => $event->start_date,
|
||||
'end_date' => $event->end_date,
|
||||
'location' => $event->location,
|
||||
'category' => [
|
||||
'data' => [
|
||||
'category_id' => 1
|
||||
],
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
private function data()
|
||||
{
|
||||
return [
|
||||
'name' => 'Test name event',
|
||||
'description' => 'Test description event',
|
||||
'category_id' => 1,
|
||||
'start_date' => '2020-07-20 09:00:00',
|
||||
'end_date' => '2020-07-26 09:00:00',
|
||||
'location' => 'Marcillac',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user