diff --git a/app/DataMapper/ClientSettings.php b/app/DataMapper/ClientSettings.php index 37ba278ab7..133719737d 100644 --- a/app/DataMapper/ClientSettings.php +++ b/app/DataMapper/ClientSettings.php @@ -93,10 +93,11 @@ class ClientSettings extends BaseSettings 'show_currency_symbol' => NULL, 'show_currency_code' => NULL, 'inclusive_taxes' => NULL, - 'custom_taxes1' => NULL, - 'custom_taxes2' => NULL, 'lock_sent_invoices' => NULL, 'invoice_email_list' => NULL, + 'custom_taxes1' => NULL, + 'custom_taxes2' => NULL, + 'auto_bill' => NULL, ]; } @@ -116,8 +117,10 @@ class ClientSettings extends BaseSettings foreach($client_settings as $key => $value) { - if(!isset($client_settings->{$key}) && property_exists($company_settings, $key)) + if(!isset($client_settings->{$key}) && property_exists($company_settings, $key)) { + Log::error('settings ' . $key .' to '. $company_settings->{$key}); $client_settings->{$key} = $company_settings->{$key}; + } } diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index cdd1ff6c13..34127d4397 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -103,14 +103,14 @@ class CompanySettings extends BaseSettings 'start_of_week' => config('ninja.i18n.start_of_week'), 'financial_year_start' => config('ninja.i18n.financial_year_start'), 'default_task_rate' => 0, - 'send_reminders' => 1, - 'show_tasks_in_portal' => 1, - 'show_currency_symbol' => 1, - 'show_currency_code' => 0, - 'inclusive_taxes' => 1, - 'custom_taxes1' => 0, - 'custom_taxes2' => 0, - 'lock_sent_invoices' => 0, + 'send_reminders' => 'TRUE', + 'show_tasks_in_portal' => 'TRUE', + 'show_currency_symbol' => 'TRUE', + 'show_currency_code' => 'FALSE', + 'inclusive_taxes' => 'TRUE', + 'custom_taxes1' => 'FALSE', + 'custom_taxes2' => 'FALSE', + 'lock_sent_invoices' => 'TRUE', 'translations' => (object) [], ]; diff --git a/app/Factory/ClientFactory.php b/app/Factory/ClientFactory.php index 9410e5dd31..63db2662a2 100644 --- a/app/Factory/ClientFactory.php +++ b/app/Factory/ClientFactory.php @@ -19,7 +19,7 @@ class ClientFactory $client->paid_to_date = 0; $client->country_id = 4; $client->is_deleted = 0; - $client->settings = ClientSettings::defaults(); + $client->settings = new ClientSettings(ClientSettings::defaults()); $client_contact = ClientContactFactory::create($company_id, $user_id); $client->contacts->add($client_contact); diff --git a/app/Factory/InvoiceFactory.php b/app/Factory/InvoiceFactory.php index c2a69aaac0..831bc69774 100644 --- a/app/Factory/InvoiceFactory.php +++ b/app/Factory/InvoiceFactory.php @@ -26,7 +26,7 @@ class InvoiceFactory $invoice->partial_due_date = null; $invoice->is_deleted = false; $invoice->line_items = json_encode([]); - $invoice->settings = ClientSettings::buildClientSettings(CompanySettings::defaults(), ClientSettings::defaults()); //todo need to embed the settings here + $invoice->settings = ClientSettings::buildClientSettings(new CompanySettings(CompanySettings::defaults()), new ClientSettings(ClientSettings::defaults())); //todo need to embed the settings here $invoice->backup = json_encode([]); $invoice->tax_name1 = ''; $invoice->tax_rate1 = 0; diff --git a/app/Helpers/Invoice/InvoiceItemCalc.php b/app/Helpers/Invoice/InvoiceItemCalc.php index 6484803fbd..1f37e7a2b8 100644 --- a/app/Helpers/Invoice/InvoiceItemCalc.php +++ b/app/Helpers/Invoice/InvoiceItemCalc.php @@ -23,7 +23,7 @@ class InvoiceItemCalc private $line_total; - public function __construct(\stdClass $item, \stdClass $settings) + public function __construct(\stdClass $item, $settings) { $this->item = $item; diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index 16b2fd5b59..c8aa469c38 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -25,7 +25,7 @@ class InvoiceRepository extends BaseRepository $invoice->save(); - $invoice_calc = new InvoiceCalc($invoice); + $invoice_calc = new InvoiceCalc($invoice, $invoice->settings); $invoice = $invoice_calc->build()->getInvoice(); diff --git a/composer.json b/composer.json index ef712e3528..6a37965ac6 100644 --- a/composer.json +++ b/composer.json @@ -37,12 +37,13 @@ "require-dev": { "barryvdh/laravel-debugbar": "^3.2", "beyondcode/laravel-dump-server": "^1.0", + "brianium/paratest": "^3.0", "filp/whoops": "^2.0", "fzaninotto/faker": "^1.4", "laravel/dusk": "^4.0", "mockery/mockery": "^1.0", "nunomaduro/collision": "^2.0", - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^8.0" }, "autoload": { "classmap": [ diff --git a/database/factories/ClientFactory.php b/database/factories/ClientFactory.php index 9aeb10d2c0..1675b98a38 100644 --- a/database/factories/ClientFactory.php +++ b/database/factories/ClientFactory.php @@ -1,6 +1,7 @@ define(App\Models\Client::class, function (Faker $faker) { @@ -27,6 +28,6 @@ $factory->define(App\Models\Client::class, function (Faker $faker) { 'shipping_state' => $faker->state, 'shipping_postal_code' => $faker->postcode, 'shipping_country_id' => 4, - 'settings' => new ClientSettings(ClientSettings::defaults()), + 'settings' => ClientSettings::buildClientSettings(new CompanySettings(CompanySettings::defaults()), new ClientSettings(ClientSettings::defaults())), ]; }); diff --git a/phpunit.xml b/phpunit.xml index ef5f2b80a8..6a1a6c03f7 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -20,9 +20,6 @@ ./tests/Feature - - ./Modules - diff --git a/tests/Feature/AccountTest.php b/tests/Feature/AccountTest.php index 5b4dde14f4..289dcb36df 100644 --- a/tests/Feature/AccountTest.php +++ b/tests/Feature/AccountTest.php @@ -24,9 +24,7 @@ use Tests\TestCase; class AccountTest extends TestCase { - //use DatabaseTransactions; - - public function setUp() + public function setUp() :void { parent::setUp(); diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index 3a681986bc..300e758253 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature; +use App\DataMapper\DefaultSettings; use App\Models\Account; use App\Models\Client; use App\Models\ClientContact; @@ -25,8 +26,9 @@ use Tests\TestCase; class ClientTest extends TestCase { use MakesHash; + use DatabaseTransactions; - public function setUp() + public function setUp() :void { parent::setUp(); @@ -184,8 +186,39 @@ class ClientTest extends TestCase public function testDefaultTimeZoneFromClientModel() { - $user = User::all()->first(); - $company = Company::all()->first(); + $account = factory(\App\Models\Account::class)->create(); + $company = factory(\App\Models\Company::class)->create([ + 'account_id' => $account->id, + ]); + + $account->default_company_id = $company->id; + $account->save(); + + $user = factory(\App\Models\User::class)->create([ + 'account_id' => $account->id, + 'confirmation_code' => $this->createDbHash(config('database.default')) + ]); + + + $userPermissions = collect([ + 'view_invoice', + 'view_client', + 'edit_client', + 'edit_invoice', + 'create_invoice', + 'create_client' + ]); + + $userSettings = DefaultSettings::userSettings(); + + $user->companies()->attach($company->id, [ + 'account_id' => $account->id, + 'is_owner' => 1, + 'is_admin' => 1, + 'permissions' => $userPermissions->toJson(), + 'settings' => json_encode($userSettings), + 'is_locked' => 0, + ]); factory(\App\Models\Client::class, 3)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){ @@ -204,8 +237,11 @@ class ClientTest extends TestCase }); - $client = Client::all()->first(); + $client = Client::whereUserId($user->id)->whereCompanyId($company->id)->first(); + $this->assertNotNull($client); + + Log::error(print_r($client,1)); /* Make sure we have a valid settings object*/ $this->assertEquals($client->getSettings()->timezone_id, 15); diff --git a/tests/Feature/InvitationTest.php b/tests/Feature/InvitationTest.php index 94e393889e..408e684835 100644 --- a/tests/Feature/InvitationTest.php +++ b/tests/Feature/InvitationTest.php @@ -31,10 +31,10 @@ use Tests\TestCase; class InvitationTest extends TestCase { - use DatabaseTransactions; use MakesHash; + use DatabaseTransactions; - public function setUp() + public function setUp() :void { parent::setUp(); @@ -126,7 +126,5 @@ class InvitationTest extends TestCase $this->assertEquals($i->invoice_id, $invoice->id); - - } } diff --git a/tests/Feature/InvoiceTest.php b/tests/Feature/InvoiceTest.php index 55835c7c9a..e4578ccde5 100644 --- a/tests/Feature/InvoiceTest.php +++ b/tests/Feature/InvoiceTest.php @@ -2,13 +2,17 @@ namespace Tests\Feature; +use App\DataMapper\ClientSettings; +use App\DataMapper\CompanySettings; use App\Models\Account; use App\Models\Client; use App\Models\Invoice; use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Session; use Tests\TestCase; @@ -21,8 +25,9 @@ class InvoiceTest extends TestCase { use MakesHash; + use DatabaseTransactions; - public function setUp() + public function setUp() :void { parent::setUp(); @@ -153,7 +158,10 @@ class InvoiceTest extends TestCase factory(\App\Models\Invoice::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]); $invoice = Invoice::where('user_id',$user->id)->first(); + $invoice->settings = ClientSettings::buildClientSettings(new CompanySettings($company->settings), new ClientSettings($client->getSettings())); + $invoice->save(); + $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $token, @@ -172,6 +180,11 @@ class InvoiceTest extends TestCase 'status_id' => Invoice::STATUS_PAID ]; + $this->assertNotNull($invoice); + $this->assertNotNull($invoice->settings); + + $this->assertTrue(property_exists($invoice->settings, 'custom_taxes1')); + $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $token, diff --git a/tests/Feature/LoginTest.php b/tests/Feature/LoginTest.php index ab0b305da4..91bc0dfb1a 100644 --- a/tests/Feature/LoginTest.php +++ b/tests/Feature/LoginTest.php @@ -19,12 +19,9 @@ use Tests\TestCase; */ class LoginTest extends TestCase { - use DatabaseTransactions; - //use UserSessionAttributes; - //use RefreshDatabase; - public function setUp() + public function setUp() :void { parent::setUp(); Session::start(); diff --git a/tests/Feature/ProductTest.php b/tests/Feature/ProductTest.php index a4d7d6276c..78b4fb99b5 100644 --- a/tests/Feature/ProductTest.php +++ b/tests/Feature/ProductTest.php @@ -24,8 +24,9 @@ use Tests\TestCase; class ProductTest extends TestCase { use MakesHash; + use DatabaseTransactions; - public function setUp() + public function setUp() :void { parent::setUp(); diff --git a/tests/Integration/MultiDBUserTest.php b/tests/Integration/MultiDBUserTest.php index 71bf25417a..017a27634f 100644 --- a/tests/Integration/MultiDBUserTest.php +++ b/tests/Integration/MultiDBUserTest.php @@ -7,6 +7,7 @@ use App\Models\Account; use App\Models\Company; use App\Models\User; use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Tests\TestCase; @@ -21,10 +22,8 @@ use Tests\TestCase; class MultiDBUserTest extends TestCase { - //use DatabaseMigrations; - //use InteractsWithDatabase; - public function setUp() + public function setUp() :void { parent::setUp(); @@ -118,7 +117,7 @@ class MultiDBUserTest extends TestCase $this->expectNotToPerformAssertions(MultiDB::setDB('db-ninja-01')); } - public function tearDown() + public function tearDown() :void { DB::connection('db-ninja-01')->table('users')->delete(); DB::connection('db-ninja-02')->table('users')->delete(); diff --git a/tests/Integration/UniqueEmailTest.php b/tests/Integration/UniqueEmailTest.php index 98405b8520..68384e6948 100644 --- a/tests/Integration/UniqueEmailTest.php +++ b/tests/Integration/UniqueEmailTest.php @@ -3,10 +3,11 @@ namespace Tests\Unit; use App\Http\ValidationRules\UniqueUserRule; -use App\Models\User; use App\Models\Account; use App\Models\Company; +use App\Models\User; use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Tests\TestCase; @@ -17,11 +18,10 @@ use Tests\TestCase; */ class UniqueEmailTest extends TestCase { - //use InteractsWithDatabase; protected $rule; - public function setUp() + public function setUp() :void { parent::setUp(); @@ -86,7 +86,7 @@ class UniqueEmailTest extends TestCase } - public function tearDown() + public function tearDown() :void { DB::connection('db-ninja-01')->table('users')->delete(); DB::connection('db-ninja-02')->table('users')->delete(); diff --git a/tests/Unit/BaseSettingsTest.php b/tests/Unit/BaseSettingsTest.php index 64a887f44d..f920152822 100644 --- a/tests/Unit/BaseSettingsTest.php +++ b/tests/Unit/BaseSettingsTest.php @@ -4,6 +4,7 @@ namespace Tests\Unit; use App\DataMapper\ClientSettings; use App\DataMapper\CompanySettings; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Tests\TestCase; /** @@ -12,8 +13,8 @@ use Tests\TestCase; */ class BaseSettingsTest extends TestCase { - - public function setUp() + + public function setUp() :void { parent::setUp(); diff --git a/tests/Unit/CollectionMergingTest.php b/tests/Unit/CollectionMergingTest.php index 2a89234f1e..203cb36c1d 100644 --- a/tests/Unit/CollectionMergingTest.php +++ b/tests/Unit/CollectionMergingTest.php @@ -16,7 +16,7 @@ class CollectionMergingTest extends TestCase use UserSessionAttributes; - public function setUp() + public function setUp() :void { parent::setUp(); diff --git a/tests/Unit/CompanySettingsTest.php b/tests/Unit/CompanySettingsTest.php index 60ee3bef8e..35c0dad07a 100644 --- a/tests/Unit/CompanySettingsTest.php +++ b/tests/Unit/CompanySettingsTest.php @@ -12,7 +12,7 @@ use Tests\TestCase; class CompanySettingsTest extends TestCase { - public function setUp() + public function setUp() :void { parent::setUp(); diff --git a/tests/Unit/CompareCollectionTest.php b/tests/Unit/CompareCollectionTest.php index 1c6c000f06..c1349b9fa6 100644 --- a/tests/Unit/CompareCollectionTest.php +++ b/tests/Unit/CompareCollectionTest.php @@ -11,7 +11,7 @@ use Tests\TestCase; class CompareCollectionTest extends TestCase { - public function setUp() + public function setUp() :void { parent::setUp(); diff --git a/tests/Unit/CompareObjectTest.php b/tests/Unit/CompareObjectTest.php index 965f5f5aaf..4975439380 100644 --- a/tests/Unit/CompareObjectTest.php +++ b/tests/Unit/CompareObjectTest.php @@ -10,10 +10,10 @@ use Tests\TestCase; * @test * @covers App\DataMapper\ClientSettings */ -class CompanyObjectTest extends TestCase +class CompareObjectTest extends TestCase { - public function setUp() + public function setUp() :void { parent::setUp(); @@ -51,5 +51,17 @@ class CompanyObjectTest extends TestCase $this->assertEquals($build_client_settings->payment_terms, 7); } + public function testDirectClientSettingsBuild() + { + $settings = ClientSettings::buildClientSettings(new CompanySettings(CompanySettings::defaults()), new ClientSettings(ClientSettings::defaults())); + + $this->assertEquals($settings->timezone_id, 15); + $this->assertEquals($settings->currency_id, 1); + $this->assertEquals($settings->language_id, 1); + $this->assertEquals($settings->payment_terms, 7); + $this->assertTrue(property_exists($settings, 'invoice_email_list')); + $this->assertEquals($settings->custom_taxes1, 'FALSE'); + } + } diff --git a/tests/Unit/InvoiceItemTest.php b/tests/Unit/InvoiceItemTest.php index f392b6c530..2d7e619aaf 100644 --- a/tests/Unit/InvoiceItemTest.php +++ b/tests/Unit/InvoiceItemTest.php @@ -4,6 +4,7 @@ namespace Tests\Unit; use App\Factory\InvoiceItemFactory; use App\Helpers\Invoice\InvoiceItemCalc; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Tests\TestCase; /** @@ -12,7 +13,9 @@ use Tests\TestCase; */ class InvoiceItemTest extends TestCase { - public function setUp() + + + public function setUp() :void { parent::setUp(); diff --git a/tests/Unit/InvoiceTest.php b/tests/Unit/InvoiceTest.php index 6ed1038f3e..8d1a5c237e 100644 --- a/tests/Unit/InvoiceTest.php +++ b/tests/Unit/InvoiceTest.php @@ -5,6 +5,7 @@ namespace Tests\Unit; use App\Factory\InvoiceFactory; use App\Factory\InvoiceItemFactory; use App\Helpers\Invoice\InvoiceCalc; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Tests\TestCase; /** @@ -14,18 +15,19 @@ use Tests\TestCase; class InvoiceTest extends TestCase { - protected $invoice; + public $invoice; - protected $invoice_calc; + public $invoice_calc; - private $settings; + public $settings; - public function setUp() + public function setUp() :void { - parent::setUp(); + parent::setUp(); $this->invoice = InvoiceFactory::create(1,1);//stub the company and user_id + $this->invoice->line_items = $this->buildLineItems(); $this->settings = $this->invoice->settings; @@ -37,6 +39,7 @@ class InvoiceTest extends TestCase $this->invoice_calc = new InvoiceCalc($this->invoice, $this->settings); + } private function buildLineItems() @@ -61,6 +64,7 @@ class InvoiceTest extends TestCase public function testInvoiceTotals() { + $this->invoice_calc->build(); $this->assertEquals($this->invoice_calc->getSubTotal(), 20); @@ -168,6 +172,7 @@ class InvoiceTest extends TestCase $line_items[] = $item; $this->invoice->line_items = $line_items; + $this->settings->inclusive_taxes = true; $this->invoice->discount = 0; $this->invoice->custom_value1 = 0; diff --git a/tests/Unit/NestedCollectionTest.php b/tests/Unit/NestedCollectionTest.php index 867d528bf3..c2f969ddee 100644 --- a/tests/Unit/NestedCollectionTest.php +++ b/tests/Unit/NestedCollectionTest.php @@ -11,7 +11,7 @@ use Tests\TestCase; class NestedCollectionTest extends TestCase { - public function setUp() + public function setUp() :void { parent::setUp();