Add scopes to models #10

Merged
okorpheus merged 5 commits from add-scopes-to-models into master 2024-07-01 04:00:24 +00:00
3 changed files with 53 additions and 10 deletions
Showing only changes of commit d12f2f2336 - Show all commits

View File

@ -27,12 +27,14 @@ class InvoiceDataServiceProvider extends ServiceProvider
*/ */
public function boot(): void public function boot(): void
{ {
$this->app->singleton(InvoiceDataService::class, function ($app) { if (auditionSetting('fee_structure')) {
return match (auditionSetting('fee_structure')) { $this->app->singleton(InvoiceDataService::class, function ($app) {
'oneFeePerEntry' => new InvoiceOneFeePerEntry($app->make(EntryService::class)), return match (auditionSetting('fee_structure')) {
'oneFeePerStudent' => new InvoiceOneFeePerStudent($app->make(EntryService::class)), 'oneFeePerEntry' => new InvoiceOneFeePerEntry($app->make(EntryService::class)),
default => throw new \Exception('Unknown Invoice Method'), 'oneFeePerStudent' => new InvoiceOneFeePerStudent($app->make(EntryService::class)),
}; default => throw new \Exception('Unknown Invoice Method'),
}); };
});
}
} }
} }

View File

@ -23,7 +23,11 @@ class UserFactory extends Factory
*/ */
public function definition(): array 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 [ return [
'first_name' => fake()->firstName(), 'first_name' => fake()->firstName(),
'last_name' => fake()->lastName(), 'last_name' => fake()->lastName(),
@ -46,4 +50,18 @@ class UserFactory extends Factory
'email_verified_at' => null, '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,
]);
}
} }

View File

@ -1,5 +1,6 @@
<?php <?php
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use function Pest\Laravel\get; use function Pest\Laravel\get;
@ -16,7 +17,7 @@ it('shows appropriate screens when not logged in', function () {
]); ]);
}); });
it('shows a registration page', function () { it('shows a registration page only if not logged in', function () {
// Act & Assert // Act & Assert
get('/register') get('/register')
->assertStatus(200) ->assertStatus(200)
@ -24,13 +25,35 @@ it('shows a registration page', function () {
'Registration Code', 'Registration Code',
'Email address', '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') get('/login')
->assertStatus(200) ->assertStatus(200)
->assertSeeText([ ->assertSeeText([
'Log In', 'Log In',
'Click here to register', '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');
}); });