Write tests - Write tests for what was done to this point that will be kept #11

Merged
okorpheus merged 61 commits from write-tests into master 2024-07-05 21:21:32 +00:00
4 changed files with 11 additions and 10 deletions
Showing only changes of commit 75ce5043c2 - Show all commits

View File

@ -6,7 +6,6 @@ use App\Http\Controllers\Controller;
use App\Models\School; use App\Models\School;
use App\Models\SchoolEmailDomain; use App\Models\SchoolEmailDomain;
use App\Services\Invoice\InvoiceDataService; use App\Services\Invoice\InvoiceDataService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use function abort; use function abort;
@ -15,7 +14,7 @@ use function request;
class SchoolController extends Controller class SchoolController extends Controller
{ {
protected $invoiceService; protected InvoiceDataService $invoiceService;
public function __construct(InvoiceDataService $invoiceController) public function __construct(InvoiceDataService $invoiceController)
{ {
@ -36,7 +35,7 @@ class SchoolController extends Controller
return view('admin.schools.index', compact('schools', 'schoolTotalFees')); return view('admin.schools.index', compact('schools', 'schoolTotalFees'));
} }
public function show(Request $request, School $school) public function show(School $school)
{ {
if (! Auth::user()->is_admin) { if (! Auth::user()->is_admin) {
abort(403); abort(403);
@ -84,7 +83,7 @@ class SchoolController extends Controller
return view('admin.schools.create'); return view('admin.schools.create');
} }
public function store(Request $request) public function store()
{ {
request()->validate([ request()->validate([
'name' => ['required'], 'name' => ['required'],
@ -105,7 +104,7 @@ class SchoolController extends Controller
return redirect('/admin/schools')->with('success', 'School '.$school->name.' created'); return redirect('/admin/schools')->with('success', 'School '.$school->name.' created');
} }
public function add_domain(Request $request, School $school) public function add_domain(School $school)
{ {
if (! Auth::user()->is_admin) { if (! Auth::user()->is_admin) {
abort(403); abort(403);
@ -116,13 +115,13 @@ class SchoolController extends Controller
]); ]);
SchoolEmailDomain::updateOrInsert([ SchoolEmailDomain::updateOrInsert([
'school_id' => $school->id, 'school_id' => $school->id,
'domain' => request('domain')], []); 'domain' => request('domain')]);
return redirect()->route('admin.schools.show', $school)->with('success', 'Domain Added'); return redirect()->route('admin.schools.show', $school)->with('success', 'Domain Added');
} }
public function destroy_domain(Request $request, SchoolEmailDomain $domain) public function destroy_domain(SchoolEmailDomain $domain)
{ {
// Destroy the $domain // Destroy the $domain
$domain->delete(); $domain->delete();
@ -131,7 +130,7 @@ class SchoolController extends Controller
return redirect()->back(); return redirect()->back();
} }
public function viewInvoice(Request $request, School $school) public function viewInvoice(School $school)
{ {
$invoiceData = $this->invoiceService->allData($school->id); $invoiceData = $this->invoiceService->allData($school->id);

View File

@ -42,7 +42,7 @@ class AuditionFactory extends Factory
return [ return [
'event_id' => $event->id, 'event_id' => $event->id,
#'name' => $this->faker->randomElement($instruments).$this->faker->numberBetween(1, 1000), #'name' => $this->faker->randomElement($instruments).$this->faker->numberBetween(1, 1000),
'name' => 'New Instrument ' . $this->faker->sentence(5), 'name' => 'New Instrument ' . $this->faker->unique()->sentence(5),
'score_order' => $this->faker->numberBetween(2, 50), 'score_order' => $this->faker->numberBetween(2, 50),
'entry_deadline' => Carbon::tomorrow(), 'entry_deadline' => Carbon::tomorrow(),
'entry_fee' => 1000, 'entry_fee' => 1000,

View File

@ -17,7 +17,7 @@ class EventFactory extends Factory
public function definition(): array public function definition(): array
{ {
return [ return [
'name' => $this->faker->name(), 'name' => $this->faker->unique()->name(),
]; ];
} }
} }

View File

@ -141,6 +141,7 @@ it('accepts a valid entry', function () {
'student_id' => $student->id, 'student_id' => $student->id,
'audition_id' => $audition->id, 'audition_id' => $audition->id,
]); ]);
/** @noinspection PhpUnhandledExceptionInspection */
$response->assertSessionHasNoErrors(); $response->assertSessionHasNoErrors();
$response->assertRedirect(route('entries.index')); $response->assertRedirect(route('entries.index'));
$this->assertDatabaseHas('entries', [ $this->assertDatabaseHas('entries', [
@ -157,6 +158,7 @@ it('deletes an entry', function () {
// Act // Act
actingAs($this->user); actingAs($this->user);
$response = delete(route('entries.destroy', $entry)); $response = delete(route('entries.destroy', $entry));
/** @noinspection PhpUnhandledExceptionInspection */
$response $response
->assertSessionHasNoErrors() ->assertSessionHasNoErrors()
->assertRedirect(route('entries.index')); ->assertRedirect(route('entries.index'));