diff --git a/.travis.yml b/.travis.yml index 4529e22a93..7e26abdb69 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,10 @@ sudo: true dist: xenial +services: + - mysql + - xvfb + # Prevent tests from taking more than 50 minutes group: deprecated-2017Q4 @@ -48,10 +52,6 @@ install: # - sed -i '/2checkout/d' composer.json - travis_retry composer install --no-interaction -services: - - mysql - - xvfb - before_script: # copy configuration files - php artisan key:generate --no-interaction @@ -72,6 +72,7 @@ before_script: # Start webserver on ninja.test:8000 - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start + - sleep 3 - ./vendor/laravel/dusk/bin/chromedriver-linux & - php artisan serve & diff --git a/app/DataMapper/ClientSettings.php b/app/DataMapper/ClientSettings.php index f2c40f6c5a..37ba278ab7 100644 --- a/app/DataMapper/ClientSettings.php +++ b/app/DataMapper/ClientSettings.php @@ -53,7 +53,7 @@ class ClientSettings extends BaseSettings */ public $industry_id; public $size_id; - public $invoice_email_list; //default comma separated list of contacts to email + public $invoice_email_list; //default comma separated list of contact ids to email /** * Cast object values and return entire class @@ -96,7 +96,7 @@ class ClientSettings extends BaseSettings 'custom_taxes1' => NULL, 'custom_taxes2' => NULL, 'lock_sent_invoices' => NULL, - 'invoice_email_list' => NULL, + 'invoice_email_list' => NULL, ]; } diff --git a/app/Events/Invoice/InvoiceWasMarkedSent.php b/app/Events/Invoice/InvoiceWasMarkedSent.php new file mode 100644 index 0000000000..1efd4b1039 --- /dev/null +++ b/app/Events/Invoice/InvoiceWasMarkedSent.php @@ -0,0 +1,29 @@ +invoice = $invoice; + } +} diff --git a/app/Listeners/Invoice/CreateInvoiceInvitations.php b/app/Listeners/Invoice/CreateInvoiceInvitations.php new file mode 100644 index 0000000000..8780351cc6 --- /dev/null +++ b/app/Listeners/Invoice/CreateInvoiceInvitations.php @@ -0,0 +1,44 @@ +invoice; + + $contacts = ClientContact::whereIn('id', explode(',', $invoice->settings->invoice_email_list))->get(); + + $contacts->each(function ($contact) use($invoice) { + + InvoiceInvitation::create([ + + ]); + + }); + + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index eea27c172b..d8e0bbdd0a 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -3,6 +3,7 @@ namespace App\Providers; use App\Events\Client\ClientWasCreated; +use App\Events\Invoice\InvoiceWasMarkedSent; use App\Events\User\UserCreated; use App\Listeners\Client\CreatedClientActivity; use App\Listeners\SendVerificationNotification; @@ -39,6 +40,13 @@ class EventServiceProvider extends ServiceProvider 'App\Events\ClientWasRestored' => [ 'App\Listeners\ActivityListener@restoredClient', ], + + //Invoices + [ + InvoiceWasMarkedSent::class => [ + CreateInvoiceInvitations::class + ] + ], ]; /** diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index b3061cdaf3..3a681986bc 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -4,6 +4,7 @@ namespace Tests\Feature; use App\Models\Account; use App\Models\Client; +use App\Models\ClientContact; use App\Models\Company; use App\Models\User; use App\Utils\Traits\MakesHash; @@ -205,9 +206,16 @@ class ClientTest extends TestCase $client = Client::all()->first(); + /* Make sure we have a valid settings object*/ $this->assertEquals($client->getSettings()->timezone_id, 15); + /* Make sure we are harvesting valid data */ $this->assertEquals($client->timezone()->name, 'US/Eastern'); + + $contacts = ClientContact::whereIn('id', explode(',', $client->getSettings()->invoice_email_list))->get(); + + /* Make sure NULL settings return the correct count (0) instead of throwing an exception*/ + $this->assertEquals(count($contacts), 0); } }