Fixes for tesytS

This commit is contained in:
David Bomba 2020-07-02 12:12:42 +10:00
parent 384fcd67b2
commit bd02554dd7

View File

@ -3,9 +3,10 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\DataMapper\DefaultSettings; use App\DataMapper\DefaultSettings;
use App\Http\Middleware\PasswordProtection;
use App\Models\Account; use App\Models\Account;
use App\Models\CompanyToken;
use App\Models\Company; use App\Models\Company;
use App\Models\CompanyToken;
use App\Models\User; use App\Models\User;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Faker\Factory; use Faker\Factory;
@ -14,11 +15,11 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Session;
use Tests\MockAccountData; use Tests\MockAccountData;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Routing\Middleware\ThrottleRequests;
/** /**
* @test * @test
@ -43,15 +44,18 @@ class CompanyTokenApiTest extends TestCase
Model::reguard(); Model::reguard();
$this->withoutMiddleware( $this->withoutMiddleware(
ThrottleRequests::class ThrottleRequests::class,
); );
} }
public function testCompanyTokenList() public function testCompanyTokenList()
{ {
$this->withoutMiddleware(PasswordProtection::class);
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token 'X-API-TOKEN' => $this->token,
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
])->get('/api/v1/tokens'); ])->get('/api/v1/tokens');
@ -60,12 +64,15 @@ class CompanyTokenApiTest extends TestCase
public function testCompanyTokenPost() public function testCompanyTokenPost()
{ {
$this->withoutMiddleware(PasswordProtection::class);
$data = [ $data = [
'name' => $this->faker->firstName, 'name' => $this->faker->firstName,
]; ];
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
'X-API-TOKEN' => $this->token 'X-API-TOKEN' => $this->token
])->post('/api/v1/tokens', $data); ])->post('/api/v1/tokens', $data);
@ -75,6 +82,8 @@ class CompanyTokenApiTest extends TestCase
public function testCompanyTokenPut() public function testCompanyTokenPut()
{ {
$this->withoutMiddleware(PasswordProtection::class);
$company_token = CompanyToken::whereCompanyId($this->company->id)->first(); $company_token = CompanyToken::whereCompanyId($this->company->id)->first();
$data = [ $data = [
@ -84,6 +93,7 @@ class CompanyTokenApiTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
'X-API-TOKEN' => $this->token 'X-API-TOKEN' => $this->token
])->put('/api/v1/tokens/'.$this->encodePrimaryKey($company_token->id), $data); ])->put('/api/v1/tokens/'.$this->encodePrimaryKey($company_token->id), $data);
@ -96,11 +106,14 @@ class CompanyTokenApiTest extends TestCase
public function testCompanyTokenGet() public function testCompanyTokenGet()
{ {
$this->withoutMiddleware(PasswordProtection::class);
$company_token = CompanyToken::whereCompanyId($this->company->id)->first(); $company_token = CompanyToken::whereCompanyId($this->company->id)->first();
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
'X-API-TOKEN' => $this->token 'X-API-TOKEN' => $this->token
])->get('/api/v1/tokens/'.$this->encodePrimaryKey($company_token->id)); ])->get('/api/v1/tokens/'.$this->encodePrimaryKey($company_token->id));
@ -110,10 +123,13 @@ class CompanyTokenApiTest extends TestCase
public function testCompanyTokenNotArchived() public function testCompanyTokenNotArchived()
{ {
$this->withoutMiddleware(PasswordProtection::class);
$company_token = CompanyToken::whereCompanyId($this->company->id)->first(); $company_token = CompanyToken::whereCompanyId($this->company->id)->first();
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
'X-API-TOKEN' => $this->token 'X-API-TOKEN' => $this->token
])->get('/api/v1/tokens/'.$this->encodePrimaryKey($company_token->id)); ])->get('/api/v1/tokens/'.$this->encodePrimaryKey($company_token->id));