Fixes for tests

This commit is contained in:
David Bomba 2023-01-18 20:42:46 +11:00
parent 04a9462872
commit 1a60f8d9d8
2 changed files with 163 additions and 19 deletions

View File

@ -483,7 +483,12 @@ class BillingPortalPurchasev2 extends Component
*/
protected function getPaymentMethods() :self
{
if($this->contact)
nlog("total amount = {$this->float_amount_total}");
if($this->float_amount_total == 0)
$this->methods = [];
if($this->contact && $this->float_amount_total >= 1)
$this->methods = $this->contact->client->service()->getPaymentMethods($this->float_amount_total);
return $this;
@ -573,6 +578,66 @@ class BillingPortalPurchasev2 extends Component
]);
}
public function handlePaymentNotRequired()
{
$eligibility_check = $this->subscription->service()->isEligible($this->contact);
if(is_array($eligibility_check) && $eligibility_check['message'] != 'Success'){
$this->is_eligible = false;
$this->not_eligible_message = $eligibility_check['message'];
return $this;
}
$invoice = $this->subscription
->service()
->createInvoiceV2($this->bundle, $this->contact->client_id, $this->valid_coupon)
->service()
->fillDefaults()
->adjustInventory()
->markPaid()
->save();
if (strlen($this->subscription->recurring_product_ids) >= 1) {
$recurring_invoice = $this->subscription->service()->convertInvoiceToRecurringBundle($this->contact->client_id, $this->bundle);
/* Start the recurring service */
$recurring_invoice->service()
->start()
->save();
$invoice->recurring_id = $recurring_invoice->id;
$invoice->save();
$context = [
'context' => 'recurring_purchase',
'recurring_invoice' => $recurring_invoice->hashed_id,
'invoice' => $invoice->hashed_id,
'client' => $recurring_invoice->client->hashed_id,
'subscription' => $this->subscription->hashed_id,
'contact' => auth()->guard('contact')->user()->hashed_id,
'redirect_url' => "/client/recurring_invoices/{$recurring_invoice->hashed_id}",
];
return $context;
}
$redirect_url = "/client/invoices/{$invoice->hashed_id}";
return $this->handleRedirect($redirect_url);
}

View File

@ -12,18 +12,11 @@
namespace Tests\Feature\Account;
use App\DataMapper\ClientSettings;
use App\DataMapper\ClientRegistrationFields;
use App\DataMapper\CompanySettings;
use App\Http\Livewire\CreditsTable;
use App\Models\Account;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Company;
use App\Models\Credit;
use App\Models\User;
use App\Utils\Traits\AppSetup;
use Faker\Factory;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Utils\Ninja;
use Illuminate\Support\Facades\Cache;
use Livewire\Livewire;
use Tests\MockAccountData;
@ -31,35 +24,121 @@ use Tests\TestCase;
class AccountEmailQuotaTest extends TestCase
{
use MockAccountData;
protected function setUp(): void
{
parent::setUp();
$this->makeTestData();
}
public function testQuotaValidRule()
{
Cache::increment($this->account->key);
$this->assertFalse($this->account->emailQuotaExceeded());
$account = Account::factory()->create([
'hosted_client_count' => 1000,
'hosted_company_count' => 1000,
'is_flagged' => false,
'key' => '123ifyouknowwhatimean',
'created_at' => now(),
'updated_at' => now(),
]);
$account->num_users = 3;
$account->save();
Cache::increment($account->key);
$this->assertFalse($account->emailQuotaExceeded());
Cache::forget('123ifyouknowwhatimean');
}
public function testEmailSentCount()
{
Cache::put($this->account->key, 3000);
$account = Account::factory()->create([
'hosted_client_count' => 1000,
'hosted_company_count' => 1000,
'is_flagged' => false,
'key' => '123ifyouknowwhatimean',
'created_at' => now(),
'updated_at' => now(),
]);
$count = $this->account->emailsSent();
$account->num_users = 3;
$account->save();
Cache::put($account->key, 3000);
$count = $account->emailsSent();
$this->assertEquals(3000, $count);
Cache::forget('123ifyouknowwhatimean');
}
public function testQuotaInValidRule()
{
Cache::put($this->account->key, 3000);
$this->assertTrue($this->account->emailQuotaExceeded());
config([
'ninja.production' => true
]);
$account = Account::factory()->create([
'hosted_client_count' => 1000,
'hosted_company_count' => 1000,
'is_flagged' => false,
'key' => '123ifyouknowwhatimean',
'created_at' => now(),
'updated_at' => now(),
]);
$account->num_users = 3;
$account->save();
$company = Company::factory()->create([
'account_id' => $account->id,
]);
$company->client_registration_fields = ClientRegistrationFields::generate();
$settings = CompanySettings::defaults();
$settings->company_logo = 'https://pdf.invoicing.co/favicon-v2.png';
$settings->website = 'www.invoiceninja.com';
$settings->address1 = 'Address 1';
$settings->address2 = 'Address 2';
$settings->city = 'City';
$settings->state = 'State';
$settings->postal_code = 'Postal Code';
$settings->phone = '555-343-2323';
$settings->email = 'nothingtoofancy@acme.com';
$settings->country_id = '840';
$settings->vat_number = 'vat number';
$settings->id_number = 'id number';
$settings->use_credits_payment = 'always';
$settings->timezone_id = '1';
$settings->entity_send_time = 0;
$company->track_inventory = true;
$company->settings = $settings;
$company->save();
$account->default_company_id = $company->id;
$account->save();
Cache::put($account->key, 3000);
$this->assertFalse($account->isPaid());
$this->assertTrue(Ninja::isNinja());
$this->assertEquals(20, $account->getDailyEmailLimit());
$this->assertEquals(3000, Cache::get($account->key));
$this->assertTrue($account->emailQuotaExceeded());
Cache::forget('123ifyouknowwhatimean');
}
}