fix event test to specifically set status

This commit is contained in:
2023-04-11 17:10:53 +10:00
parent c79ec065d3
commit fd1522a2ca

View File

@@ -1,4 +1,5 @@
<?php
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Models\User;
@@ -13,6 +14,7 @@ class EventsApiTest extends TestCase
protected $faker;
public function setUp(): void
{
parent::setUp();
@@ -24,11 +26,13 @@ class EventsApiTest extends TestCase
// Create an event
$event = Event::factory()->create([
'publish_at' => Carbon::parse($this->faker->dateTimeBetween('-2 months', '-1 month')),
'status' => 'open',
]);
// Create a future event
$futureEvent = Event::factory()->create([
'publish_at' => Carbon::parse($this->faker->dateTimeBetween('+1 day', '+1 month')),
'status' => 'open',
]);
// Send GET request to the /api/events endpoint
@@ -48,6 +52,39 @@ class EventsApiTest extends TestCase
]);
}
public function testAnyUserCannotSeeDraftEvent()
{
// Create a draft event
$draftEvent = Event::factory()->create([
'publish_at' => Carbon::parse($this->faker->dateTimeBetween('-2 months', '-1 month')),
'status' => 'draft',
]);
// Create a open event
$openEvent = Event::factory()->create([
'publish_at' => Carbon::parse($this->faker->dateTimeBetween('-2 months', '-1 month')),
'status' => 'open',
]);
// Create a closed event
$closedEvent = Event::factory()->create([
'publish_at' => Carbon::parse($this->faker->dateTimeBetween('-2 months', '-1 month')),
'status' => 'closed',
]);
// Send GET request to the /api/events endpoint
$response = $this->getJson('/api/events');
$response->assertStatus(200);
// Assert that the event is in the response data
$response->assertJsonCount(2, 'events');
$response->assertJsonMissing([
'id' => $draftEvent->id,
'title' => $draftEvent->title,
]);
}
public function testAdminCanCreateUpdateDeleteEvent()
{
// Create a user with the admin/events permission
@@ -78,11 +115,11 @@ class EventsApiTest extends TestCase
$response->assertStatus(200);
$response->assertJsonStructure([
'event' => [
'id',
'title',
'content',
'start_at',
'end_at',
'id',
'title',
'content',
'start_at',
'end_at',
]
]);