Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Nov 18, 2019
1 parent 63ab577 commit 2cdc431
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 154 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ robots.txt
_ide_helper.php
.phpstorm.meta.php
/storage/debugbar/*
.phpunit.result.cache
2 changes: 1 addition & 1 deletion app/Jobs/Banking/CreateReconciliation.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function handle()
$transactions = $this->request->get('transactions');

$reconciliation = Reconciliation::create([
'company_id' => session('company_id'),
'company_id' => $this->request['company_id'],
'account_id' => $this->request->get('account_id'),
'started_at' => $this->request->get('started_at'),
'ended_at' => $this->request->get('ended_at'),
Expand Down
26 changes: 0 additions & 26 deletions database/factories/ItemFacorty.php

This file was deleted.

21 changes: 21 additions & 0 deletions database/factories/ItemFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use App\Models\Auth\User;
use App\Models\Common\Item;
use Faker\Generator as Faker;

$factory->define(Item::class, function (Faker $faker) {
$user = User::first();
$company = $user->companies()->first();

return [
'company_id' => $company->id,
'name' => $faker->text(15),
'description' => $faker->text(100),
'purchase_price' => $faker->randomFloat(2, 10, 20),
'sale_price' => $faker->randomFloat(2, 10, 20),
'category_id' => $company->categories()->type('item')->pluck('id')->first(),
'tax_id' => '',
'enabled' => $faker->boolean ? 1 : 0
];
});
28 changes: 28 additions & 0 deletions database/factories/TransactionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use App\Models\Auth\User;
use App\Models\Banking\Transaction;
use Faker\Generator as Faker;
use Illuminate\Http\UploadedFile;

$factory->define(Transaction::class, function (Faker $faker) {
$user = User::first();
$company = $user->companies()->first();

$attachment = UploadedFile::fake()->create('image.jpg');

return [
'company_id' => $company->id,
'type' => 'income',
'account_id' => setting('default.account'),
'paid_at' => $faker->date(),
'amount' => $faker->randomFloat(2, 2),
'currency_code' => setting('default.currency'),
'currency_rate' => '1',
'description' => $faker->text(5),
'category_id' => $company->categories()->type('income')->first()->id,
'reference' => $faker->text(5),
'payment_method' => setting('default.payment_method'),
'attachment' => $attachment,
];
});
42 changes: 17 additions & 25 deletions database/seeds/TestCompany.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace Database\Seeds;

use App\Abstracts\Model;
use App\Models\Auth\User;
use App\Jobs\Auth\CreateUser;
use App\Models\Common\Company;
use Artisan;
use Date;
use App\Traits\Jobs;
use Illuminate\Database\Seeder;

class TestCompany extends Seeder
{
use Jobs;

/**
* Run the database seeds.
*
Expand All @@ -37,17 +38,17 @@ private function createCompany()

setting()->setExtraColumns(['company_id' => '1']);
setting()->set([
'company.name' => 'Test Inc.',
'company.email' => 'info@test.com',
'company.name' => 'Test Company',
'company.email' => 'test@company.com',
'company.address' => 'New Street 1254',
'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' => '0',
'schedule.send_bill_reminder' => '0',
'schedule.send_invoice_reminder' => '1',
'schedule.send_bill_reminder' => '1',
'wizard.completed' => '1',
'contact.type.customer' => 'customer',
'contact.type.vendor' => 'vendor',
Expand All @@ -59,25 +60,16 @@ private function createCompany()

public function createUser()
{
// Create user
$user = User::create([
'name' => 'Admin',
'email' => 'admin@akaunting.com',
$this->dispatch(new CreateUser([
'name' => 'Test',
'email' => 'test@company.com',
'password' => '123456',
'last_logged_in_at' => Date::now(),
]);

// Attach Role
$user->roles()->attach(1);

// Attach company
$user->companies()->attach(1);

Artisan::call('user:seed', [
'user' => $user->id,
'company' => 1,
]);
'locale' => 'en-GB',
'companies' => ['1'],
'roles' => ['1'],
'enabled' => '1',
]));

$this->command->info('Admin user created.');
$this->command->info('Test user created.');
}
}
2 changes: 1 addition & 1 deletion tests/Feature/Auth/UsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private function getUserRequest()
'password_confirmation' => $password,
'locale' => 'en-GB',
'companies' => [$this->company->id],
'roles' => Role::take(1)->pluck('id')->toArray(),
'roles' => ['1'],
'enabled' => $this->faker->boolean ? 1 : 0,
];
}
Expand Down
13 changes: 6 additions & 7 deletions tests/Feature/Banking/AccountsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Tests\Feature\Banking;

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

class AccountsTest extends FeatureTestCase
Expand Down Expand Up @@ -47,7 +46,7 @@ public function testItShouldUpdateAccount()
{
$request = $this->getAccountRequest();

$account= Account::create($request);
$account = $this->dispatch(new CreateAccount($request));

$request['name'] = $this->faker->text(5);

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

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

$this->loginAs()
->delete(route('accounts.destroy', ['account' => $account]))
Expand All @@ -74,13 +73,13 @@ private function getAccountRequest()
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(5),
'number' => '1',
'currency_code' => setting('default.currency'),
'opening_balance' => 0,
'number' => (string) $this->faker->randomNumber(2),
'currency_code' => setting('default.currency', 'USD'),
'opening_balance' => '0',
'bank_name' => $this->faker->text(5),
'bank_phone' => null,
'bank_address' => null,
'default_account' => $this->faker->randomElement(['yes', 'no']),
'default_account' => 0,
'enabled' => $this->faker->boolean ? 1 : 0,
];
}
Expand Down
1 change: 0 additions & 1 deletion tests/Feature/Banking/ReconciliationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public function testItShouldDeleteReconciliation()
$this->assertFlashLevel('success');
}


private function getReconciliationRequest()
{
return [
Expand Down
62 changes: 17 additions & 45 deletions tests/Feature/Banking/TransfersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Tests\Feature\Banking;

use App\Jobs\Banking\CreateTransaction;
use App\Jobs\Banking\CreateTransfer;
use App\Models\Banking\Transfer;
use Illuminate\Http\UploadedFile;
use Tests\Feature\FeatureTestCase;

Expand All @@ -27,11 +27,9 @@ public function testItShouldSeeTransferCreatePage()

public function testItShouldCreateTransfer()
{
// Create income
$income_transaction = $this->dispatch(new CreateTransaction($this->getIncomeRequest()));
$income_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('income')));

// Create expense
$expense_transaction = $this->dispatch(new CreateTransaction($this->getExpenseRequest()));
$expense_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('expense')));

$this->loginAs()
->post(route('transfers.store'), $this->getTransferRequest($income_transaction, $expense_transaction))
Expand All @@ -42,31 +40,27 @@ public function testItShouldCreateTransfer()

public function testItShouldSeeTransferUpdatePage()
{
// Create income
$income_transaction = $this->dispatch(new CreateTransaction($this->getIncomeRequest()));
$income_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('income')));

// Create expense
$expense_transaction = $this->dispatch(new CreateTransaction($this->getExpenseRequest()));
$expense_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('expense')));

$transfer = $this->dispatch(new CreateTransfer($this->getTransferRequest($income_transaction, $expense_transaction)));
$transfer = Transfer::create($this->getTransferRequest($income_transaction, $expense_transaction));

$this->loginAs()
->get(route('transfers.edit', ['transfer' => $transfer->id]))
->assertStatus(200)
->assertSee($expense_transaction->description);
->assertSee($transfer->description);
}

public function testItShouldUpdateTransfer()
{
// Create income
$income_transaction = $this->dispatch(new CreateTransaction($this->getIncomeRequest()));
$income_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('income')));

// Create expense
$expense_transaction = $this->dispatch(new CreateTransaction($this->getExpenseRequest()));
$expense_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('expense')));

$request = $this->getTransferRequest($income_transaction, $expense_transaction);

$transfer = $this->dispatch(new CreateTransfer($request));
$transfer = Transfer::create($request);

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

Expand All @@ -79,13 +73,11 @@ public function testItShouldUpdateTransfer()

public function testItShouldDeleteTransfer()
{
// Create income
$income_transaction = $this->dispatch(new CreateTransaction($this->getIncomeRequest()));
$income_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('income')));

// Create expense
$expense_transaction = $this->dispatch(new CreateTransaction($this->getExpenseRequest()));
$expense_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('expense')));

$transfer = $this->dispatch(new CreateTransfer($this->getTransferRequest($income_transaction, $expense_transaction)));
$transfer = Transfer::create($this->getTransferRequest($income_transaction, $expense_transaction));

$this->loginAs()
->delete(route('transfers.destroy', ['transfer' => $transfer->id]))
Expand All @@ -112,43 +104,23 @@ private function getTransferRequest($income_transaction, $expense_transaction)
];
}

private function getIncomeRequest()
private function getTransactionRequest($type)
{
$attachment = UploadedFile::fake()->create('image.jpg');

return [
'company_id' => $this->company->id,
'type' => 'income',
'type' => $type,
'account_id' => setting('default.account'),
'paid_at' => $this->faker->date(),
'amount' => $this->faker->randomFloat(2, 2),
'currency_code' => setting('default.currency'),
'currency_rate' => '1',
'description' => $this->faker->text(5),
'category_id' => $this->company->categories()->type('income')->first()->id,
'category_id' => $this->company->categories()->type($type)->first()->id,
'reference' => $this->faker->text(5),
'payment_method' => setting('default.payment_method'),
'attachment' => $attachment
];
}

private function getExpenseRequest()
{
$attachment = UploadedFile::fake()->create('image.jpg');

return [
'company_id' => $this->company->id,
'type' => 'expense',
'account_id' => setting('default.account'),
'paid_at' => $this->faker->date(),
'amount' => $this->faker->randomFloat(2, 2),
'currency_code' => setting('default.currency'),
'currency_rate' => '1',
'description' => $this->faker->text(5),
'category_id' => $this->company->categories()->type('expense')->first()->id,
'payment_method' => setting('default.payment_method'),
'reference' => $this->faker->text(5),
'attachment' => $attachment
'attachment' => $attachment,
];
}
}

0 comments on commit 2cdc431

Please sign in to comment.