auditionadmin/tests/Feature/app/Http/Controllers/ResultsPageTest.php

89 lines
2.8 KiB
PHP

<?php
use App\Models\Ensemble;
use App\Models\Entry;
use App\Models\Seat;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Cache;
uses(RefreshDatabase::class);
beforeEach(function () {
Cache::flush();
});
it('includes seated entries for published auditions', function () {
$entry = Entry::factory()->create();
$ensemble = Ensemble::factory()->create(['event_id' => $entry->audition->event_id]);
Seat::create([
'ensemble_id' => $ensemble->id,
'audition_id' => $entry->audition_id,
'seat' => 5,
'entry_id' => $entry->id,
]);
$entry->audition->addFlag('seats_published');
$response = $this->get(route('results'));
$response->assertSee($entry->student->full_name());
});
it('does not show results that are not published', function () {
$entry = Entry::factory()->create();
$ensemble = Ensemble::factory()->create(['event_id' => $entry->audition->event_id]);
Seat::create([
'ensemble_id' => $ensemble->id,
'audition_id' => $entry->audition_id,
'seat' => 5,
'entry_id' => $entry->id,
]);
$response = $this->get(route('results'));
$response->assertDontSee($entry->student->full_name());
});
it('does not show an audition with no seats', function () {
$entry = Entry::factory()->create();
$ensemble = Ensemble::factory()->create(['event_id' => $entry->audition->event_id]);
$entry->audition->addFlag('seats_published');
$response = $this->get(route('results'));
$response->assertDontSee($ensemble->name);
});
it('shows advancement results that are published', function () {
$entry = Entry::factory()->create();
$entry->addFlag('will_advance');
$entry->audition->addFlag('advancement_published');
$response = $this->get(route('results'));
$response->assertSee($entry->student->full_name());
});
describe('test caching', function () {
test('results are served from cache when available', function () {
Cache::forever('publicResultsPage', 'test');
$response = $this->get(route('results'));
expect($response->getContent())->toBe('test');
});
test('results are generated and cached when not in cache', function () {
expect(Cache::has('publicResultsPage'))->toBeFalse();
$response = $this->get(route('results'));
$response->assertOk();
expect(Cache::has('publicResultsPage'))->toBeTrue();
});
test('cached and fresh results match', function () {
// Clear cache
Cache::forget('publicResultsPage');
// Get fresh content
$freshContent = $this->get(route('results'))->getContent();
// Get cached content
$cachedContent = $this->get(route('results'))->getContent();
expect($cachedContent)->toBe($freshContent);
});
});