1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/tests/Feature/Account/AccountEmailQuotaTest.php

138 lines
3.8 KiB
PHP
Raw Normal View History

2021-08-07 11:56:56 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace Tests\Feature\Account;
2023-01-18 10:42:46 +01:00
use App\DataMapper\ClientRegistrationFields;
2021-08-07 11:56:56 +02:00
use App\DataMapper\CompanySettings;
use App\Models\Account;
use App\Models\Company;
2023-01-18 10:42:46 +01:00
use App\Utils\Ninja;
use Illuminate\Support\Facades\Cache;
2021-08-07 11:56:56 +02:00
use Tests\TestCase;
class AccountEmailQuotaTest extends TestCase
{
protected function setUp(): void
2021-08-07 11:56:56 +02:00
{
parent::setUp();
}
2023-01-18 10:04:53 +01:00
2023-01-18 11:07:15 +01:00
public function testIfQuotaBreached()
2021-08-07 11:56:56 +02:00
{
2023-01-18 10:42:46 +01:00
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();
2024-02-04 05:06:24 +01:00
/** @vart \App\Models\Account $account */
2023-01-18 10:42:46 +01:00
$account->default_company_id = $company->id;
$account->save();
2023-03-09 06:01:34 +01:00
Cache::put("email_quota".$account->key, 3000);
2023-01-18 10:42:46 +01:00
$this->assertFalse($account->isPaid());
$this->assertTrue(Ninja::isNinja());
$this->assertEquals(20, $account->getDailyEmailLimit());
2023-03-09 06:01:34 +01:00
$this->assertEquals(3000, Cache::get("email_quota".$account->key));
2023-01-18 10:42:46 +01:00
$this->assertTrue($account->emailQuotaExceeded());
2023-03-09 06:01:34 +01:00
Cache::forget("email_quota".'123ifyouknowwhatimean');
2021-08-07 11:56:56 +02:00
}
2023-01-18 11:07:15 +01:00
public function testQuotaValidRule()
{
$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();
2023-03-09 06:01:34 +01:00
Cache::increment("email_quota".$account->key);
2023-01-18 11:07:15 +01:00
$this->assertFalse($account->emailQuotaExceeded());
2023-03-09 06:01:34 +01:00
Cache::forget("email_quota".'123ifyouknowwhatimean');
2023-01-18 11:07:15 +01:00
}
public function testEmailSentCount()
{
$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();
2023-06-18 06:34:35 +02:00
Cache::put("email_quota".$account->key, 3000);
2023-01-18 11:07:15 +01:00
$count = $account->emailsSent();
$this->assertEquals(3000, $count);
2023-03-09 06:01:34 +01:00
Cache::forget("email_quota".'123ifyouknowwhatimean');
2023-01-18 11:07:15 +01:00
}
2021-08-07 11:56:56 +02:00
}