Tests for container manipulation

This commit is contained in:
David Bomba 2020-08-10 14:55:44 +10:00
parent 6840e3e471
commit 2e663447b8
11 changed files with 101 additions and 13 deletions

View File

@ -36,7 +36,7 @@ class EmailCredit extends BaseMailerJob implements ShouldQueue
public $message_array = [];
public $settings;
/**
* Create a new job instance.
*
@ -45,6 +45,8 @@ class EmailCredit extends BaseMailerJob implements ShouldQueue
public function __construct(Credit $credit)
{
$this->credit = $credit;
$this->settings = $credit->client->getMergedSettings();
}
/**
@ -59,7 +61,7 @@ class EmailCredit extends BaseMailerJob implements ShouldQueue
$template_style = $this->credit->client->getSetting('email_style');
$this->setMailDriver($this->credit->client->getSetting('email_sending_method'));
$this->setMailDriver();
$this->credit->invitations->each(function ($invitation) use ($template_style) {

View File

@ -41,6 +41,8 @@ class EmailInvoice extends BaseMailerJob implements ShouldQueue
public $email_builder;
public $company;
public $settings;
/**
*
* EmailInvoice constructor.
@ -55,6 +57,9 @@ class EmailInvoice extends BaseMailerJob implements ShouldQueue
$this->invoice_invitation = $invoice_invitation;
$this->email_builder = $email_builder;
$this->settings = $invoice_invitation->contact->client->getMergedSettings();
}
/**
@ -68,7 +73,7 @@ class EmailInvoice extends BaseMailerJob implements ShouldQueue
{
MultiDB::setDB($this->company->db);
$this->setMailDriver($this->invoice_invitation->invoice->client->getSetting('email_sending_method'));
$this->setMailDriver();
Mail::to($this->invoice_invitation->contact->email, $this->invoice_invitation->contact->present()->name())
->send(

View File

@ -11,6 +11,7 @@
namespace App\Jobs\Invoice;
use App\Jobs\Mail\BaseMailerJob;
use App\Jobs\Util\UnlinkFile;
use App\Libraries\MultiDB;
use App\Mail\DownloadInvoices;
@ -27,7 +28,7 @@ use Illuminate\Support\Facades\Storage;
use ZipStream\Option\Archive;
use ZipStream\ZipStream;
class ZipInvoices implements ShouldQueue
class ZipInvoices extends BaseMailerJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@ -37,6 +38,7 @@ class ZipInvoices implements ShouldQueue
private $email;
public $settings;
/**
* @deprecated confirm to be deleted
* Create a new job instance.
@ -50,6 +52,8 @@ class ZipInvoices implements ShouldQueue
$this->company = $company;
$this->email = $email;
$this->settings = $company->settings;
}
/**
@ -82,6 +86,8 @@ class ZipInvoices implements ShouldQueue
fclose($tempStream);
$this->setMailDriver();
Mail::to($this->email)
->send(new DownloadInvoices(Storage::disk(config('filesystems.default'))->url($path . $file_name), $this->company));

View File

@ -29,9 +29,9 @@ class BaseMailerJob implements ShouldQueue
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function setMailDriver(string $driver)
public function setMailDriver()
{
switch ($driver) {
switch ($this->settings->email_sending_method) {
case 'default':
break;
case 'gmail':
@ -45,7 +45,7 @@ class BaseMailerJob implements ShouldQueue
public function setGmailMailer()
{
$sending_user = $this->entity->client->getSetting('gmail_sending_user_id');
$sending_user = $this->settings->gmail_sending_user_id;
$user = User::find($sending_user);

View File

@ -43,6 +43,8 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue
public $entity_type;
public $entity;
public $settings;
/**
* Create a new job instance.
*
@ -55,6 +57,9 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue
$this->user = $user;
$this->payment = $payment;
$this->settings = $payment->client->getMergedSettings();
}
/**
@ -72,7 +77,7 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue
return true;
//if we need to set an email driver do it now
$this->setMailDriver($this->payment->client->getSetting('email_sending_method'));
$this->setMailDriver();
$mail_obj = (new EntityPaidObject($this->payment))->build();
$mail_obj->from = [$this->payment->user->email, $this->payment->user->present()->name()];

View File

@ -42,6 +42,9 @@ class EntitySentMailer extends BaseMailerJob implements ShouldQueue
public $entity_type;
public $entity;
public $settings;
/**
* Create a new job instance.
*
@ -58,6 +61,8 @@ class EntitySentMailer extends BaseMailerJob implements ShouldQueue
$this->entity = $invitation->{$entity_type};
$this->entity_type = $entity_type;
$this->settings = $invitation->contact->client->getMergedSettings();
}
/**
@ -71,7 +76,7 @@ class EntitySentMailer extends BaseMailerJob implements ShouldQueue
MultiDB::setDb($this->company->db);
//if we need to set an email driver do it now
$this->setMailDriver($this->entity->client->getSetting('email_sending_method'));
$this->setMailDriver();
$mail_obj = (new EntitySentObject($this->invitation, $this->entity_type))->build();
$mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()];

View File

@ -42,6 +42,8 @@ class EntityViewedMailer extends BaseMailerJob implements ShouldQueue
public $entity_type;
public $entity;
public $settings;
/**
* Create a new job instance.
*
@ -58,6 +60,9 @@ class EntityViewedMailer extends BaseMailerJob implements ShouldQueue
$this->entity = $invitation->{$entity_type};
$this->entity_type = $entity_type;
$this->settings = $invitation->contact->client->getMergedSettings();
}
/**
@ -72,7 +77,7 @@ class EntityViewedMailer extends BaseMailerJob implements ShouldQueue
MultiDB::setDb($this->company->db);
//if we need to set an email driver do it now
$this->setMailDriver($this->entity->client->getSetting('email_sending_method'));
$this->setMailDriver();
$mail_obj = (new EntityViewedObject($this->invitation, $this->entity_type))->build();
$mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()];

View File

@ -17,6 +17,7 @@ use App\Libraries\Google\Google;
use App\Libraries\MultiDB;
use App\Mail\Admin\EntityNotificationMailer;
use App\Mail\Admin\EntitySentObject;
use App\Models\ClientContact;
use App\Models\Company;
use App\Models\SystemLog;
use App\Models\User;
@ -45,6 +46,8 @@ class MailRouter extends BaseMailerJob implements ShouldQueue
public $sending_method;
public $settings;
public function __construct(Mailable $mailable, Company $company, $to_user, string $sending_method)
{
$this->mailable = $mailable;
@ -54,6 +57,11 @@ class MailRouter extends BaseMailerJob implements ShouldQueue
$this->to_user = $to_user;
$this->sending_method = $sending_method;
if($to_user instanceof ClientContact)
$this->settings = $to_user->client->getMergedSettings();
else
$this->settings = $this->company->settings;
}
public function handle()
@ -61,7 +69,7 @@ class MailRouter extends BaseMailerJob implements ShouldQueue
MultiDB::setDb($this->company->db);
//if we need to set an email driver do it now
$this->setMailDriver($sending_method);
$this->setMailDriver();
//send email
Mail::to($this->to_user->email)

View File

@ -44,6 +44,8 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
public $amount;
public $settings;
/**
* Create a new job instance.
*
@ -58,6 +60,8 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
$this->client = $client;
$this->amount = $amount;
$this->settings = $client->getMergedSettings();
}
/**
@ -72,7 +76,7 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
MultiDB::setDb($this->company->db);
//if we need to set an email driver do it now
$this->setMailDriver($this->client->getSetting('email_sending_method'));
$this->setMailDriver();
//iterate through company_users
$this->company->company_users->each(function ($company_user){

View File

@ -34,6 +34,7 @@ class UserEmailChanged extends BaseMailerJob implements ShouldQueue
protected $company;
public $settings;
/**
* Create a new job instance.
*
@ -45,6 +46,8 @@ class UserEmailChanged extends BaseMailerJob implements ShouldQueue
$this->new_email = $new_email;
$this->old_email = $old_email;
$this->company = $company;
$this->settings = $this->company->settings;
}
public function handle()
@ -53,7 +56,7 @@ class UserEmailChanged extends BaseMailerJob implements ShouldQueue
MultiDB::setDb($this->company->db);
//If we need to set an email driver do it now
$this->setMailDriver($this->company->settings->email_sending_method);
$this->setMailDriver();
/*Build the object*/
$mail_obj = new \stdClass;

View File

@ -0,0 +1,45 @@
<?php
namespace Tests\Integration;
use App\Models\Company;
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Cache;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
*/
class ContainerTest extends TestCase
{
use MockAccountData;
public function setUp() :void
{
parent::setUp();
$this->makeTestData();
app()->instance(Company::class, $this->company);
}
public function testBindingWorks()
{
$resolved_company = resolve(Company::class);
$this->assertNotNull($resolved_company);
$this->assertEquals($this->account->id, $resolved_company->account_id);
}
}