start Events test

This commit is contained in:
2020-07-19 16:28:28 +02:00
parent ee81ee6216
commit 01d4fd4a4f
3 changed files with 72 additions and 15 deletions

View File

@@ -3,7 +3,6 @@
namespace App\Http\Controllers;
use App\Http\Requests\EventCategoryRequest;
use App\Http\Resources\CustomerCatchmentArea;
use App\Http\Resources\EventCategory as EventCategoryResource;
use App\Models\EventCategory;
use Illuminate\Http\Request;
@@ -76,7 +75,7 @@ class EventCategoryController extends Controller
*/
public function destroy(EventCategory $category)
{
if(auth()->user()->role === 2) {
if(auth()->user()->isAdmin()) {
$category->delete();
return response()->json([], 204);
} else {

View File

@@ -33,7 +33,7 @@ class EventController extends Controller
* Store a newly created resource in storage.
*
* @param EventRequest $request
* @return void
* @return \Illuminate\Http\JsonResponse
*/
public function store(EventRequest $request)
{
@@ -51,11 +51,13 @@ class EventController extends Controller
* Display the specified resource.
*
* @param \App\Models\Event $event
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function show(Event $event)
{
//
return (new EventResource($event))
->response()
->setStatusCode(200);
}
/**

View File

@@ -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',
];
}
}