diff --git a/app/Enums/AuditionFlags.php b/app/Enums/AuditionFlags.php new file mode 100644 index 0000000..fa156a1 --- /dev/null +++ b/app/Enums/AuditionFlags.php @@ -0,0 +1,10 @@ +with('error', 'Cannot enter a no-show for an entry in an audition where seats are published'); } - if ($entry->audition->hasFlag('advance_published')) { + if ($entry->audition->hasFlag('advancement_published')) { return to_route('entry-flags.noShowSelect')->with('error', 'Cannot enter a no-show for an entry in an audition where advancement is published'); } @@ -71,7 +71,7 @@ class EntryFlagController extends Controller return to_route('entry-flags.noShowSelect')->with('error', 'Cannot enter a no-show for an entry in an audition where seats are published'); } - if ($entry->audition->hasFlag('advance_published')) { + if ($entry->audition->hasFlag('advancement_published')) { return to_route('entry-flags.noShowSelect')->with('error', 'Cannot enter a no-show for an entry in an audition where advancement is published'); } @@ -90,7 +90,7 @@ class EntryFlagController extends Controller return to_route('entry-flags.noShowSelect')->with('error', 'Cannot undo a no-show for an entry in an audition where seats are published'); } - if ($entry->audition->hasFlag('advance_published')) { + if ($entry->audition->hasFlag('advancement_published')) { return to_route('entry-flags.noShowSelect')->with('error', 'Cannot undo a no-show for an entry in an audition where advancement is published'); } diff --git a/app/Http/Controllers/Tabulation/ScoreController.php b/app/Http/Controllers/Tabulation/ScoreController.php index 5f2fe69..217801a 100644 --- a/app/Http/Controllers/Tabulation/ScoreController.php +++ b/app/Http/Controllers/Tabulation/ScoreController.php @@ -4,9 +4,9 @@ namespace App\Http\Controllers\Tabulation; use App\Http\Controllers\Controller; use App\Models\Entry; -use App\Models\ScoreSheet; use Illuminate\Http\Request; use Illuminate\Support\Facades\Session; +use Tests\Feature\Models\ScoreSheet; class ScoreController extends Controller { diff --git a/app/Models/Audition.php b/app/Models/Audition.php index d33b721..658fec1 100644 --- a/app/Models/Audition.php +++ b/app/Models/Audition.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Enums\AuditionFlags; use Carbon\Carbon; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -10,6 +11,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; +use function in_array; + class Audition extends Model { use HasFactory; @@ -75,8 +78,13 @@ class Audition extends Model public function hasFlag($flag): bool { + $flags = []; + foreach ($this->flags as $checkFlag) { + $flags[] = $checkFlag->flag_name->value; + } + // return true if any flag in $this->flags has a flag_name of declined without making another db query if flags are loaded - return $this->flags->contains('flag_name', $flag); + return in_array($flag, $flags); } public function addFlag($flag): void @@ -84,8 +92,12 @@ class Audition extends Model if ($this->hasFlag($flag)) { return; } - - $this->flags()->create(['flag_name' => $flag]); + $enum = match ($flag) { + 'drawn' => AuditionFlags::DRAWN, + 'seats_published' => AuditionFlags::SEATS_PUBLISHED, + 'advancement_published' => AuditionFlags::ADVANCEMENT_PUBLISHED, + }; + $this->flags()->create(['flag_name' => $enum]); $this->load('flags'); } diff --git a/app/Models/AuditionFlag.php b/app/Models/AuditionFlag.php index 7b11fba..26429a6 100644 --- a/app/Models/AuditionFlag.php +++ b/app/Models/AuditionFlag.php @@ -2,7 +2,7 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; +use App\Enums\AuditionFlags; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -10,6 +10,10 @@ class AuditionFlag extends Model { protected $guarded = []; + protected $casts = [ + 'flag_name' => AuditionFlags::class, + ]; + public function audition(): BelongsTo { return $this->belongsTo(Audition::class); diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 9b08f7e..0a4c608 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasOneThrough; +use Tests\Feature\Models\ScoreSheet; class Entry extends Model { diff --git a/app/Models/User.php b/app/Models/User.php index 361da51..c3ec38b 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Collection; +use Tests\Feature\Models\ScoreSheet; class User extends Authenticatable implements MustVerifyEmail { diff --git a/app/Observers/ScoreSheetObserver.php b/app/Observers/ScoreSheetObserver.php index 533763e..3b31bc2 100644 --- a/app/Observers/ScoreSheetObserver.php +++ b/app/Observers/ScoreSheetObserver.php @@ -3,7 +3,7 @@ namespace App\Observers; use App\Events\ScoreSheetChange; -use App\Models\ScoreSheet; +use Tests\Feature\Models\ScoreSheet; class ScoreSheetObserver { diff --git a/app/Policies/ScoreSheetPolicy.php b/app/Policies/ScoreSheetPolicy.php index c83ebdd..2a897b8 100644 --- a/app/Policies/ScoreSheetPolicy.php +++ b/app/Policies/ScoreSheetPolicy.php @@ -3,9 +3,8 @@ namespace App\Policies; use App\Models\Entry; -use App\Models\ScoreSheet; use App\Models\User; -use Illuminate\Auth\Access\Response; +use Tests\Feature\Models\ScoreSheet; class ScoreSheetPolicy { diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6d1eea9..62097a7 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -17,7 +17,6 @@ use App\Models\Entry; use App\Models\Room; use App\Models\RoomUser; use App\Models\School; -use App\Models\ScoreSheet; use App\Models\ScoringGuide; use App\Models\SeatingLimit; use App\Models\Student; @@ -43,6 +42,7 @@ use App\Services\SeatingService; use App\Services\TabulationService; use Illuminate\Support\Facades\Event; use Illuminate\Support\ServiceProvider; +use Tests\Feature\Models\ScoreSheet; class AppServiceProvider extends ServiceProvider diff --git a/app/Services/ScoreService.php b/app/Services/ScoreService.php index c7db47c..106a477 100644 --- a/app/Services/ScoreService.php +++ b/app/Services/ScoreService.php @@ -3,12 +3,11 @@ namespace App\Services; use App\Models\Entry; -use App\Models\ScoreSheet; use App\Models\ScoringGuide; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; - +use Tests\Feature\Models\ScoreSheet; use function array_unshift; class ScoreService diff --git a/database/seeders/ScoreAllAuditions.php b/database/seeders/ScoreAllAuditions.php index 9a9f569..35e10b5 100644 --- a/database/seeders/ScoreAllAuditions.php +++ b/database/seeders/ScoreAllAuditions.php @@ -2,9 +2,9 @@ namespace Database\Seeders; -use App\Models\ScoreSheet; use App\Models\User; use Illuminate\Database\Seeder; +use Tests\Feature\Models\ScoreSheet; class ScoreAllAuditions extends Seeder { diff --git a/resources/views/components/layout/navbar/menus/tabulation.blade.php b/resources/views/components/layout/navbar/menus/tabulation.blade.php index 10617d7..48e8507 100644 --- a/resources/views/components/layout/navbar/menus/tabulation.blade.php +++ b/resources/views/components/layout/navbar/menus/tabulation.blade.php @@ -21,6 +21,7 @@
Enter Scores + Enter No-Shows Audition Status {{ auditionSetting('advanceTo') }} Status diff --git a/resources/views/test.blade.php b/resources/views/test.blade.php index 2140a66..44f7d68 100644 --- a/resources/views/test.blade.php +++ b/resources/views/test.blade.php @@ -1,14 +1,5 @@ -@php use App\Models\Audition; - use App\Models\Entry; - use App\Models\School; - use App\Models\SchoolEmailDomain; - use App\Models\ScoreSheet; - use App\Models\ScoringGuide; - use App\Models\User;use App\Services\ScoreService;use App\Settings; - use Illuminate\Support\Facades\Auth; - use Illuminate\Support\Facades\DB; - use Illuminate\Support\Facades\Session; -@endphp +@php use App\Enums\AuditionFlags;use App\Models\Audition;use App\Models\AuditionFlag; @endphp +@php @endphp @inject('scoreservice','App\Services\ScoreService'); @inject('auditionService','App\Services\AuditionService'); @inject('entryService','App\Services\EntryService') @@ -17,7 +8,8 @@ Test Page @php - $drawService->hello(); + $audition = Audition::first(); + $audition->addFlag('drawn'); @endphp diff --git a/tests/Feature/Models/AuditionFlagTest.php b/tests/Feature/Models/AuditionFlagTest.php index 67d2d35..2a5c0ac 100644 --- a/tests/Feature/Models/AuditionFlagTest.php +++ b/tests/Feature/Models/AuditionFlagTest.php @@ -1,5 +1,6 @@ $audition->id, - 'flag_name' => 'Test Flag', + 'flag_name' => AuditionFlags::DRAWN, ]); // Act and Assert diff --git a/tests/Feature/Models/AuditionTest.php b/tests/Feature/Models/AuditionTest.php index 7c54eda..52ee4c4 100644 --- a/tests/Feature/Models/AuditionTest.php +++ b/tests/Feature/Models/AuditionTest.php @@ -1,5 +1,6 @@ create(); - AuditionFlag::create(['audition_id' => $audition->id, 'flag_name' => 'seats_published']); - AuditionFlag::create(['audition_id' => $audition->id, 'flag_name' => 'advance_published']); + AuditionFlag::create(['audition_id' => $audition->id, 'flag_name' => AuditionFlags::SEATS_PUBLISHED]); + AuditionFlag::create(['audition_id' => $audition->id, 'flag_name' => AuditionFlags::ADVANCEMENT_PUBLISHED]); // Act // Assert - expect($audition->hasFlag('seats_published'))->toBeTrue(); - expect($audition->hasFlag('notaflag'))->toBeFalse(); - expect($audition->flags->count())->toEqual(2); + expect($audition->hasFlag('seats_published'))->toBeTrue() + ->and($audition->hasFlag('notaflag'))->toBeFalse() + ->and($audition->flags->count())->toEqual(2); }); it('can add flags', function () { diff --git a/tests/Feature/Models/EntryTest.php b/tests/Feature/Models/EntryTest.php index f0ba254..233e6af 100644 --- a/tests/Feature/Models/EntryTest.php +++ b/tests/Feature/Models/EntryTest.php @@ -6,11 +6,11 @@ use App\Models\Entry; use App\Models\EntryFlag; use App\Models\JudgeAdvancementVote; use App\Models\School; -use App\Models\ScoreSheet; use App\Models\Seat; use App\Models\Student; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; +use Tests\Feature\Models\ScoreSheet; uses(RefreshDatabase::class); diff --git a/app/Models/ScoreSheet.php b/tests/Feature/Models/ScoreSheet.php similarity index 92% rename from app/Models/ScoreSheet.php rename to tests/Feature/Models/ScoreSheet.php index 7b7c337..1a1bb52 100644 --- a/app/Models/ScoreSheet.php +++ b/tests/Feature/Models/ScoreSheet.php @@ -1,7 +1,10 @@ create(); + $advancePublishedAudition = Audition::factory()->create(); + $seatsPublishedAudition->addFlag('seats_published'); + $advancePublishedAudition->addFlag('advancement_published'); + // Act & Assert + +}); diff --git a/tests/Feature/Pages/Tabulation/noShowConfirmTest.php b/tests/Feature/Pages/Tabulation/noShowConfirmTest.php index 011f22f..1a7c340 100644 --- a/tests/Feature/Pages/Tabulation/noShowConfirmTest.php +++ b/tests/Feature/Pages/Tabulation/noShowConfirmTest.php @@ -33,7 +33,7 @@ it('will not work with an entry if it is in a published audition', function () { $entry1 = Entry::factory()->create(); $entry2 = Entry::factory()->create(); $entry1->audition->addFlag('seats_published'); - $entry2->audition->addFlag('advance_published'); + $entry2->audition->addFlag('advancement_published'); actAsTab(); get(route('entry-flags.confirmNoShow', ['entry_id' => $entry1->id])) ->assertRedirect(route('entry-flags.noShowSelect')) diff --git a/tests/Feature/Pages/Tabulation/noShowEnterTest.php b/tests/Feature/Pages/Tabulation/noShowEnterTest.php index fd16205..47850f8 100644 --- a/tests/Feature/Pages/Tabulation/noShowEnterTest.php +++ b/tests/Feature/Pages/Tabulation/noShowEnterTest.php @@ -31,7 +31,7 @@ it('will not record an entry in a published audition as a no show', function () $entry1 = Entry::factory()->create(); $entry2 = Entry::factory()->create(); $entry1->audition->addFlag('seats_published'); - $entry2->audition->addFlag('advance_published'); + $entry2->audition->addFlag('advancement_published'); actAsAdmin(); post(route('entry-flags.enterNoShow', $entry1)) ->assertRedirect(route('entry-flags.noShowSelect')) diff --git a/tests/Feature/Pages/Tabulation/noShowUndoTest.php b/tests/Feature/Pages/Tabulation/noShowUndoTest.php index cd5723c..8f0b975 100644 --- a/tests/Feature/Pages/Tabulation/noShowUndoTest.php +++ b/tests/Feature/Pages/Tabulation/noShowUndoTest.php @@ -33,7 +33,7 @@ it('will not undo a no-show flag for an entry in a published audition', function $entry1->addFlag('no_show'); $entry2->addFlag('no_show'); $entry1->audition->addFlag('seats_published'); - $entry2->audition->addFlag('advance_published'); + $entry2->audition->addFlag('advancement_published'); actAsAdmin(); delete(route('entry-flags.undoNoShow', $entry1)) ->assertRedirect(route('entry-flags.noShowSelect'))