mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Fixes for tests
This commit is contained in:
parent
cb0385dd39
commit
e349245c45
@ -66,7 +66,7 @@ class EmailQuotaNotification extends Notification
|
||||
{
|
||||
$content = "Email quota exceeded by Account {$this->account->key} \n";
|
||||
|
||||
$owner = $this->account->companies()->first()->owner();
|
||||
$owner = $this->account->companies()->first()->owner() ?? $this->account->users()->orderBy('id','asc')->first();
|
||||
$owner_name = $owner->present()->name() ?? 'No Owner Found';
|
||||
$owner_email = $owner->email ?? 'No Owner Email Found';
|
||||
|
||||
|
@ -21,10 +21,6 @@ class PaymentMethod
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
private $client;
|
||||
|
||||
private $amount;
|
||||
|
||||
/** @var \Illuminate\Support\Collection<CompanyGateway> $gateways **/
|
||||
private $gateways;
|
||||
|
||||
@ -32,10 +28,8 @@ class PaymentMethod
|
||||
|
||||
private $payment_urls = [];
|
||||
|
||||
public function __construct(Client $client, float $amount)
|
||||
public function __construct(private Client $client, private float $amount)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->amount = $amount;
|
||||
}
|
||||
|
||||
public function run()
|
||||
@ -105,7 +99,6 @@ class PaymentMethod
|
||||
$transformed_ids = [];
|
||||
}
|
||||
|
||||
|
||||
$this->gateways = $this->client
|
||||
->company
|
||||
->company_gateways
|
||||
@ -140,7 +133,7 @@ class PaymentMethod
|
||||
|
||||
foreach ($gateway->driver($this->client)->gatewayTypes() as $type) {
|
||||
if (isset($gateway->fees_and_limits) && is_object($gateway->fees_and_limits) && property_exists($gateway->fees_and_limits, $type)) {
|
||||
if ($this->validGatewayForAmount($gateway->fees_and_limits->{$type}, $this->amount) && $gateway->fees_and_limits->{$type}->is_enabled) {
|
||||
if ($this->validGatewayForAmount($gateway->fees_and_limits->{$type}) && $gateway->fees_and_limits->{$type}->is_enabled) {
|
||||
$this->payment_methods[] = [$gateway->id => $type];
|
||||
}
|
||||
} else {
|
||||
@ -159,8 +152,8 @@ class PaymentMethod
|
||||
{
|
||||
foreach ($type as $gateway_id => $gateway_type_id)
|
||||
{
|
||||
$gate = $this->gateways->where('id',$gateway_id)->first();
|
||||
$this->buildUrl($gate, $gateway_type_id);
|
||||
$gate = $this->gateways->where('id', $gateway_id)->first();
|
||||
$this->buildUrl($gate, $gateway_type_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,6 +204,7 @@ class PaymentMethod
|
||||
];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
//@deprecated as buildUrl() supercedes
|
||||
@ -256,14 +250,14 @@ class PaymentMethod
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function validGatewayForAmount($fees_and_limits_for_payment_type, $amount): bool
|
||||
private function validGatewayForAmount($fees_and_limits_for_payment_type): bool
|
||||
{
|
||||
if (isset($fees_and_limits_for_payment_type)) {
|
||||
$fees_and_limits = $fees_and_limits_for_payment_type;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $fees_and_limits->min_limit != -1 && ($this->amount < $fees_and_limits->min_limit && $this->amount != -1)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -38,12 +38,15 @@ class ClientModelTest extends TestCase
|
||||
if (! config('ninja.testvars.stripe')) {
|
||||
$this->markTestSkipped('Skip test no company gateways installed');
|
||||
}
|
||||
|
||||
if(CompanyGateway::count() == 0)
|
||||
$this->markTestSkipped('Skip test no company gateways installed');
|
||||
|
||||
}
|
||||
|
||||
public function testPaymentMethodsWithCreditsEnforced()
|
||||
{
|
||||
$amount = 40;
|
||||
|
||||
|
||||
$payment_methods = $this->client->service()->getPaymentMethods(40);
|
||||
|
||||
$this->assertGreaterThan(0, CompanyGateway::count());
|
||||
|
@ -54,7 +54,9 @@ class CompanyGatewayResolutionTest extends TestCase
|
||||
|
||||
$this->withoutExceptionHandling();
|
||||
|
||||
CompanyGateway::whereNotNull('id')->delete();
|
||||
CompanyGateway::query()->withTrashed()->cursor()->each(function ($cg){
|
||||
$cg->forceDelete();
|
||||
});
|
||||
|
||||
$data = [];
|
||||
$data[1]['min_limit'] = -1;
|
||||
@ -123,11 +125,14 @@ class CompanyGatewayResolutionTest extends TestCase
|
||||
{
|
||||
$amount = 10;
|
||||
|
||||
$this->client->country_id = 840;
|
||||
$this->client->save();
|
||||
|
||||
$this->assertInstanceOf('\\stdClass', $this->cg->fees_and_limits);
|
||||
// $this->assertObjectHasAttribute('min_limit', $this->cg->fees_and_limits->{1});
|
||||
$this->assertNotNull($this->cg->fees_and_limits->{1}->min_limit);
|
||||
$payment_methods = $this->client->service()->getPaymentMethods($amount);
|
||||
|
||||
|
||||
$this->assertEquals(2, count($payment_methods));
|
||||
}
|
||||
|
||||
@ -135,7 +140,9 @@ class CompanyGatewayResolutionTest extends TestCase
|
||||
{
|
||||
$amount = 10;
|
||||
|
||||
CompanyGateway::whereNotNull('id')->delete();
|
||||
CompanyGateway::query()->withTrashed()->cursor()->each(function ($cg) {
|
||||
$cg->forceDelete();
|
||||
});
|
||||
|
||||
$data = [];
|
||||
$data[1]['min_limit'] = -1;
|
||||
@ -181,9 +188,10 @@ class CompanyGatewayResolutionTest extends TestCase
|
||||
$this->cg->fees_and_limits = $data;
|
||||
$this->cg->save();
|
||||
|
||||
// nlog($this->client->service()->getPaymentMethods($amount));
|
||||
$this->client->country_id = 840;
|
||||
$this->client->save();
|
||||
|
||||
$this->assertEquals(2, count($this->client->service()->getPaymentMethods($amount)));
|
||||
$this->assertEquals(1, count($this->client->service()->getPaymentMethods($amount)));
|
||||
}
|
||||
|
||||
public function testEnableFeeAdjustment()
|
||||
|
@ -203,32 +203,32 @@ trait MockAccountData
|
||||
{
|
||||
config(['database.default' => config('ninja.db.default')]);
|
||||
|
||||
/* Warm up the cache !*/
|
||||
$cached_tables = config('ninja.cached_tables');
|
||||
// /* Warm up the cache !*/
|
||||
// $cached_tables = config('ninja.cached_tables');
|
||||
|
||||
Artisan::call('db:seed', [
|
||||
'--force' => true
|
||||
]);
|
||||
// Artisan::call('db:seed', [
|
||||
// '--force' => true
|
||||
// ]);
|
||||
|
||||
foreach ($cached_tables as $name => $class) {
|
||||
// check that the table exists in case the migration is pending
|
||||
if (! Schema::hasTable((new $class())->getTable())) {
|
||||
continue;
|
||||
}
|
||||
if ($name == 'payment_terms') {
|
||||
$orderBy = 'num_days';
|
||||
} elseif ($name == 'fonts') {
|
||||
$orderBy = 'sort_order';
|
||||
} elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) {
|
||||
$orderBy = 'name';
|
||||
} else {
|
||||
$orderBy = 'id';
|
||||
}
|
||||
$tableData = $class::orderBy($orderBy)->get();
|
||||
if ($tableData->count()) {
|
||||
Cache::forever($name, $tableData);
|
||||
}
|
||||
}
|
||||
// foreach ($cached_tables as $name => $class) {
|
||||
// // check that the table exists in case the migration is pending
|
||||
// if (! Schema::hasTable((new $class())->getTable())) {
|
||||
// continue;
|
||||
// }
|
||||
// if ($name == 'payment_terms') {
|
||||
// $orderBy = 'num_days';
|
||||
// } elseif ($name == 'fonts') {
|
||||
// $orderBy = 'sort_order';
|
||||
// } elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) {
|
||||
// $orderBy = 'name';
|
||||
// } else {
|
||||
// $orderBy = 'id';
|
||||
// }
|
||||
// $tableData = $class::orderBy($orderBy)->get();
|
||||
// if ($tableData->count()) {
|
||||
// Cache::forever($name, $tableData);
|
||||
// }
|
||||
// }
|
||||
|
||||
$this->faker = \Faker\Factory::create();
|
||||
$fake_email = $this->faker->email();
|
||||
@ -808,7 +808,7 @@ trait MockAccountData
|
||||
|
||||
if (config('ninja.testvars.stripe')) {
|
||||
$data = [];
|
||||
$data[1]['min_limit'] = 234;
|
||||
$data[1]['min_limit'] = 22;
|
||||
$data[1]['max_limit'] = 65317;
|
||||
$data[1]['fee_amount'] = 0.00;
|
||||
$data[1]['fee_percent'] = 0.000;
|
||||
|
Loading…
Reference in New Issue
Block a user