From d0e59e1d27d55c57aca78535ce6d50f6bf7aa122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Thu, 1 Jul 2021 19:20:46 +0200 Subject: [PATCH 1/3] Show only credits with `due_date` <= now() --- app/Http/Livewire/CreditsTable.php | 3 +- tests/ClientPortal/CreditsTest.php | 84 ++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tests/ClientPortal/CreditsTest.php diff --git a/app/Http/Livewire/CreditsTable.php b/app/Http/Livewire/CreditsTable.php index 9e254b9c0e50..97ac843fa8f4 100644 --- a/app/Http/Livewire/CreditsTable.php +++ b/app/Http/Livewire/CreditsTable.php @@ -26,7 +26,7 @@ class CreditsTable extends Component public $per_page = 10; public $company; - + public function mount() { MultiDB::setDb($this->company->db); @@ -37,6 +37,7 @@ class CreditsTable extends Component $query = Credit::query() ->where('client_id', auth('contact')->user()->client->id) ->where('status_id', '<>', Credit::STATUS_DRAFT) + ->whereDate('due_date', '<=', now()) ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->paginate($this->per_page); diff --git a/tests/ClientPortal/CreditsTest.php b/tests/ClientPortal/CreditsTest.php new file mode 100644 index 000000000000..c28525cc0187 --- /dev/null +++ b/tests/ClientPortal/CreditsTest.php @@ -0,0 +1,84 @@ +faker = Factory::create(); + + Model::reguard(); + + $this->makeTestData(); + } + + public function testShowingOnlyQuotesWithDueDateLessOrEqualToNow() + { + // Create two credits, one with due_date in future, one with now, one with less than now. + Credit::factory()->create([ + 'user_id' => $this->user->id, + 'company_id' => $this->company->id, + 'client_id' => $this->client->id, + 'number' => 'testing-number-01', + 'due_date' => now()->subDays(5), + ]); + + Credit::factory()->create([ + 'user_id' => $this->user->id, + 'company_id' => $this->company->id, + 'client_id' => $this->client->id, + 'number' => 'testing-number-02', + 'due_date' => now(), + ]); + + Credit::factory()->create([ + 'user_id' => $this->user->id, + 'company_id' => $this->company->id, + 'client_id' => $this->client->id, + 'number' => 'testing-number-03', + 'due_date' => now()->addDays(5), + ]); + + $this->actingAs($this->client); + + // Argument 1 passed to Illuminate\Foundation\Testing\TestCase::actingAs() must implement interface + // Illuminate\Contracts\Auth\Authenticatable, instance of App\Models\Client given, + // called in /var/www/html/tests/ClientPortal/CreditsTest.php on line 65 + + Livewire::test(CreditsTable::class) + ->assertSee('testing-number-01') + ->assertSee('testing-number-02') + ->assertDontSee('testing-number-03'); + } +} From 9ea59e2c7ad17126b98e1e41577d136dc3674a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 2 Jul 2021 01:37:44 +0200 Subject: [PATCH 2/3] Update for tests --- tests/ClientPortal/CreditsTest.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/ClientPortal/CreditsTest.php b/tests/ClientPortal/CreditsTest.php index c28525cc0187..c82f406aef9a 100644 --- a/tests/ClientPortal/CreditsTest.php +++ b/tests/ClientPortal/CreditsTest.php @@ -45,13 +45,13 @@ class CreditsTest extends TestCase public function testShowingOnlyQuotesWithDueDateLessOrEqualToNow() { - // Create two credits, one with due_date in future, one with now, one with less than now. Credit::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id, 'number' => 'testing-number-01', 'due_date' => now()->subDays(5), + 'status_id' => Credit::STATUS_SENT, ]); Credit::factory()->create([ @@ -60,6 +60,7 @@ class CreditsTest extends TestCase 'client_id' => $this->client->id, 'number' => 'testing-number-02', 'due_date' => now(), + 'status_id' => Credit::STATUS_SENT, ]); Credit::factory()->create([ @@ -68,15 +69,12 @@ class CreditsTest extends TestCase 'client_id' => $this->client->id, 'number' => 'testing-number-03', 'due_date' => now()->addDays(5), + 'status_id' => Credit::STATUS_SENT, ]); - $this->actingAs($this->client); + $this->actingAs($this->client->contacts->first(), 'contact'); - // Argument 1 passed to Illuminate\Foundation\Testing\TestCase::actingAs() must implement interface - // Illuminate\Contracts\Auth\Authenticatable, instance of App\Models\Client given, - // called in /var/www/html/tests/ClientPortal/CreditsTest.php on line 65 - - Livewire::test(CreditsTable::class) + Livewire::test(CreditsTable::class, ['company' => $this->company]) ->assertSee('testing-number-01') ->assertSee('testing-number-02') ->assertDontSee('testing-number-03'); From c9585002491aae773fc98b14ea9bb40562906089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 2 Jul 2021 01:51:31 +0200 Subject: [PATCH 3/3] Update for tests --- tests/ClientPortal/CreditsTest.php | 55 +++++++++++++++++------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/tests/ClientPortal/CreditsTest.php b/tests/ClientPortal/CreditsTest.php index c82f406aef9a..16ab0923a8b2 100644 --- a/tests/ClientPortal/CreditsTest.php +++ b/tests/ClientPortal/CreditsTest.php @@ -14,67 +14,76 @@ namespace Tests\ClientPortal; 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\Utils\Traits\MakesHash; +use App\Models\User; use Faker\Factory; -use Illuminate\Database\Eloquent\Model; use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Support\Facades\Session; use Livewire\Livewire; -use Tests\MockAccountData; use Tests\TestCase; class CreditsTest extends TestCase { - use MakesHash; use DatabaseTransactions; - use MockAccountData; public function setUp(): void { parent::setUp(); - Session::start(); - $this->faker = Factory::create(); - - Model::reguard(); - - $this->makeTestData(); } public function testShowingOnlyQuotesWithDueDateLessOrEqualToNow() { + $account = Account::factory()->create(); + + $user = User::factory()->create( + ['account_id' => $account->id, 'email' => $this->faker->safeEmail] + ); + + $company = Company::factory()->create(['account_id' => $account->id]); + + $client = Client::factory()->create(['company_id' => $company->id, 'user_id' => $user->id]); + + ClientContact::factory()->count(2)->create([ + 'user_id' => $user->id, + 'client_id' => $client->id, + 'company_id' => $company->id, + ]); + Credit::factory()->create([ - 'user_id' => $this->user->id, - 'company_id' => $this->company->id, - 'client_id' => $this->client->id, + 'user_id' => $user->id, + 'company_id' => $company->id, + 'client_id' => $client->id, 'number' => 'testing-number-01', 'due_date' => now()->subDays(5), 'status_id' => Credit::STATUS_SENT, ]); Credit::factory()->create([ - 'user_id' => $this->user->id, - 'company_id' => $this->company->id, - 'client_id' => $this->client->id, + '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' => $this->user->id, - 'company_id' => $this->company->id, - 'client_id' => $this->client->id, + '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, ]); - $this->actingAs($this->client->contacts->first(), 'contact'); + $this->actingAs($client->contacts->first(), 'contact'); - Livewire::test(CreditsTable::class, ['company' => $this->company]) + Livewire::test(CreditsTable::class, ['company' => $company]) ->assertSee('testing-number-01') ->assertSee('testing-number-02') ->assertDontSee('testing-number-03');