Skip to content

Commit

Permalink
applied jobs to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Nov 17, 2019
1 parent 272905d commit 58048a1
Show file tree
Hide file tree
Showing 25 changed files with 194 additions and 186 deletions.
2 changes: 1 addition & 1 deletion .env.testing
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
APP_NAME=Akaunting
APP_ENV=testing
APP_LOCALE=en-GB
APP_INSTALLED=false
APP_INSTALLED=true
APP_KEY=base64:xBC+BxlC7sXhYAtpTZv8TYAHqoPgsJaXL0S5Id6BbBc=
APP_DEBUG=true
APP_SCHEDULE_TIME="09:00"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class ModifySkuQuantityColumnItemsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('items', function (Blueprint $table) {
$table->string('sku')->nullable()->change();
$table->integer('quantity')->default(1)->change();
$table->dropUnique('items_company_id_sku_deleted_at_unique');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('items', function (Blueprint $table) {
$table->string('sku')->change();
$table->integer('quantity')->change();
$table->unique(['company_id', 'sku', 'deleted_at']);
});
}
}
28 changes: 15 additions & 13 deletions database/seeds/TestCompany.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Abstracts\Model;
use App\Models\Auth\User;
use App\Models\Common\Company;
use Artisan;
use Date;
use Illuminate\Database\Seeder;

Expand All @@ -30,16 +31,9 @@ public function run()

private function createCompany()
{
$rows = [
[
'id' => '1',
'domain' => 'test.com',
],
];

foreach ($rows as $row) {
Company::create($row);
}
Company::create([
'domain' => 'test.com',
]);

setting()->setExtraColumns(['company_id' => '1']);
setting()->set([
Expand All @@ -49,11 +43,14 @@ private function createCompany()
'localisation.financial_start' => '01-01',
'default.currency' => 'USD',
'default.account' => '1',
'default.payment_method' => 'offline-paymentz.cash.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' => true,
'schedule.send_bill_reminder' => true,
'schedule.send_invoice_reminder' => '0',
'schedule.send_bill_reminder' => '0',
'wizard.completed' => '1',
'contact.type.customer' => 'customer',
'contact.type.vendor' => 'vendor',
]);
setting()->save();

Expand All @@ -76,6 +73,11 @@ public function createUser()
// Attach company
$user->companies()->attach(1);

Artisan::call('user:seed', [
'user' => $user->id,
'company' => 1,
]);

$this->command->info('Admin user created.');
}
}
63 changes: 0 additions & 63 deletions tests/Feature/Auth/LoginTest.php

This file was deleted.

8 changes: 4 additions & 4 deletions tests/Feature/Auth/PermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests\Feature\Auth;

use App\Models\Auth\Permission;
use App\Jobs\Auth\CreatePermission;
use Tests\Feature\FeatureTestCase;

class PermissionsTest extends FeatureTestCase
Expand Down Expand Up @@ -35,7 +35,7 @@ public function testItShouldCreatePermission()

