Company Gateway Tests

This commit is contained in:
David Bomba 2019-10-03 20:59:19 +10:00
parent 3b6fa39d43
commit 16cd98980b
8 changed files with 64 additions and 16 deletions

View File

@ -131,7 +131,10 @@ class CompanyGatewayController extends BaseController
* @return \Illuminate\Http\Response
*/
public function update(UpdateCompanyGatewayRequest $request, CompanyGateway $company_gateway)
//public function update(CompanyGateway $company_gateway)
{
\Log::error('wooppee');
\Log::error(print_r($company_gateway,1));
$company_gateway->fill($request->all());
$company_gateway->save();

View File

@ -29,4 +29,5 @@ class CreateCompanyGatewayRequest extends Request
}
}

View File

@ -31,7 +31,9 @@ class UpdateCompanyGatewayRequest extends Request
{
$this->sanitize();
$rules = [];
$rules = [
'gateway_key' => 'required',
];
return $rules;
}

View File

@ -107,6 +107,11 @@ class CompanyGateway extends BaseModel
return json_decode(decrypt($this->config));
}
public function getConfigTransformed()
{
return $this->config ? decrypt($this->config) : '';
}
/**
* @param $field
*

View File

@ -81,6 +81,10 @@ class RouteServiceProvider extends ServiceProvider
return \App\Models\Company::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail();
});
Route::bind('company_gateway', function ($value) {
return \App\Models\CompanyGateway::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail();
});
Route::bind('companies', function ($value) {
return \App\Models\Company::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail();
});

View File

@ -49,7 +49,7 @@ class CompanyGatewayTransformer extends EntityTransformer
'show_address' => (bool)$company_gateway->show_address,
'show_shipping_address' => (bool)$company_gateway->show_shipping_address,
'update_details' => (bool)$company_gateway->update_details,
'config' => (string) decrypt($company_gateway->config) ?: '',
'config' => (string) $company_gateway->getConfigTransformed(),
'priority_id' => (int)$company_gateway->priority_id,
'min_limit' => (float)$company_gateway->min_limit,
'max_limit' => (float)$company_gateway->max_limit,

View File

@ -29,6 +29,7 @@ class CompanyGatewayApiTest extends TestCase
use DatabaseTransactions;
use MockAccountData;
public function setUp() :void
{
parent::setUp();
@ -40,52 +41,84 @@ class CompanyGatewayApiTest extends TestCase
$this->faker = \Faker\Factory::create();
Model::reguard();
}
public function testCompanyGatewayPost()
public function testCompanyGatewayEndPoints()
{
$data = [
'config' => 'random config',
'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb',
];
/* POST */
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token
])->post('/api/v1/company_gateways', $data);
$cg = $response->json();
$cg_id = $cg['data']['id'];
$this->assertNotNull($cg_id);
$response->assertStatus(200);
}
public function testCompanyGatewayPut()
{
/* 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 */
$data = [
'config' => 'changed',
];
\Log::error('the id = '.$cg_id);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token
])->put('/api/v1/company_gateways/'.$this->encodePrimaryKey($this->client->id), $data);
])->put("/api/v1/company_gateways/{$cg_id}", $data);
$response->assertStatus(200);
}
public function testCompanyGatewayGet()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token
])->get('/api/v1/company_gateways/'.$this->encodePrimaryKey($this->client->id));
])->put("/api/v1/company_gateways/{$cg_id}", $data);
$response->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token
])->delete("/api/v1/company_gateways/{$cg_id}", $data);
$response->assertStatus(200);
}

View File

@ -58,7 +58,7 @@ class UploadLogoTest extends TestCase
$response->assertStatus(200);
$acc = $response->json();
$logo = $acc['data']['logo'];
$logo = $acc['data']['logo_url'];
$logo_file = Storage::url($logo);