261 lines
12 KiB
PHP
261 lines
12 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use App\Models\Event;
|
|
use App\Models\Student;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->event = Event::factory()->create();
|
|
$this->auditions = Audition::factory()->count(2)->create(['event_id' => $this->event->id]);
|
|
$this->students = Student::factory()->count(2)->create();
|
|
$this->entry1 = Entry::factory()->create([
|
|
'audition_id' => $this->auditions[0]->id, 'student_id' => $this->students[0]->id, 'for_seating' => 1,
|
|
'for_advancement' => 0,
|
|
]);
|
|
$this->entry2 = Entry::factory()->create([
|
|
'audition_id' => $this->auditions[1]->id, 'student_id' => $this->students[1]->id, 'for_seating' => 1,
|
|
'for_advancement' => 1,
|
|
]);
|
|
$this->entry3 = Entry::factory()->create([
|
|
'audition_id' => $this->auditions[0]->id, 'student_id' => $this->students[1]->id, 'for_seating' => 0,
|
|
'for_advancement' => 1,
|
|
]);
|
|
$this->entry4 = Entry::factory()->create([
|
|
'audition_id' => $this->auditions[1]->id, 'student_id' => $this->students[0]->id, 'for_seating' => 1,
|
|
'for_advancement' => 1,
|
|
]);
|
|
$this->entry1->student->update(['grade' => 9]);
|
|
$this->entry2->student->update(['grade' => 10]);
|
|
});
|
|
|
|
describe('EntryController::index', function () {
|
|
it('denies access to non-admins', function () {
|
|
$this->get(route('admin.entries.index'))->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->get(route('admin.entries.index'))->assertRedirect(route('dashboard'));
|
|
actAsTab();
|
|
$this->get(route('admin.entries.index'))->assertRedirect(route('dashboard'));
|
|
});
|
|
it('provides a list of entries', function () {
|
|
actAsAdmin();
|
|
$response = $this->get(route('admin.entries.index'))->assertOk()
|
|
->assertViewIs('admin.entries.index');
|
|
foreach (Entry::all() as $entry) {
|
|
$response->assertSee($entry->student->full_name());
|
|
$response->assertSee($entry->audition->name);
|
|
}
|
|
});
|
|
describe('test filters', function () {
|
|
it('can filter by ID', function () {
|
|
actAsAdmin();
|
|
$response = $this->withSession([
|
|
'adminEntryFilters' => [
|
|
'id' => $this->entry4->id,
|
|
],
|
|
])->get(route('admin.entries.index'))->assertOk();
|
|
saveContentLocally($response->getContent());
|
|
$response->assertSee($this->entry4->student->full_name())
|
|
->assertDontSee($this->entry2->student->full_name());
|
|
});
|
|
it('can filter by first_name', function () {
|
|
actAsAdmin();
|
|
$response = $this->withSession([
|
|
'adminEntryFilters' => [
|
|
'first_name' => $this->entry4->student->first_name,
|
|
],
|
|
])->get(route('admin.entries.index'))->assertOk();
|
|
saveContentLocally($response->getContent());
|
|
$response->assertSee($this->entry4->student->full_name())
|
|
->assertDontSee($this->entry2->student->full_name());
|
|
});
|
|
it('can filter by last_name', function () {
|
|
actAsAdmin();
|
|
$response = $this->withSession([
|
|
'adminEntryFilters' => [
|
|
'last_name' => $this->entry4->student->last_name,
|
|
],
|
|
])->get(route('admin.entries.index'))->assertOk();
|
|
saveContentLocally($response->getContent());
|
|
$response->assertSee($this->entry4->student->full_name())
|
|
->assertDontSee($this->entry2->student->full_name());
|
|
});
|
|
it('can filter by audition', function () {
|
|
actAsAdmin();
|
|
$response = $this->withSession([
|
|
'adminEntryFilters' => [
|
|
'audition' => $this->entry1->audition_id,
|
|
],
|
|
])->get(route('admin.entries.index'))->assertOk();
|
|
saveContentLocally($response->getContent());
|
|
$returnedEntries = $response->viewData('entries');
|
|
expect($returnedEntries->contains('id', $this->entry1->id))->toBeTrue()
|
|
->and($returnedEntries->contains('id', $this->entry2->id))->toBeFalse()
|
|
->and($returnedEntries->contains('id', $this->entry3->id))->toBeTrue()
|
|
->and($returnedEntries->contains('id', $this->entry4->id))->toBeFalse();
|
|
});
|
|
it('can filter by school', function () {
|
|
actAsAdmin();
|
|
$response = $this->withSession([
|
|
'adminEntryFilters' => [
|
|
'school' => $this->entry1->student->school_id,
|
|
],
|
|
])->get(route('admin.entries.index'))->assertOk();
|
|
saveContentLocally($response->getContent());
|
|
$returnedEntries = $response->viewData('entries');
|
|
expect($returnedEntries->contains('id', $this->entry1->id))->toBeTrue()
|
|
->and($returnedEntries->contains('id', $this->entry2->id))->toBeFalse()
|
|
->and($returnedEntries->contains('id', $this->entry3->id))->toBeFalse()
|
|
->and($returnedEntries->contains('id', $this->entry4->id))->toBeTrue();
|
|
});
|
|
it('can filter by grade', function () {
|
|
actAsAdmin();
|
|
$response = $this->withSession([
|
|
'adminEntryFilters' => [
|
|
'grade' => 9,
|
|
],
|
|
])->get(route('admin.entries.index'))->assertOk();
|
|
saveContentLocally($response->getContent());
|
|
$returnedEntries = $response->viewData('entries');
|
|
expect($returnedEntries->contains('id', $this->entry1->id))->toBeTrue()
|
|
->and($returnedEntries->contains('id', $this->entry2->id))->toBeFalse()
|
|
->and($returnedEntries->contains('id', $this->entry3->id))->toBeFalse()
|
|
->and($returnedEntries->contains('id', $this->entry4->id))->toBeTrue();
|
|
});
|
|
it('can show auditions entered in seating', function () {
|
|
actAsAdmin();
|
|
$response = $this->withSession([
|
|
'adminEntryFilters' => [
|
|
'entry_type' => 'seats',
|
|
],
|
|
])->get(route('admin.entries.index'))->assertOk();
|
|
saveContentLocally($response->getContent());
|
|
$returnedEntries = $response->viewData('entries');
|
|
expect($returnedEntries->contains('id', $this->entry1->id))->toBeTrue()
|
|
->and($returnedEntries->contains('id', $this->entry2->id))->toBeTrue()
|
|
->and($returnedEntries->contains('id', $this->entry3->id))->toBeFalse()
|
|
->and($returnedEntries->contains('id', $this->entry4->id))->toBeTrue();
|
|
});
|
|
it('can show auditions entered in advancement', function () {
|
|
actAsAdmin();
|
|
$response = $this->withSession([
|
|
'adminEntryFilters' => [
|
|
'entry_type' => 'advancement',
|
|
],
|
|
])->get(route('admin.entries.index'))->assertOk();
|
|
saveContentLocally($response->getContent());
|
|
$returnedEntries = $response->viewData('entries');
|
|
expect($returnedEntries->contains('id', $this->entry1->id))->toBeFalse()
|
|
->and($returnedEntries->contains('id', $this->entry2->id))->toBeTrue()
|
|
->and($returnedEntries->contains('id', $this->entry3->id))->toBeTrue()
|
|
->and($returnedEntries->contains('id', $this->entry4->id))->toBeTrue();
|
|
});
|
|
it('can show auditions entered only in seating', function () {
|
|
actAsAdmin();
|
|
$response = $this->withSession([
|
|
'adminEntryFilters' => [
|
|
'entry_type' => 'seatsOnly',
|
|
],
|
|
])->get(route('admin.entries.index'))->assertOk();
|
|
saveContentLocally($response->getContent());
|
|
$returnedEntries = $response->viewData('entries');
|
|
expect($returnedEntries->contains('id', $this->entry1->id))->toBeTrue()
|
|
->and($returnedEntries->contains('id', $this->entry2->id))->toBeFalse()
|
|
->and($returnedEntries->contains('id', $this->entry3->id))->toBeFalse()
|
|
->and($returnedEntries->contains('id', $this->entry4->id))->toBeFalse();
|
|
});
|
|
it('can show auditions entered only in advancement', function () {
|
|
actAsAdmin();
|
|
$response = $this->withSession([
|
|
'adminEntryFilters' => [
|
|
'entry_type' => 'advancementOnly',
|
|
],
|
|
])->get(route('admin.entries.index'))->assertOk();
|
|
saveContentLocally($response->getContent());
|
|
$returnedEntries = $response->viewData('entries');
|
|
expect($returnedEntries->contains('id', $this->entry1->id))->toBeFalse()
|
|
->and($returnedEntries->contains('id', $this->entry2->id))->toBeFalse()
|
|
->and($returnedEntries->contains('id', $this->entry3->id))->toBeTrue()
|
|
->and($returnedEntries->contains('id', $this->entry4->id))->toBeFalse();
|
|
});
|
|
it('can limit the number of results per page', function () {
|
|
actAsAdmin();
|
|
$response = $this->withSession([
|
|
'adminEntryFilters' => [
|
|
'entries_per_page' => 1,
|
|
],
|
|
])->get(route('admin.entries.index'))->assertOk();
|
|
$returnedEntries = $response->viewData('entries');
|
|
expect($returnedEntries->count())->toEqual(1);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('EntryController::create', function () {
|
|
it('denies access to non-admins', function () {
|
|
$this->get(route('admin.entries.create'))->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->get(route('admin.entries.create'))->assertRedirect(route('dashboard'));
|
|
actAsTab();
|
|
$this->get(route('admin.entries.create'))->assertRedirect(route('dashboard'));
|
|
});
|
|
it('provides a form to make an entry', function () {
|
|
actAsAdmin();
|
|
$response = $this->get(route('admin.entries.create'));
|
|
$response->assertOk();
|
|
});
|
|
it('provides auditions to the form', function () {
|
|
actAsAdmin();
|
|
$response = $this->get(route('admin.entries.create'));
|
|
$response->assertOk();
|
|
$response->assertViewHas('auditions');
|
|
$returnedAuditions = $response->viewData('auditions');
|
|
foreach (Audition::all() as $audition) {
|
|
expect($returnedAuditions->contains('id', $audition->id))->toBeTrue();
|
|
}
|
|
});
|
|
it('does not provide published auditions to the form', function () {
|
|
actAsAdmin();
|
|
$unavailableAudition[0] = Audition::factory()->create();
|
|
$unavailableAudition[0]->addFlag('seats_published');
|
|
$unavailableAudition[1] = Audition::factory()->create();
|
|
$unavailableAudition[1]->addFlag('advancement_published');
|
|
|
|
$response = $this->get(route('admin.entries.create'));
|
|
$response->assertOk();
|
|
$response->assertViewHas('auditions');
|
|
$returnedAuditions = $response->viewData('auditions');
|
|
foreach ($unavailableAudition as $audition) {
|
|
expect($returnedAuditions->contains('id', $audition->id))->toBeFalse();
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('EntryController::store', function () {
|
|
beforeEach(function () {
|
|
$this->testAudition = Audition::factory()->create();
|
|
$this->testStudent = Student::factory()->create();
|
|
$this->testSubmitData = [
|
|
'student_id' => $this->testStudent->id,
|
|
'audition_id' => $this->testAudition->id,
|
|
'for_seating' => 'on',
|
|
'for_advancement' => 'on',
|
|
'late_fee_waived' => 'on',
|
|
];
|
|
});
|
|
it('denies access to non-admins', function () {
|
|
$this->post(route('admin.entries.store'), $this->testSubmitData)->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->post(route('admin.entries.store'), $this->testSubmitData)->assertRedirect(route('dashboard'));
|
|
actAsTab();
|
|
$this->post(route('admin.entries.store'), $this->testSubmitData)->assertRedirect(route('dashboard'));
|
|
});
|
|
it('creates an entry', function () {
|
|
actAsAdmin();
|
|
$this->post(route('admin.entries.store'), $this->testSubmitData);
|
|
});
|
|
});
|