2019-12-14 06:49:48 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Feature;
|
|
|
|
|
2020-02-15 12:49:31 +01:00
|
|
|
use App\Helpers\Email\InvoiceEmail;
|
|
|
|
use App\Jobs\Invoice\EmailInvoice;
|
2019-12-16 12:34:38 +01:00
|
|
|
use App\Mail\TemplateEmail;
|
|
|
|
use App\Models\ClientContact;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\InvoiceInvitation;
|
|
|
|
use App\Utils\Traits\GeneratesCounter;
|
|
|
|
use App\Utils\Traits\InvoiceEmailBuilder;
|
2019-12-14 06:49:48 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2019-12-16 12:34:38 +01:00
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
2019-12-14 06:49:48 +01:00
|
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* @test
|
|
|
|
* @covers App\Jobs\Invoice\EmailInvoice
|
|
|
|
*/
|
2019-12-14 06:49:48 +01:00
|
|
|
class InvoiceEmailTest extends TestCase
|
|
|
|
{
|
|
|
|
use MockAccountData;
|
|
|
|
use DatabaseTransactions;
|
2019-12-16 12:34:38 +01:00
|
|
|
use GeneratesCounter;
|
2019-12-14 06:49:48 +01:00
|
|
|
|
|
|
|
public function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
Session::start();
|
|
|
|
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
|
|
|
|
Model::reguard();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
}
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
public function test_initial_email_send_emails()
|
2019-12-14 06:49:48 +01:00
|
|
|
{
|
2019-12-16 12:34:38 +01:00
|
|
|
$this->invoice->date = now();
|
|
|
|
$this->invoice->due_date = now()->addDays(7);
|
|
|
|
$this->invoice->number = $this->getNextInvoiceNumber($this->client);
|
2019-12-14 06:49:48 +01:00
|
|
|
|
2020-02-15 12:49:31 +01:00
|
|
|
$this->invoice->client_id = $this->client->id;
|
2020-04-15 02:30:52 +02:00
|
|
|
|
|
|
|
$client_settings = $this->client->settings;
|
|
|
|
$client_settings->email_style = 'dark';
|
|
|
|
$this->client->settings = $client_settings;
|
|
|
|
$this->client->save();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-15 12:49:31 +01:00
|
|
|
$this->invoice->setRelation('client', $this->client);
|
2019-12-14 06:49:48 +01:00
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
$this->invoice->save();
|
2019-12-14 06:49:48 +01:00
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
$this->invoice->invitations->each(function ($invitation) {
|
|
|
|
if ($invitation->contact->send_email && $invitation->contact->email) {
|
|
|
|
$email_builder = (new InvoiceEmail())->build($invitation, null);
|
2019-12-14 06:49:48 +01:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
EmailInvoice::dispatchNow($email_builder, $invitation, $invitation->company);
|
2019-12-14 06:49:48 +01:00
|
|
|
|
2020-02-15 12:49:31 +01:00
|
|
|
$this->expectsJobs(EmailInvoice::class);
|
|
|
|
}
|
2019-12-16 12:34:38 +01:00
|
|
|
});
|
2020-04-15 02:30:52 +02:00
|
|
|
|
|
|
|
$this->assertTrue(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTemplateThemes()
|
|
|
|
{
|
|
|
|
$settings = $this->company->settings;
|
|
|
|
$settings->email_style = 'light';
|
|
|
|
|
|
|
|
$this->company->settings = $settings;
|
|
|
|
$this->company->save();
|
|
|
|
|
|
|
|
$this->invoice->date = now();
|
|
|
|
$this->invoice->due_date = now()->addDays(7);
|
|
|
|
$this->invoice->number = $this->getNextInvoiceNumber($this->client);
|
|
|
|
|
|
|
|
$this->invoice->client_id = $this->client->id;
|
|
|
|
$this->invoice->setRelation('client', $this->client);
|
|
|
|
|
|
|
|
$this->invoice->save();
|
|
|
|
|
|
|
|
$this->invoice->invitations->each(function ($invitation) {
|
|
|
|
if ($invitation->contact->send_email && $invitation->contact->email) {
|
|
|
|
$email_builder = (new InvoiceEmail())->build($invitation, null);
|
|
|
|
|
|
|
|
EmailInvoice::dispatchNow($email_builder, $invitation, $invitation->company);
|
|
|
|
|
|
|
|
$this->expectsJobs(EmailInvoice::class);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$settings = $this->company->settings;
|
|
|
|
$settings->email_style = 'dark';
|
|
|
|
|
|
|
|
$this->company->settings = $settings;
|
|
|
|
$this->company->save();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
$this->invoice->date = now();
|
|
|
|
$this->invoice->due_date = now()->addDays(7);
|
|
|
|
$this->invoice->number = $this->getNextInvoiceNumber($this->client);
|
|
|
|
|
|
|
|
$this->invoice->client_id = $this->client->id;
|
|
|
|
|
|
|
|
$client_settings = $this->client->settings;
|
|
|
|
$client_settings->email_style = 'dark';
|
|
|
|
$this->client->settings = $client_settings;
|
|
|
|
$this->client->save();
|
|
|
|
|
|
|
|
$this->invoice->setRelation('client', $this->client);
|
|
|
|
$this->invoice->save();
|
|
|
|
|
|
|
|
$this->invoice->invitations->each(function ($invitation) {
|
|
|
|
if ($invitation->contact->send_email && $invitation->contact->email) {
|
|
|
|
$email_builder = (new InvoiceEmail())->build($invitation, null);
|
|
|
|
|
|
|
|
EmailInvoice::dispatchNow($email_builder, $invitation, $invitation->company);
|
|
|
|
|
|
|
|
$this->expectsJobs(EmailInvoice::class);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$settings = $this->company->settings;
|
|
|
|
$settings->email_style = 'plain';
|
|
|
|
|
|
|
|
$this->company->settings = $settings;
|
|
|
|
$this->company->save();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
$this->invoice->date = now();
|
|
|
|
$this->invoice->due_date = now()->addDays(7);
|
|
|
|
$this->invoice->number = $this->getNextInvoiceNumber($this->client);
|
|
|
|
|
|
|
|
$this->invoice->client_id = $this->client->id;
|
|
|
|
$this->invoice->setRelation('client', $this->client);
|
|
|
|
|
|
|
|
$this->invoice->save();
|
|
|
|
|
|
|
|
$this->invoice->invitations->each(function ($invitation) {
|
|
|
|
if ($invitation->contact->send_email && $invitation->contact->email) {
|
|
|
|
$email_builder = (new InvoiceEmail())->build($invitation, null);
|
|
|
|
|
|
|
|
EmailInvoice::dispatchNow($email_builder, $invitation, $invitation->company);
|
|
|
|
|
|
|
|
$this->expectsJobs(EmailInvoice::class);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->assertTrue(true);
|
2019-12-16 12:34:38 +01:00
|
|
|
}
|
2020-02-15 12:49:31 +01:00
|
|
|
}
|