42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use App\Models\Hunts;
|
|
use App\Enums\HuntStatus;
|
|
use App\Enums\HuntDifficulty;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
test('authenticated user can filter participating hunts', function () {
|
|
$user = User::factory()->create();
|
|
|
|
$hunt = Hunts::create([
|
|
'title' => 'Test Hunt',
|
|
'slug' => 'test-hunt-' . uniqid(),
|
|
'status' => HuntStatus::PUBLISHED,
|
|
'difficulty' => HuntDifficulty::EASY,
|
|
'city' => 'Paris',
|
|
'creator_id' => $user->id,
|
|
'latitude' => 0,
|
|
'longitude' => 0,
|
|
'is_public' => true
|
|
]);
|
|
|
|
// Participate
|
|
$hunt->participants()->attach($user->id, ['status' => 'started', 'current_step_number' => 1]);
|
|
|
|
$response = $this->actingAs($user)->getJson('/api/hunts?participating=true');
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonCount(1, 'data')
|
|
->assertJsonFragment(['id' => $hunt->id]);
|
|
});
|
|
|
|
test('guest receiving empty list when filtering participating hunts', function () {
|
|
$response = $this->getJson('/api/hunts?participating=true');
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonCount(0, 'data');
|
|
});
|