Improve Company Gateway validation

This commit is contained in:
David Bomba 2021-07-24 10:25:48 +10:00
parent c061046247
commit b5a8c60db5
2 changed files with 40 additions and 4 deletions

View File

@ -34,7 +34,7 @@ class StoreCompanyGatewayRequest extends Request
public function rules()
{
$rules = [
'gateway_key' => 'required',
'gateway_key' => 'required|alpha_num',
'fees_and_limits' => new ValidCompanyGatewayFeesAndLimitsRule(),
];
@ -45,9 +45,8 @@ class StoreCompanyGatewayRequest extends Request
{
$input = $this->all();
$gateway = Gateway::where('key', $input['gateway_key'])->first();
if($gateway);
if($gateway = Gateway::where('key', $input['gateway_key'])->first())
{
$default_gateway_fields = json_decode($gateway->fields);

View File

@ -45,6 +45,43 @@ class CompanyGatewayApiTest extends TestCase
Model::reguard();
}
public function testCompanyGatewayEndPointsWithIncorrectFields()
{
$data = [
'config' => 'random config',
'gateway_key' => '',
];
/* POST */
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/company_gateways', $data);
$response->assertStatus(302);
}
public function testCompanyGatewayEndPointsWithInvalidFields()
{
$data = [
'config' => 'random config',
'gateway_key' => '$#%^&*(',
];
/* POST */
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/company_gateways', $data);
$response->assertStatus(302);
}
public function testCompanyGatewayEndPoints()
{
$data = [