2021-07-01 19:20:46 +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
|
|
|
|
*/
|
|
|
|
|
2021-07-05 10:38:16 +02:00
|
|
|
namespace Tests\Feature\ClientPortal;
|
2021-07-01 19:20:46 +02:00
|
|
|
|
2021-07-21 01:13:04 +02:00
|
|
|
use App\DataMapper\ClientSettings;
|
|
|
|
use App\DataMapper\CompanySettings;
|
2021-07-01 19:20:46 +02:00
|
|
|
use App\Http\Livewire\CreditsTable;
|
2021-07-02 01:51:31 +02:00
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\ClientContact;
|
|
|
|
use App\Models\Company;
|
2021-07-01 19:20:46 +02:00
|
|
|
use App\Models\Credit;
|
2021-07-02 01:51:31 +02:00
|
|
|
use App\Models\User;
|
2021-07-21 01:13:04 +02:00
|
|
|
use App\Utils\Traits\AppSetup;
|
2021-07-01 19:20:46 +02:00
|
|
|
use Faker\Factory;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Livewire\Livewire;
|
2021-07-05 10:38:16 +02:00
|
|
|
use function now;
|
2022-06-21 11:57:17 +02:00
|
|
|
use Tests\TestCase;
|
2021-07-01 19:20:46 +02:00
|
|
|
|
|
|
|
class CreditsTest extends TestCase
|
|
|
|
{
|
|
|
|
use DatabaseTransactions;
|
2021-07-21 01:13:04 +02:00
|
|
|
use AppSetup;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-07-01 19:20:46 +02:00
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->faker = Factory::create();
|
2021-07-21 01:13:04 +02:00
|
|
|
$this->buildCache(true);
|
2021-07-01 19:20:46 +02:00
|
|
|
}
|
|
|
|
|
2021-07-02 08:36:14 +02:00
|
|
|
public function testShowingOnlyCreditsWithDueDateLessOrEqualToNow()
|
2021-07-01 19:20:46 +02:00
|
|
|
{
|
2021-07-02 01:51:31 +02:00
|
|
|
$account = Account::factory()->create();
|
|
|
|
|
|
|
|
$user = User::factory()->create(
|
2022-06-21 11:59:36 +02:00
|
|
|
['account_id' => $account->id, 'email' => $this->faker->safeEmail()]
|
2021-07-02 01:51:31 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$company = Company::factory()->create(['account_id' => $account->id]);
|
2021-07-21 01:13:04 +02:00
|
|
|
$company->settings = CompanySettings::defaults();
|
2022-06-21 11:57:17 +02:00
|
|
|
$company->settings->language_id = '1';
|
2021-07-21 01:13:04 +02:00
|
|
|
$company->save();
|
2021-07-02 01:51:31 +02:00
|
|
|
|
|
|
|
$client = Client::factory()->create(['company_id' => $company->id, 'user_id' => $user->id]);
|
2021-07-21 01:13:04 +02:00
|
|
|
$client->settings = ClientSettings::defaults();
|
2022-01-17 08:53:39 +01:00
|
|
|
$settings = $client->settings;
|
2022-06-21 11:57:17 +02:00
|
|
|
$settings->language_id = '1';
|
2022-01-17 08:53:39 +01:00
|
|
|
$client->settings = $settings;
|
2021-07-21 01:13:04 +02:00
|
|
|
$client->save();
|
2021-07-02 01:51:31 +02:00
|
|
|
|
|
|
|
ClientContact::factory()->count(2)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
]);
|
|
|
|
|
2022-01-17 08:53:39 +01:00
|
|
|
$c1 = Credit::factory()->create([
|
2021-07-02 01:51:31 +02:00
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'client_id' => $client->id,
|
2021-07-01 19:20:46 +02:00
|
|
|
'number' => 'testing-number-01',
|
|
|
|
'due_date' => now()->subDays(5),
|
2021-07-02 01:37:44 +02:00
|
|
|
'status_id' => Credit::STATUS_SENT,
|
2021-07-01 19:20:46 +02:00
|
|
|
]);
|
|
|
|
|
2022-01-17 08:53:39 +01:00
|
|
|
$c2 = Credit::factory()->create([
|
2021-07-02 01:51:31 +02:00
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'client_id' => $client->id,
|
2021-07-01 19:20:46 +02:00
|
|
|
'number' => 'testing-number-02',
|
|
|
|
'due_date' => now(),
|
2021-07-02 01:37:44 +02:00
|
|
|
'status_id' => Credit::STATUS_SENT,
|
2021-07-01 19:20:46 +02:00
|
|
|
]);
|
|
|
|
|
2022-01-17 08:53:39 +01:00
|
|
|
$c3 = Credit::factory()->create([
|
2021-07-02 01:51:31 +02:00
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'client_id' => $client->id,
|
2021-07-01 19:20:46 +02:00
|
|
|
'number' => 'testing-number-03',
|
|
|
|
'due_date' => now()->addDays(5),
|
2021-07-02 01:37:44 +02:00
|
|
|
'status_id' => Credit::STATUS_SENT,
|
2021-07-01 19:20:46 +02:00
|
|
|
]);
|
|
|
|
|
2021-07-02 01:51:31 +02:00
|
|
|
$this->actingAs($client->contacts->first(), 'contact');
|
2021-07-01 19:20:46 +02:00
|
|
|
|
2022-01-17 08:53:39 +01:00
|
|
|
$c1->load('client');
|
|
|
|
$c2->load('client');
|
|
|
|
$c3->load('client');
|
|
|
|
|
2021-07-02 01:51:31 +02:00
|
|
|
Livewire::test(CreditsTable::class, ['company' => $company])
|
2021-10-05 04:49:15 +02:00
|
|
|
->assertDontSee('testing-number-01')
|
2021-07-01 19:20:46 +02:00
|
|
|
->assertSee('testing-number-02')
|
2021-10-05 04:49:15 +02:00
|
|
|
->assertSee('testing-number-03');
|
2021-07-01 19:20:46 +02:00
|
|
|
}
|
2021-07-02 08:36:14 +02:00
|
|
|
|
|
|
|
public function testShowingCreditsWithNullDueDate()
|
|
|
|
{
|
|
|
|
$account = Account::factory()->create();
|
|
|
|
|
|
|
|
$user = User::factory()->create(
|
2022-06-21 11:59:36 +02:00
|
|
|
['account_id' => $account->id, 'email' => $this->faker->safeEmail()]
|
2021-07-02 08:36:14 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$company = Company::factory()->create(['account_id' => $account->id]);
|
|
|
|
|
|
|
|
$client = Client::factory()->create(['company_id' => $company->id, 'user_id' => $user->id]);
|
2022-01-17 08:53:39 +01:00
|
|
|
$client->settings = ClientSettings::defaults();
|
|
|
|
$settings = $client->settings;
|
2022-06-21 11:57:17 +02:00
|
|
|
$settings->language_id = '1';
|
2022-01-17 08:53:39 +01:00
|
|
|
$client->settings = $settings;
|
|
|
|
$client->save();
|
2021-07-02 08:36:14 +02:00
|
|
|
|
|
|
|
ClientContact::factory()->count(2)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
Credit::factory()->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'number' => 'testing-number-01',
|
|
|
|
'status_id' => Credit::STATUS_SENT,
|
2021-10-05 04:49:15 +02:00
|
|
|
'due_date' => null,
|
2021-07-02 08:36:14 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
Credit::factory()->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'number' => 'testing-number-02',
|
|
|
|
'due_date' => now(),
|
|
|
|
'status_id' => Credit::STATUS_SENT,
|
|
|
|
]);
|
|
|
|
|
|
|
|
Credit::factory()->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'number' => 'testing-number-03',
|
|
|
|
'due_date' => now()->addDays(5),
|
|
|
|
'status_id' => Credit::STATUS_SENT,
|
|
|
|
]);
|
|
|
|
|
2021-10-05 04:49:15 +02:00
|
|
|
Credit::factory()->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'number' => 'testing-number-04',
|
|
|
|
'due_date' => '',
|
|
|
|
'status_id' => Credit::STATUS_SENT,
|
|
|
|
]);
|
|
|
|
|
2021-07-02 08:36:14 +02:00
|
|
|
$this->actingAs($client->contacts->first(), 'contact');
|
|
|
|
|
|
|
|
Livewire::test(CreditsTable::class, ['company' => $company])
|
|
|
|
->assertSee('testing-number-01')
|
|
|
|
->assertSee('testing-number-02')
|
2021-10-05 04:49:15 +02:00
|
|
|
->assertSee('testing-number-03');
|
2021-07-02 08:36:14 +02:00
|
|
|
}
|
2021-07-01 19:20:46 +02:00
|
|
|
}
|