Пример #1
0
 public function testErrorCreateGroup()
 {
     $planner_id = \plunner\Employee::where('company_id', '<>', $this->company->id)->firstOrFail()->id;
     $data_response = $this->data;
     $data_response['planner_id'] = $planner_id;
     $response = $this->actingAs($this->company)->json('POST', '/companies/groups', $data_response);
     $response->seeStatusCode(422);
 }
Пример #2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $groupId
  * @param  int $employeeId
  * @return \Illuminate\Http\Response
  */
 public function destroy($groupId, $employeeId)
 {
     //
     $employee = Employee::findOrFail($employeeId);
     $this->authorize($employee);
     $group = Group::findOrFail($groupId);
     if (!$employee->belongsToGroup($group)) {
         return Response::json(['error' => 'employId <> groupId'], 404);
     }
     $employee->groups()->detach($groupId);
     return $group->employees;
 }
Пример #3
0
 public function testUpdate()
 {
     $employee = \plunner\Employee::findOrFail(1);
     $data = ['name' => 'test', 'password' => 'testest', 'password_confirmation' => 'testest'];
     //correct request
     $response = $this->actingAs($employee)->json('PUT', '/employees/employee/', $data);
     $response->assertResponseOk();
     $data2 = $data;
     unset($data2['password']);
     unset($data2['password_confirmation']);
     $response->seeJson($data2);
     //no correct request
     unset($data['password_confirmation']);
     $response = $this->actingAs($employee)->json('PUT', '/employees/employee/', $data);
     $response->seeStatusCode(422);
 }
Пример #4
0
 public function testUpdate()
 {
     $company = \plunner\Company::findOrFail(1);
     $employee = $company->employees->first();
     $data = ['name' => 'test', 'email' => '*****@*****.**', 'password' => 'testest', 'password_confirmation' => 'testest'];
     //correct request
     $response = $this->actingAs($company)->json('PUT', '/companies/employees/' . $employee->id, $data);
     $response->assertResponseOk();
     $data2 = $data;
     unset($data2['password']);
     unset($data2['password_confirmation']);
     $response->seeJson($data2);
     //duplicate employee
     $response = $this->actingAs($company)->json('PUT', '/companies/employees/' . $employee->id, $data);
     $response->seeStatusCode(422);
     //a no my employee
     $employee2 = \plunner\Employee::where('company_id', '<>', $company->id)->firstOrFail();
     $data['email'] = '*****@*****.**';
     //this since we are acting as original company -> see how requests work
     $response = $this->actingAs($company)->json('PUT', '/companies/employees/' . $employee2->id, $data);
     $response->seeStatusCode(403);
     $data['email'] = '*****@*****.**';
     //force field
     $data['email'] = '*****@*****.**';
     $data['company_id'] = 2;
     $response = $this->actingAs($company)->json('PUT', '/companies/employees/' . $employee->id, $data);
     $response->assertResponseOk();
     $data2 = $data;
     unset($data2['password']);
     unset($data2['password_confirmation']);
     $json = $response->response->content();
     $json = json_decode($json, true);
     $this->assertNotEquals($data['company_id'], $json['company_id']);
     //this for travis problem due to consider 1 as number instead of string
     $this->assertEquals(1, $json['company_id']);
     unset($data2['company_id']);
     $response->SeeJson($data2);
 }
Пример #5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     //
     $employee = Employee::findOrFail($id);
     $this->authorize($employee);
     $employee->delete();
     return $employee;
 }
 public function testDeleteEmployeeNotMine()
 {
     $company = \plunner\Company::findOrFail(1);
     $employee = \plunner\Employee::where('company_id', '<>', $company->id)->firstOrFail();
     $id = $employee->id;
     $response = $this->actingAs($company)->json('DELETE', '/companies/groups/' . $company->groups()->first()->id . '/employees/' . $id);
     $response->seeStatusCode(403);
 }
Пример #7
0
 /**
  * @param Solver $solver
  */
 private function saveEmployeesMeetings(Solver $solver)
 {
     $employeesMeetings = $solver->getXResults();
     foreach ($employeesMeetings as $eId => $employeeMeetings) {
         $employee = \plunner\Employee::findOrFail($eId);
         $employeeMeetings = collect($employeeMeetings);
         $employeeMeetings = $employeeMeetings->filter(function ($item) {
             return $item == 1;
         });
         $employee->meetings()->attach($employeeMeetings->keys()->toArray());
     }
 }
 public function testGetExternalCalendars()
 {
     $employee = \plunner\Employee::findOrFail(1);
     $data = ['url' => 'http://test.com', 'username' => 'test', 'password' => 'test'];
     //error request
     $response = $this->actingAs($employee)->json('POST', '/employees/calendars/calendars', $data);
     $response->seeStatusCode(422);
     $response->seeJson(['error' => "Invalid URL: 'http://test.com'"]);
 }
 public function testShowNotMine()
 {
     $employee = \plunner\Employee::findOrFail(1);
     $calendar = $employee->Calendars()->firstOrFail();
     $timeslot = \plunner\Timeslot::whereNotIn('calendar_id', $employee->calendars()->get()->pluck('id'))->firstOrFail();
     $response = $this->actingAs($employee)->json('GET', '/employees/calendars/' . $calendar->id . '/timeslots/' . $timeslot->id);
     $response->seeStatusCode(403);
 }