fixed tests

This commit is contained in:
denisdulici 2019-12-22 18:57:04 +03:00
parent e82f948353
commit 15650d3d6b
3 changed files with 29 additions and 28 deletions

View File

@ -36,7 +36,7 @@ class CreateCompany extends Job
$this->callSeeds(); $this->callSeeds();
$this->createSettings(); $this->updateSettings();
return $this->company; return $this->company;
} }
@ -48,17 +48,21 @@ class CreateCompany extends Job
'company' => $this->company->id 'company' => $this->company->id
]); ]);
if (!$user = user()) {
return;
}
// Attach company to user logged in // Attach company to user logged in
user()->companies()->attach($this->company->id); $user->companies()->attach($this->company->id);
// User seeds // User seeds
Artisan::call('user:seed', [ Artisan::call('user:seed', [
'user' => user()->id, 'user' => $user->id,
'company' => $this->company->id, 'company' => $this->company->id,
]); ]);
} }
protected function createSettings() protected function updateSettings()
{ {
setting()->setExtraColumns(['company_id' => $this->company->id]); setting()->setExtraColumns(['company_id' => $this->company->id]);
@ -81,6 +85,12 @@ class CreateCompany extends Job
'default.locale' => $this->request->get('locale', 'en-GB'), 'default.locale' => $this->request->get('locale', 'en-GB'),
]); ]);
if (!empty($this->request->settings)) {
foreach ($this->request->settings as $name => $value) {
setting()->set([$name => $value]);
}
}
setting()->save(); setting()->save();
setting()->forgetAll(); setting()->forgetAll();
} }

View File

@ -4,7 +4,7 @@ namespace Database\Seeds;
use App\Abstracts\Model; use App\Abstracts\Model;
use App\Jobs\Auth\CreateUser; use App\Jobs\Auth\CreateUser;
use App\Models\Common\Company; use App\Jobs\Common\CreateCompany;
use App\Traits\Jobs; use App\Traits\Jobs;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
@ -32,28 +32,17 @@ class TestCompany extends Seeder
private function createCompany() private function createCompany()
{ {
Company::create([ $this->dispatch(new CreateCompany([
'domain' => 'test.com', 'name' => 'My Company',
]); 'domain' => 'company.com',
'address' => 'New Street 1254',
setting()->setExtraColumns(['company_id' => '1']); 'currency' => 'USD',
setting()->set([ 'locale' => 'en-GB',
'company.name' => 'Test Company', 'enabled' => '1',
'company.email' => 'test@company.com', 'settings' => [
'company.address' => 'New Street 1254', 'wizard.completed' => '1',
'localisation.financial_start' => '01-01', ],
'default.currency' => 'USD', ]));
'default.account' => '1',
'default.payment_method' => 'offline-payments.cash.1',
'schedule.bill_days' => '10,5,3,1',
'schedule.invoice_days' => '1,3,5,10',
'schedule.send_invoice_reminder' => '1',
'schedule.send_bill_reminder' => '1',
'wizard.completed' => '1',
'contact.type.customer' => 'customer',
'contact.type.vendor' => 'vendor',
]);
setting()->save();
$this->command->info('Test company created.'); $this->command->info('Test company created.');
} }
@ -61,7 +50,7 @@ class TestCompany extends Seeder
public function createUser() public function createUser()
{ {
$this->dispatch(new CreateUser([ $this->dispatch(new CreateUser([
'name' => 'Test', 'name' => 'Test User',
'email' => 'test@company.com', 'email' => 'test@company.com',
'password' => '123456', 'password' => '123456',
'locale' => 'en-GB', 'locale' => 'en-GB',

View File

@ -19,6 +19,8 @@ abstract class FeatureTestCase extends TestCase
{ {
parent::setUp(); parent::setUp();
$this->withoutExceptionHandling();
$this->faker = Factory::create(); $this->faker = Factory::create();
$this->user = User::first(); $this->user = User::first();
$this->company = $this->user->companies()->first(); $this->company = $this->user->companies()->first();