assigner = app(AssignUserToSchool::class); $this->user = User::factory()->create(); $this->school = School::factory()->create(); }); it('throws an exception if the user does not exist', function () { $newUser = User::factory()->make(); $this->assigner->assign($newUser, $this->school); })->throws(AuditionAdminException::class, 'User does not exist'); it('throws an exception if the school does not exist', function () { $newSchool = School::factory()->make(); $this->assigner->assign($this->user, $newSchool); })->throws(AuditionAdminException::class, 'School does not exist'); it('assigns a user to a school', function () { ($this->assigner)($this->user, $this->school); expect($this->user->school_id)->toEqual($this->school->id); }); it('logs the assignment of the user to the school', function () { ($this->assigner)($this->user, $this->school); $logEntry = AuditLogEntry::first(); expect($logEntry->message)->toEqual('Assigned '.$this->user->full_name().' to school '.$this->school->name); }); it('changes a users school assignment', function () { $this->user->school_id = $this->school->id; $this->user->save(); $newSchool = School::factory()->create(); ($this->assigner)($this->user, $newSchool); $this->user->refresh(); expect($this->user->school_id)->toEqual($newSchool->id); }); it('logs a change in school assignment', function () { $this->user->school_id = $this->school->id; $this->user->save(); $newSchool = School::factory()->create(); ($this->assigner)($this->user, $newSchool); $this->user->refresh(); $logEntry = AuditLogEntry::first(); expect($logEntry->message)->toEqual('Moved '.$this->user->full_name().' from school '.$this->school->name.' to school '.$newSchool->name); });