From d12f2f233668c1e58a95226a00bb4aa5d666736f Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sun, 30 Jun 2024 22:59:33 -0500 Subject: [PATCH] Updating --- app/Providers/InvoiceDataServiceProvider.php | 16 +++++++----- database/factories/UserFactory.php | 20 ++++++++++++++- tests/Feature/PagesResponseTest.php | 27 ++++++++++++++++++-- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/app/Providers/InvoiceDataServiceProvider.php b/app/Providers/InvoiceDataServiceProvider.php index 6556ed4..439181f 100644 --- a/app/Providers/InvoiceDataServiceProvider.php +++ b/app/Providers/InvoiceDataServiceProvider.php @@ -27,12 +27,14 @@ class InvoiceDataServiceProvider extends ServiceProvider */ public function boot(): void { - $this->app->singleton(InvoiceDataService::class, function ($app) { - return match (auditionSetting('fee_structure')) { - 'oneFeePerEntry' => new InvoiceOneFeePerEntry($app->make(EntryService::class)), - 'oneFeePerStudent' => new InvoiceOneFeePerStudent($app->make(EntryService::class)), - default => throw new \Exception('Unknown Invoice Method'), - }; - }); + if (auditionSetting('fee_structure')) { + $this->app->singleton(InvoiceDataService::class, function ($app) { + return match (auditionSetting('fee_structure')) { + 'oneFeePerEntry' => new InvoiceOneFeePerEntry($app->make(EntryService::class)), + 'oneFeePerStudent' => new InvoiceOneFeePerStudent($app->make(EntryService::class)), + default => throw new \Exception('Unknown Invoice Method'), + }; + }); + } } } diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 5c234c8..c4971cc 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -23,7 +23,11 @@ class UserFactory extends Factory */ public function definition(): array { - $judingPrefPossibilities = ['woodwinds','flute','clarinet','saxophones', 'low clarinets','oboe','bassoon','double reeds','brass','low brass','trumpet','trombone','horn','tuba','euphonium','percussion']; + $judingPrefPossibilities = [ + 'woodwinds', 'flute', 'clarinet', 'saxophones', 'low clarinets', 'oboe', 'bassoon', 'double reeds', 'brass', + 'low brass', 'trumpet', 'trombone', 'horn', 'tuba', 'euphonium', 'percussion', + ]; + return [ 'first_name' => fake()->firstName(), 'last_name' => fake()->lastName(), @@ -46,4 +50,18 @@ class UserFactory extends Factory 'email_verified_at' => null, ]); } + + public function admin(): static + { + return $this->state(fn (array $attributes) => [ + 'is_admin' => 1, + ]); + } + + public function tab(): static + { + return $this->state(fn (array $attributes) => [ + 'is_tab' => 1, + ]); + } } diff --git a/tests/Feature/PagesResponseTest.php b/tests/Feature/PagesResponseTest.php index 6b037a1..2679461 100644 --- a/tests/Feature/PagesResponseTest.php +++ b/tests/Feature/PagesResponseTest.php @@ -1,5 +1,6 @@ assertStatus(200) @@ -24,13 +25,35 @@ it('shows a registration page', function () { 'Registration Code', 'Email address', ]); + $user = User::factory()->create(); + $this->actingAs($user); + get('/register') + ->assertStatus(302) + ->assertRedirect(route('dashboard')); }); -it('shows a login page', function () { +it('shows a login page only if not logged in', function () { get('/login') ->assertStatus(200) ->assertSeeText([ 'Log In', 'Click here to register', ]); + $user = User::factory()->create(); + $this->actingAs($user); + get('/register') + ->assertStatus(302) + ->assertRedirect(route('dashboard')); +}); + +it('shows dashboard only if logged in', function () { + get(route('dashboard')) + ->assertStatus(302) + ->assertRedirect(route('home')); + $user = User::factory()->create(); + $this->actingAs($user); + get(route('dashboard')) + ->assertStatus(200) + ->assertSeeText('My School') + ->assertSeeText('Dashboard'); });