2019-10-03 05:21:24 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\DataMapper\DefaultSettings;
|
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\ClientContact;
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Faker\Factory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2019-10-03 06:27:17 +02:00
|
|
|
class CompanyGatewayApiTest extends TestCase
|
2019-10-03 05:21:24 +02:00
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
use MockAccountData;
|
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
|
2019-10-03 05:21:24 +02:00
|
|
|
public function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
|
|
|
|
Session::start();
|
|
|
|
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
|
|
|
|
Model::reguard();
|
2019-10-03 12:59:19 +02:00
|
|
|
|
2019-10-03 05:21:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
public function testCompanyGatewayEndPoints()
|
2019-10-03 05:21:24 +02:00
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'config' => 'random config',
|
2019-10-03 12:59:19 +02:00
|
|
|
'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb',
|
2019-10-03 05:21:24 +02:00
|
|
|
];
|
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
/* POST */
|
2019-10-03 05:21:24 +02:00
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
$cg = $response->json();
|
|
|
|
|
|
|
|
$cg_id = $cg['data']['id'];
|
|
|
|
|
|
|
|
$this->assertNotNull($cg_id);
|
2019-10-03 05:21:24 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* GET */
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token
|
|
|
|
])->get("/api/v1/company_gateways/{$cg_id}");
|
|
|
|
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
|
|
/* GET CREATE */
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token
|
|
|
|
])->get('/api/v1/company_gateways/create');
|
|
|
|
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
/* PUT */
|
2019-10-03 05:21:24 +02:00
|
|
|
$data = [
|
|
|
|
'config' => 'changed',
|
|
|
|
];
|
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
\Log::error('the id = '.$cg_id);
|
2019-10-03 05:21:24 +02:00
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token
|
2019-10-03 12:59:19 +02:00
|
|
|
])->put("/api/v1/company_gateways/{$cg_id}", $data);
|
2019-10-03 05:21:24 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token
|
|
|
|
])->put("/api/v1/company_gateways/{$cg_id}", $data);
|
2019-10-03 05:21:24 +02:00
|
|
|
|
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
2019-10-03 05:21:24 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token
|
2019-10-03 12:59:19 +02:00
|
|
|
])->delete("/api/v1/company_gateways/{$cg_id}", $data);
|
2019-10-03 05:21:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
2019-10-03 12:59:19 +02:00
|
|
|
|
|
|
|
|
2019-10-03 05:21:24 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|