84 lines
3.1 KiB
PHP
84 lines
3.1 KiB
PHP
<?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');
|
|
});
|
|
});
|