Example #1
0
 public function postReset(Request $request)
 {
     $this->validate($request, ['company' => 'required|exists:companies,name']);
     $this->company = Company::whereName($request->input('company'))->firstOrFail();
     $request->merge(['company_id' => $this->company->id]);
     return $this->postResetOriginal($request);
 }
 public function testShowGroupNotInSameCompany()
 {
     $test_company = \plunner\Company::where('id', '<>', $this->company->id)->firstOrFail();
     $test_group = $test_company->groups->first();
     $response = $this->actingAs($this->employee)->json('GET', '/employees/groups/' . $test_group->id);
     $response->seeStatusCode(403);
 }
 public function setUp()
 {
     parent::setUp();
     config(['auth.model' => \plunner\Planner::class]);
     config(['jwt.user' => \plunner\Planner::class]);
     $this->company = \plunner\Company::findOrFail(1);
     $this->planner = $this->company->groups()->has('planner')->with('planner')->firstOrFail()->Planner;
 }
Example #4
0
 public function testIndex()
 {
     config(['auth.model' => \plunner\Company::class]);
     config(['jwt.user' => \plunner\Company::class]);
     $company = \plunner\Company::findOrFail(1);
     $response = $this->actingAs($company)->json('GET', '/companies/example');
     $response->seeStatusCode(200);
 }
Example #5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     //
     $companyId = $this->argument('companyId');
     if (is_numeric($companyId)) {
         print_r(Company::with(self::withFilter())->findOrFail($companyId)->toArray());
     } else {
         print_r(Company::with(self::withFilter())->select('id')->get()->toArray());
     }
 }
Example #6
0
 public function setUp()
 {
     parent::setUp();
     config(['auth.model' => \plunner\Planner::class]);
     config(['jwt.user' => \plunner\Planner::class]);
     $this->company = \plunner\Company::findOrFail(1);
     $this->employee = $this->company->employees()->has('groups')->with('groups')->firstOrFail();
     $this->group = $this->employee->groups->first();
     $this->planner = $this->group->planner;
     $this->data = ['title' => 'Test meeting', 'description' => 'Errare humanum est!', 'duration' => 120];
 }
 public function testSameGroupDataDifferentCompanies()
 {
     $company1 = $this->company;
     $company2 = \plunner\Company::findOrFail(2);
     //insert in company1
     $company2->groups()->create($this->data);
     //insert user in company2
     $response = $this->actingAs($company1)->json('POST', '/companies/groups/', $this->data);
     $response->assertResponseOk();
     //duplicated in company2
     $response = $this->actingAs($company1)->json('POST', '/companies/groups/', $this->data);
     $response->seeStatusCode(422);
 }