public function testItShouldSeePermissionUpdatePage()
{
$permission = Permission::create($this->getPermissionRequest());
$permission = $this->dispatch(new CreatePermission($this->getPermissionRequest()));

$this->loginAs()
->get(route('permissions.edit', ['permission' => $permission->id]))
Expand All @@ -47,7 +47,7 @@ public function testItShouldUpdatePermission()
{
$request = $this->getPermissionRequest();

$permission = Permission::create($request);
$permission = $this->dispatch(new CreatePermission($request));

$request['name'] = $this->faker->name;

Expand All @@ -60,7 +60,7 @@ public function testItShouldUpdatePermission()

public function testItShouldDeletePermission()
{
$permission = Permission::create($this->getPermissionRequest());
$permission = $this->dispatch(new CreatePermission($this->getPermissionRequest()));

$this->loginAs()
->delete(route('permissions.destroy', $permission->id))
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/Auth/RolesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Tests\Feature\Auth;

use App\Jobs\Auth\CreateRole;
use App\Models\Auth\Permission;
use App\Models\Auth\Role;
use Tests\Feature\FeatureTestCase;

class RolesTest extends FeatureTestCase
Expand Down Expand Up @@ -36,7 +36,7 @@ public function testItShouldCreateRole()

public function testItShouldSeeRoleUpdatePage()
{
$role = Role::create($this->getRoleRequest());
$role = $this->dispatch(new CreateRole($this->getRoleRequest()));

$this->loginAs()
->get(route('roles.edit', ['role' => $role->id]))
Expand All @@ -48,7 +48,7 @@ public function testItShouldUpdateRole()
{
$request = $this->getRoleRequest();

$role = Role::create($request);
$role = $this->dispatch(new CreateRole($request));

$request['name'] = $this->faker->name;

Expand All @@ -61,7 +61,7 @@ public function testItShouldUpdateRole()

public function testItShouldDeleteRole()
{
$role = Role::create($this->getRoleRequest());
$role = $this->dispatch(new CreateRole($this->getRoleRequest()));

$this->loginAs()
->delete(route('roles.destroy', $role->id))
Expand Down
50 changes: 44 additions & 6 deletions tests/Feature/Auth/UsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace Tests\Feature\Auth;

use App\Jobs\Auth\CreateUser;
use App\Models\Auth\Role;
use App\Models\Auth\User;
use Tests\Feature\FeatureTestCase;

class UsersTest extends FeatureTestCase
{

public function testItShouldSeeUserListPage()
{
$this->loginAs()
Expand Down Expand Up @@ -36,7 +35,7 @@ public function testItShouldCreateUser()

public function testItShouldSeeUserUpdatePage()
{
$user = User::create($this->getUserRequest());
$user = $this->dispatch(new CreateUser($this->getUserRequest()));

$this->loginAs()
->get(route('users.edit', ['user' => $user->id]))
Expand All @@ -48,7 +47,7 @@ public function testItShouldUpdateUser()
{
$request = $this->getUserRequest();

$user = User::create($request);
$user = $this->dispatch(new CreateUser($request));

$request['name'] = $this->faker->name;

Expand All @@ -61,7 +60,7 @@ public function testItShouldUpdateUser()

public function testItShouldDeleteUser()
{
$user = User::create($this->getUserRequest());
$user = $this->dispatch(new CreateUser($this->getUserRequest()));

$this->loginAs()
->delete(route('users.destroy', $user->id))
Expand All @@ -70,6 +69,45 @@ public function testItShouldDeleteUser()
$this->assertFlashLevel('success');
}

public function testItShouldSeeLoginPage()
{
$this->get(route('login'))
->assertStatus(200)
->assertSeeText(trans('auth.login_to'));
}

public function testItShouldLoginUser()
{
$user = $this->dispatch(new CreateUser($this->getUserRequest()));

$this->post(route('login'), ['email' => $user->email, 'password' => $user->password])
->assertStatus(200);

$this->isAuthenticated($user->user);
}

public function testItShouldNotLoginUser()
{
$user = $this->dispatch(new CreateUser($this->getUserRequest()));

$this->post(route('login'), ['email' => $user->email, $this->faker->password()])
->assertStatus(302);

$this->assertGuest();
}

public function testItShouldLogoutUser()
{
$user = $this->dispatch(new CreateUser($this->getUserRequest()));

$this->loginAs()
->get(route('logout', $user->id))
->assertStatus(302)
->assertRedirect(route('login'));

$this->assertGuest();
}

private function getUserRequest()
{
$password = $this->faker->password();
Expand All @@ -80,7 +118,7 @@ private function getUserRequest()
'password' => $password,
'password_confirmation' => $password,
'locale' => 'en-GB',
'companies' => [session('company_id')],
'companies' => [$this->company->id],
'roles' => Role::take(1)->pluck('id')->toArray(),
'enabled' => $this->faker->boolean ? 1 : 0,
];
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Banking/AccountsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Feature\Banking;

use App\Jobs\Banking\CreateAccount;
use App\Models\Banking\Account;
use Tests\Feature\FeatureTestCase;

Expand Down Expand Up @@ -34,7 +35,7 @@ public function testItShouldCreateAccount()

public function testItShouldSeeAccountUpdatePage()
{
$account = Account::create($this->getAccountRequest());
$account = $this->dispatch(new CreateAccount($this->getAccountRequest()));

$this->loginAs()
->get(route('accounts.edit', ['account' => $account->id]))
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/Banking/ReconciliationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests\Feature\Banking;

use App\Models\Banking\Reconciliation;
use App\Jobs\Banking\CreateReconciliation;
use Tests\Feature\FeatureTestCase;

class ReconciliationsTest extends FeatureTestCase
Expand Down Expand Up @@ -34,7 +34,7 @@ public function testItShouldCreateReconciliation()

public function testItShouldSeeReconciliationUpdatePage()
{
$reconciliation = Reconciliation::create($this->getReconciliationRequest());
$reconciliation = $this->dispatch(new CreateReconciliation($this->getReconciliationRequest()));

$this->loginAs()
->get(route('reconciliations.edit', ['reconciliation' => $reconciliation->id]))
Expand All @@ -46,7 +46,7 @@ public function testItShouldUpdateReconciliation()
{
$request = $this->getReconciliationRequest();

$reconciliation= Reconciliation::create($request);
$reconciliation= $this->dispatch(new CreateReconciliation($request));

$request['description'] = $this->faker->text(10);

Expand All @@ -59,7 +59,7 @@ public function testItShouldUpdateReconciliation()

public function testItShouldDeleteReconciliation()
{
$reconciliation = Reconciliation::create($this->getReconciliationRequest());
$reconciliation = $this->dispatch(new CreateReconciliation($this->getReconciliationRequest()));

$this->loginAs()
->delete(route('reconciliations.destroy', ['reconciliation' => $reconciliation]))
Expand Down

0 comments on commit 58048a1

Please sign in to comment.