festbench-web/tests/Feature/HomeSnapshotTest.php

43 lines
1.8 KiB
PHP

<?php
use App\Models\BenchmarkRun;
use App\Models\SoftbenchResult;
use App\Models\User;
use Illuminate\Support\Facades\Artisan;
test('festbench:snapshot rebuilds the flat home view', function () {
$run = BenchmarkRun::factory()->create(['suite' => 'softbench', 'model_id' => 'snap/model', 'visibility' => 'public']);
SoftbenchResult::factory()->create(['benchmark_run_id' => $run->id, 'task' => 'snap-task']);
BenchmarkRun::factory()->private()->create(['suite' => 'softbench']);
Artisan::call('festbench:snapshot');
$rows = DB::table('home_snapshot')->get();
expect($rows)->toHaveCount(1)
->and($rows[0]->task)->toBe('snap-task')
->and($rows[0]->model_id)->toBe('snap/model')
->and($rows[0]->run_id)->toBe($run->run_id);
});
test('guest default results view reads the snapshot, no union needed', function () {
$run = BenchmarkRun::factory()->create(['suite' => 'softbench', 'visibility' => 'public']);
SoftbenchResult::factory()->create(['benchmark_run_id' => $run->id, 'task' => 'snapshotted-task']);
Artisan::call('festbench:snapshot');
// The snapshot is the only path that knows this task name; seeing it
// proves the default view served from home_snapshot.
$this->get(route('results'))->assertOk()->assertSee('snapshotted-task');
});
test('guest pages get public cache headers, authenticated pages do not', function () {
$guest = $this->get(route('results'));
expect($guest->headers->get('Cache-Control'))->toContain('public')
->and($guest->headers->get('Cache-Control'))->toContain('s-maxage');
$this->actingAs(User::factory()->create());
$auth = $this->get(route('results'));
expect($auth->headers->get('Cache-Control'))->toContain('private')
->and($auth->headers->get('Cache-Control'))->not->toContain('public');
});