1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Client Portal Browser Tests

This commit is contained in:
David Bomba 2019-07-31 20:37:55 +10:00
parent 1e7bb34326
commit 54c4d7d8c5
5 changed files with 113 additions and 56 deletions

View File

@ -0,0 +1,102 @@
<?php
namespace Tests\Browser;
use App\DataMapper\DefaultSettings;
use App\Models\ClientContact;
use App\Utils\Traits\MakesHash;
use Hash;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\DB;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
class ClientPortalTest extends DuskTestCase
{
use WithFaker;
use MakesHash;
public function testLoginPageDisplayed()
{
$this->browse(function ($browser){
$browser->visit('/client/login')
->assertPathIs('/client/login');
});
}
/**
* A valid user can be logged in.
*
* @return void
*/
public function testLoginAValidUser()
{
\Eloquent::unguard();
$faker = \Faker\Factory::create();
$account = factory(\App\Models\Account::class)->create();
$company = factory(\App\Models\Company::class)->create([
'account_id' => $account->id,
'domain' => 'ninja.test',
]);
$account->default_company_id = $company->id;
$account->save();
$user = factory(\App\Models\User::class)->create([
'email' => $faker->email,
// 'account_id' => $account->id,
'confirmation_code' => $this->createDbHash(config('database.default'))
]);
$company_token = \App\Models\CompanyToken::create([
'user_id' => $user->id,
'company_id' => $company->id,
'account_id' => $account->id,
'name' => 'test token',
'token' => str_random(64),
]);
$user->companies()->attach($company->id, [
'account_id' => $account->id,
'is_owner' => 1,
'is_admin' => 1,
'is_locked' => 0,
'permissions' => json_encode([]),
'settings' => json_encode(DefaultSettings::userSettings()),
]);
$client = factory(\App\Models\Client::class)->create([
'user_id' => $user->id,
'company_id' => $company->id
]);
$contact = new ClientContact;
$contact->first_name = $faker->firstName;
$contact->last_name = $faker->lastName;
$contact->email = $faker->email;
$contact->company_id = $company->id;
$contact->password = Hash::make(config('ninja.testvars.password'));
$contact->email_verified_at = now();
$contact->client_id = $client->id;
$contact->save();
$this->browse(function ($browser) use ($contact) {
$browser->visit('/client/login')
->type('email', $contact->email)
->type('password', config('ninja.testvars.password'))
->press('Login')
->assertPathIs('/client/dashboard');
});
}
}

View File

@ -13,32 +13,10 @@ class CreateAccountTest extends DuskTestCase
use WithFaker;
public function testSignupFormDisplayed()
{
$response = $this->get('/signup');
$response->assertStatus(200);
}
/**
* A valid user can be logged in.
*
* @return void
public function testCreateAValidUser()
{
$this->browse(function (Browser $browser) {
$browser->visit('/signup')
->type('first_name',$this->faker->firstName())
->type('last_name', $this->faker->lastName())
->type('email', $this->faker->email())
->type('password', $this->faker->password(7))
->check('terms_of_service')
->check('privacy_policy')
->press(trans('texts.create_account'))
->assertPathIs('/dashboard');
});
}
*/
}

View File

@ -1,23 +0,0 @@
<?php
namespace Tests\Browser;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class ExampleTest extends DuskTestCase
{
/**
* A basic browser test example.
*
* @return void
*/
public function testBasicExample()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('Account');
});
}
}

View File

@ -34,24 +34,24 @@ class MultiDBUserTest extends TestCase
$ac = factory(\App\Models\Account::class)->make();
$ac->setHidden(['hashed_id']);
$account = Account::on('db-ninja-01')->create($ac->toArray());
$account2 = Account::on('db-ninja-02')->create($ac->toArray());
$company = factory(\App\Models\Company::class)->make([
'account_id' => $account->id,
'domain' => 'ninja.test',
'domain' => 'ninja.test',
]);
$company2 = factory(\App\Models\Company::class)->make([
'account_id' => $account2->id,
'domain' => 'ninja.test',
'domain' => 'ninja.test',
]);
$company->setHidden(['settings', 'settings_object']);
$company2->setHidden(['settings', 'settings_object']);
$company->setHidden(['settings', 'settings_object', 'hashed_id']);
$company2->setHidden(['settings', 'settings_object', 'hashed_id']);
Company::on('db-ninja-01')->create($company->toArray());
Company::on('db-ninja-02')->create($company2->toArray());

View File

@ -34,14 +34,14 @@ class UniqueEmailTest extends TestCase
$ac = factory(\App\Models\Account::class)->make();
$ac->setHidden(['hashed_id']);
$account = Account::on('db-ninja-01')->create($ac->toArray());
$account2 = Account::on('db-ninja-02')->create($ac->toArray());
$company = factory(\App\Models\Company::class)->make([
'account_id' => $account->id,
'domain' => 'ninja.test',
'domain' => 'ninja.test',
]);
$company2 = factory(\App\Models\Company::class)->make([
@ -50,8 +50,8 @@ class UniqueEmailTest extends TestCase
]);
$company->setHidden(['settings', 'settings_object']);
$company2->setHidden(['settings', 'settings_object']);
$company->setHidden(['settings', 'settings_object', 'hashed_id']);
$company2->setHidden(['settings', 'settings_object', 'hashed_id']);
Company::on('db-ninja-01')->create($company->toArray());
Company::on('db-ninja-02')->create($company2->toArray());