creator = app(CreateSchool::class); }); it('creates a school', function () { $newSchool = ($this->creator)( 'Longfellow Intermediate', '210 East 4th Stret', 'Chelsea', 'OK', '74016', ); $dbSchool = School::first(); expect(School::where('name', 'Longfellow Intermediate')->exists())->toBeTrue() ->and($dbSchool->name)->toEqual('Longfellow Intermediate') ->and($dbSchool->address)->toEqual('210 East 4th Stret') ->and($dbSchool->city)->toEqual('Chelsea') ->and($dbSchool->state)->toEqual('OK') ->and($dbSchool->zip)->toEqual('74016'); }); it('logs school creation', function () { actAsAdmin(); $schoolAddress = fake()->streetAddress(); $schoolCity = fake()->city(); $schoolState = 'OK'; $schoolZip = fake()->postcode(); $schoolName = $schoolCity.' High School'; $this->creator->create( $schoolName, $schoolAddress, $schoolCity, $schoolState, $schoolZip, ); $logEntry = \App\Models\AuditLogEntry::first(); expect($logEntry->message)->toEqual('Created school '.$schoolName) ->and($logEntry->affected['schools'])->toEqual([1]) ->and($logEntry->user)->toEqual(auth()->user()->email); }); it('will not create a school with a duplicate name', function () { $schoolName = 'Longfellow Intermediate'; $this->creator->create( $schoolName ); $this->creator->create( $schoolName ); })->throws(AuditionAdminException::class, 'The school Longfellow Intermediate already exists');