<?php

use App\User;
use \App\Company;

class UserTest extends TestCase {

  public function testShowProfileRealUser()
  {
    $User = User::find(mt_rand(1, 10));
    $this->action('GET', 'UserController@showProfile', ['user'=>$User->login]);
    $this->assertViewHas('user');
  }

  public function testShowProfileNotRealUser()
  {
    $this->action('GET', 'UserController@showProfile', ['user'=>null]);

    $this->assertResponseStatus(404);
  }

  public function testShowCabinetAuthUser()
  {
    $user = $this->setUser();

    $response = $this->call('GET', 'cabinet');

    $this->assertEquals($user->login, $response->original['user']->login);
  }

  public function testShowCabinetNotAuthUser()
  {
    $this->call('GET', 'cabinet');

    $this->assertRedirectedTo('auth/login');
  }

  public function testUpdateRate()
  {
    $user = $this->setUser();

    $this->assertEquals(0, $user->updateRate());
  }

  public function testUpdateCompanyInfo()
  {
    Session::start();

    $oldLogin       = $this->setCompany()->login;
    $newCompanyName = $this->__faker->company;

    $updateParams =
      [
        '_token'       => csrf_token(),
        'company_name' => $newCompanyName,
        'login'        => $this->__faker->userName
      ];

    $this->action('PUT', 'UserController@updateCabinet', [], $updateParams);

    $this->assertEquals($newCompanyName, Company::find(1)->name);
    $this->assertNotEquals($oldLogin, User::find(3)->login);
  }
}