mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Company Gateway Tests
This commit is contained in:
parent
3b6fa39d43
commit
16cd98980b
@ -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();
|
||||
|
@ -29,4 +29,5 @@ class CreateCompanyGatewayRequest extends Request
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -31,7 +31,9 @@ class UpdateCompanyGatewayRequest extends Request
|
||||
{
|
||||
$this->sanitize();
|
||||
|
||||
$rules = [];
|
||||
$rules = [
|
||||
'gateway_key' => 'required',
|
||||
];
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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();
|
||||
});
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user