diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 8ece8e6..8128cba 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -32,7 +32,7 @@ class DashboardController extends Controller public function my_school() { if (Auth::user()->school) { - return redirect('/schools/'.Auth::user()->school->id); + return redirect(route('schools.show', auth()->user()->school)); } $possibilities = Auth::user()->possibleSchools(); if (count($possibilities) < 1) { diff --git a/app/Http/Controllers/SchoolController.php b/app/Http/Controllers/SchoolController.php index 83524de..42e227d 100644 --- a/app/Http/Controllers/SchoolController.php +++ b/app/Http/Controllers/SchoolController.php @@ -7,7 +7,6 @@ use App\Actions\Schools\AddSchoolEmailDomain; use App\Actions\Schools\AssignUserToSchool; use App\Actions\Schools\CreateSchool; use App\Actions\Schools\SetHeadDirector; -use App\Exceptions\AuditionAdminException; use App\Http\Requests\SchoolStoreRequest; use App\Mail\NewUserPassword; use App\Models\AuditLogEntry; @@ -129,11 +128,8 @@ class SchoolController extends Controller if ($school->id !== $user->school_id) { abort(403); } - try { - $headSetter->setHeadDirector($user); - } catch (AuditionAdminException $e) { - return redirect()->back()->with('error', $e->getMessage()); - } + + $headSetter->setHeadDirector($user); return redirect()->route('schools.show', $school)->with('success', 'New head director set'); } diff --git a/tests/Feature/app/Http/Controllers/DashboardControllerTest.php b/tests/Feature/app/Http/Controllers/DashboardControllerTest.php new file mode 100644 index 0000000..9d935ac --- /dev/null +++ b/tests/Feature/app/Http/Controllers/DashboardControllerTest.php @@ -0,0 +1,83 @@ +get(route('my_profile'))->assertViewIs('dashboard.profile'); +}); + +it('redirects guests away from the profile view', function () { + $this->get(route('my_profile'))->assertRedirect(route('home')); +}); + +it('returns the dashboard view for the dashboard method', function () { + actAsNormal(); + $this->get(route('dashboard'))->assertViewIs('dashboard.dashboard'); +}); + +it('redirects guests away from the dashboard view', function () { + $this->get(route('my_profile'))->assertRedirect(route('home')); +}); + +describe('my_school method and route', function () { + it('redirects to school show view for users with schools', function () { + $school = School::factory()->create(); + $user = User::factory()->forSchool($school)->create(); + $this->actingAs($user); + $this->get(route('my_school'))->assertRedirect(route('schools.show', $school)); + }); + + it('shows the school create page if there are no viable schools', function () { + $user = User::factory()->create(); + $this->actingAs($user); + $this->get(route('my_school'))->assertViewIs('schools.create'); + }); + + it('allows the user to choose a school that they share an email domain with', function () { + $user = User::factory()->create(['email' => 'picard@starfleet.com']); + $school = School::factory()->create(); + $school2 = School::factory()->create(); + SchoolEmailDomain::create([ + 'domain' => 'starfleet.com', + 'school_id' => $school->id, + ]); + $this->actingAs($user); + $response = $this->get(route('my_school')); + $response->assertViewIs('dashboard.select_school') + ->assertViewHas('schools') + ->assertViewHas('possibilities'); + + expect($response->viewData('possibilities')->count())->toEqual(1) + ->and($response->viewData('schools')->count())->toEqual(2) + ->and($response->viewData('possibilities')[0]->id)->toEqual($school->id); + }); +}); + +describe('my_invoice', function () { + it('redirects if the user has no shoolders', function () { + $user = User::factory()->create(); + $this->actingAs($user); + $this->get(route('my_invoice'))->assertRedirect(route('dashboard')); + }); + it('redirects if invoicing is not enabled', function () { + Settings::set('invoicing_enabled', false); + $school = School::factory()->create(); + $user = User::factory()->forSchool($school)->create(); + $this->actingAs($user); + $this->get(route('my_invoice'))->assertRedirect(route('dashboard')); + Settings::set('invoicing_enabled', true); + }); + it('returns the invoice view', function () { + $school = School::factory()->create(); + $user = User::factory()->forSchool($school)->create(); + $this->actingAs($user); + $this->get(route('my_invoice'))->assertViewIs('dashboard.invoice'); + }); +});