Example #8
0
 public function testError()
 {
     if (!$this->doConsole()) {
         return;
     }
     $company = \plunner\Company::whereEmail('*****@*****.**')->firstOrFail();
     $employee = $company->employees()->whereEmail('*****@*****.**')->firstOrFail();
     $calendar = $employee->calendars()->whereName('errors')->firstOrFail()->caldav;
     $calendar->sync_errors = '';
     $calendar->save();
     \Artisan::call('sync:caldav');
     $calendar = $calendar->fresh();
     $this->assertNotEquals('', $calendar->sync_errors);
 }
 public function setUp()
 {
     parent::setUp();
     config(['auth.model' => Planner::class]);
     config(['jwt.user' => Planner::class]);
     $this->company = Company::findOrFail(1);
     $this->employee = $this->company->employees()->with('groups')->first();
     $this->group = $this->employee->groups->first();
     $this->planner = $this->group->planner;
     $this->meeting = $this->group->meetings()->has('timeslots')->with('group')->first();
     $this->data = ['time_start' => '2015-12-17 12:00:00', 'time_end' => '2015-12-17 14:00:00'];
     $this->meeting->timeslots()->create($this->data);
     $this->timeslot = $this->meeting->timeslots()->with('meeting')->firstOrFail();
 }
 public function testUpdate()
 {
     $company = \plunner\Company::findOrFail(1);
     $data = ['name' => 'test', 'password' => 'testest', 'password_confirmation' => 'testest'];
     //correct request
     $response = $this->actingAs($company)->json('PUT', '/companies/company/', $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($company)->json('PUT', '/companies/company/', $data);
     $response->seeStatusCode(422);
 }
Example #11
0
 public function testResetPassword()
 {
     //perform restore request
     $response = $this->json('POST', '/employees/password/email', ['company' => 'testInit', 'email' => '*****@*****.**']);
     $response->seeStatusCode(200);
     //get the token
     $token = DB::table('password_resets_employees')->where('email', '*****@*****.**' . \plunner\Company::whereName('testInit')->firstOrFail()->id)->value('token');
     //perform reset with error
     $response = $this->json('POST', '/employees/password/reset', ['company' => 'testInit', 'email' => '*****@*****.**', 'password_confirmation' => 'testtest', 'password' => 'testtest', 'token' => 're' . $token]);
     $response->seeStatusCode(422);
     $response = $this->json('POST', '/employees/password/reset', ['company' => 'testInita', 'email' => '*****@*****.**', 'password_confirmation' => 'testtest', 'password' => 'testtest', 'token' => 're' . $token]);
     $response->seeStatusCode(422);
     //perform correct reset
     $response = $this->json('POST', '/employees/password/reset', ['company' => 'testInit', 'email' => '*****@*****.**', 'password_confirmation' => 'testtest', 'password' => 'testtest', 'token' => $token]);
     $response->seeStatusCode(200);
     $response = $this->json('POST', '/employees/auth/login', ['company' => 'testInit', 'email' => '*****@*****.**', 'password' => 'test']);
     $response->seeStatusCode(422);
     $response = $this->json('POST', '/employees/auth/login', ['company' => 'testInit', 'email' => '*****@*****.**', 'password' => 'testtest']);
     $response->seeStatusCode(200);
 }
Example #12
0
 public function postLogin(Request $request)
 {
     //get company ID and impiled it in the request
     $this->validate($request, ['company' => 'required|exists:companies,name']);
     $this->company = Company::whereName($request->input('company'))->firstOrFail();
     $request->merge(['company_id' => $this->company->id]);
     //remember me
     $this->validate($request, ['remember' => 'required|boolean']);
     if ($request->input('remember', false)) {
         config(['jwt.ttl' => '43200']);
         //30 days
         $this->custom = array_merge($this->custom, ['remember' => 'true']);
     } else {
         $this->custom = array_merge($this->custom, ['remember' => 'false']);
     }
     $ret = $this->postLoginOriginal($request);
     if ($ret->getStatusCode() == 200) {
     }
     //TODO set the token
     return $ret;
 }
 public function testSimpleModel()
 {
     if (!$this->doConsole()) {
         return;
     }
     //create data
     ob_start();
     $status = \Artisan::call('db:seed', ['--class' => 'OptimisationDemoSeeder', '--force' => true]);
     ob_end_clean();
     $this->assertEquals(0, $status);
     //get company
     $company = \plunner\Company::all()->last();
     //optimise
     $status = \Artisan::call('optimise:meetings', ['companyId' => $company->id]);
     $this->assertEquals(0, $status);
     //check if the meetings are correctly optimised looking the users number that attend to them
     $meetingShort = \plunner\Meeting::whereIn('group_id', $company->groups->pluck('id'))->where('duration', config('app.timeslots.duration'))->firstOrfail();
     $meetingLong = \plunner\Meeting::whereIn('group_id', $company->groups->pluck('id'))->where('duration', config('app.timeslots.duration') * 3)->firstOrfail();
     $this->assertEquals(1, $meetingShort->employees->count());
     $this->assertEquals(2, $meetingLong->employees->count());
 }
Example #14
0
 private function syncAll()
 {
     //TODO if are there no companies?
     $companies = Company::all();
     if ($this->option('background')) {
         \Log::debug(self::BACKGROUND_MOD_MEX);
         $this->info(self::BACKGROUND_MOD_MEX);
         foreach ($companies as $company) {
             $this->makeBackground($company);
         }
         \Log::debug(self::BACKGROUND_COMPLETED_MEX);
         $this->info(self::BACKGROUND_COMPLETED_MEX);
     } else {
         foreach ($companies as $company) {
             $this->makeForeground($company);
         }
     }
 }
 public function testDelete404()
 {
     $company = \plunner\Company::findOrFail(1);
     $group = $company->groups()->first();
     $ids = [];
     $employees = $group->employees;
     foreach ($employees as $employee) {
         $ids[] = $employee->id;
     }
     $employee = $company->employees()->create(['name' => 'ttt', 'email' => '*****@*****.**', 'password' => bcrypt('ttt')]);
     $response = $this->actingAs($company)->json('DELETE', '/companies/groups/' . $group->id . '/employees/' . $employee->id);
     $response->seeStatusCode(404);
 }
Example #16
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);
 }
Example #17
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return Company
  */
 protected function create(array $data)
 {
     return Company::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }