api/tests/Feature/HuntIndexTest.php

40 lines
974 B
PHP

<?php
use App\Models\Hunts;
use App\Models\HuntSteps;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Scout\EngineManager;
uses(RefreshDatabase::class);
it('lists hunts with total step xp', function () {
config(['scout.driver' => 'collection']);
app(EngineManager::class)->forgetEngines();
$user = User::factory()->create();
$hunt = Hunts::withoutSyncingToSearch(fn () => Hunts::factory()->create([
'title' => 'Treasure hunt',
]));
HuntSteps::factory()->create([
'hunt_id' => $hunt->id,
'xp' => 125,
]);
HuntSteps::factory()->create([
'hunt_id' => $hunt->id,
'xp' => 75,
]);
$response = $this
->actingAs($user, 'sanctum')
->getJson('/api/hunts');
$response
->assertOk()
->assertJsonPath('data.0.id', $hunt->id)
->assertJsonPath('data.0.xp', 200)
->assertJsonMissingPath('data.0.steps_sum_xp');
});