1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/tests/Feature/InvoiceEmailTest.php
David Bomba f57339f185
Fixes and Refactors for Invoice Emails. (#3339)
* Working on emailing invoices

* Working on emailing and displaying email

* Working on emailing and displaying email

* Email invoices

* Fixes for html emails

* Ensure valid client prior to store

* Ensure client exists when storing an entity

* Update variable name send -> send_email for client_contacts

* Mailable download files

* Extend timeouts of password protected routes when a protected route is hit

* Add default portal design to company settings

* Minor fixes

* Fixes for Tests

* Fixes for invoicing emails

* Refactors for InvoiceEmail

* Implement abstractservice

* Refactors for services

* Refactors for emails

* Fixes for Invoice Emails
2020-02-17 20:37:44 +11:00

72 lines
1.7 KiB
PHP

<?php
namespace Feature;
use App\Helpers\Email\InvoiceEmail;
use App\Jobs\Invoice\EmailInvoice;
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;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Session;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
*/
class InvoiceEmailTest extends TestCase
{
use MockAccountData;
use DatabaseTransactions;
use GeneratesCounter;
public function setUp() :void
{
parent::setUp();
Session::start();
$this->faker = \Faker\Factory::create();
Model::reguard();
$this->makeTestData();
}
public function test_initial_email_send_emails()
{
$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::dispatch($email_builder, $invitation, $invitation->company);
$this->expectsJobs(EmailInvoice::class);
}
});
}
}