Dashboard Controller testing
This commit is contained in:
parent
45bf624bfc
commit
099f36b48c
|
|
@ -32,7 +32,7 @@ class DashboardController extends Controller
|
||||||
public function my_school()
|
public function my_school()
|
||||||
{
|
{
|
||||||
if (Auth::user()->school) {
|
if (Auth::user()->school) {
|
||||||
return redirect('/schools/'.Auth::user()->school->id);
|
return redirect(route('schools.show', auth()->user()->school));
|
||||||
}
|
}
|
||||||
$possibilities = Auth::user()->possibleSchools();
|
$possibilities = Auth::user()->possibleSchools();
|
||||||
if (count($possibilities) < 1) {
|
if (count($possibilities) < 1) {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ use App\Actions\Schools\AddSchoolEmailDomain;
|
||||||
use App\Actions\Schools\AssignUserToSchool;
|
use App\Actions\Schools\AssignUserToSchool;
|
||||||
use App\Actions\Schools\CreateSchool;
|
use App\Actions\Schools\CreateSchool;
|
||||||
use App\Actions\Schools\SetHeadDirector;
|
use App\Actions\Schools\SetHeadDirector;
|
||||||
use App\Exceptions\AuditionAdminException;
|
|
||||||
use App\Http\Requests\SchoolStoreRequest;
|
use App\Http\Requests\SchoolStoreRequest;
|
||||||
use App\Mail\NewUserPassword;
|
use App\Mail\NewUserPassword;
|
||||||
use App\Models\AuditLogEntry;
|
use App\Models\AuditLogEntry;
|
||||||
|
|
@ -129,11 +128,8 @@ class SchoolController extends Controller
|
||||||
if ($school->id !== $user->school_id) {
|
if ($school->id !== $user->school_id) {
|
||||||
abort(403);
|
abort(403);
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
$headSetter->setHeadDirector($user);
|
$headSetter->setHeadDirector($user);
|
||||||
} catch (AuditionAdminException $e) {
|
|
||||||
return redirect()->back()->with('error', $e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return redirect()->route('schools.show', $school)->with('success', 'New head director set');
|
return redirect()->route('schools.show', $school)->with('success', 'New head director set');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,83 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\School;
|
||||||
|
use App\Models\SchoolEmailDomain;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Settings;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class);
|
||||||
|
|
||||||
|
it('returns the profile view for the profile method', function () {
|
||||||
|
actAsNormal();
|
||||||
|
$this->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');
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue