<?php

use App\OperationType;
use App\Operation;
use App\User;

class ScoreTest extends TestCase {

  protected $__operation_types = ['pickup', 'highlight', 'enforce'];

  public function testUserScoreGetActions()
  {
    $this->setUser();

    $this->action('GET', 'ScoreController@getIndex');
    $this->assertViewHas('user');

    $this->action('GET', 'ScoreController@getCreate');
    $this->assertViewHas('user');
  }

  public function testGetOperationTypeByCode()
  {
    $Type = OperationType::getByCode($this->__operation_types[$this->__faker->numberBetween(0, count($this->__operation_types)-1)]);

    $this->assertInstanceOf('App\OperationType', $Type);
  }

  public function testFailGetNotExistOperationType()
  {
    $Type = OperationType::getByCode('');

    $this->assertNull($Type);
  }

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

    $User = User::has('adverts')->first();
    $this->setUser($User->id);
    $type = $this->__operation_types[$this->__faker->numberBetween(0, count($this->__operation_types)-1)];

    $post_params = [
      '_token'    => csrf_token()
    ];

    $this->action('POST', 'ScoreController@postPay', ['type'=>$type, $User->adverts()->first()->id], $post_params);

    $this->assertEquals(Operation::orderBy('created_at', 'desc')->first()->user->id, $User->id);
  }

}