<?php

use \App\User;
use \App\Review;

class ReviewTest extends TestCase {

  public function testInvalidRateValue()
  {
    Session::start();
    $this->setUser();

    $this->action('POST', 'ReviewController@postIndex', [],
                  [
                    '_token'=>csrf_token(),
                    'user_id'=>$this->__faker->numberBetween(5,10),
                    'content'=>$this->__faker->realText(),
                    'rate'=>6
                  ]);
    $this->assertSessionHasErrors();
  }

  public function testIfReviewAdded()
  {
    Session::start();
    $this->setUser();

    $user_id = $this->__faker->numberBetween(5,10);
    $rate    = $this->__faker->numberBetween(1,5);

    $this->action('POST', 'ReviewController@postIndex', [],
      [
        '_token'=>csrf_token(),
        'user_id'=>$user_id,
        'content'=>$this->__faker->realText(),
        'rate'=>$rate
      ]);

    $this->assertEquals($rate, User::find($user_id)->rate);
  }

  public function testFailGetNotExistReview()
  {
    $this->action('GET', 'ReviewController@getGet', ['id'=>0]);

    $this->assertResponseStatus(404);
  }

  public function testGetReview()
  {
    $response = $this->action('GET', 'ReviewController@getGet', ['id'=>$this->__faker->numberBetween(1,10)])->getContent();

    $this->assertJson($response);
  }

  public function testGetReviewed()
  {
    $Review = Review::find($this->__faker->numberBetween(1,10));

    $this->assertEquals(1, $Review->user->id);
  }
}