make sure randomly selected journals match prerequisites.

This commit is contained in:
James Cole
2018-03-02 17:07:32 +01:00
parent 139c2284b8
commit 36113f84be
80 changed files with 728 additions and 281 deletions

View File

@@ -66,19 +66,6 @@ class BudgetFactoryTest extends TestCase
}
/**
* Put in unknown, get NULL
*
* @covers \FireflyIII\Factory\BudgetFactory
*/
public function testFindUnknown()
{
/** @var BudgetFactory $factory */
$factory = app(BudgetFactory::class);
$factory->setUser($this->user());
$this->assertNull($factory->find(null, 'I dont exist.'.rand(1,000)));
}
/**
* Put in NULL, will find NULL.
*
@@ -94,4 +81,17 @@ class BudgetFactoryTest extends TestCase
}
/**
* Put in unknown, get NULL
*
* @covers \FireflyIII\Factory\BudgetFactory
*/
public function testFindUnknown()
{
/** @var BudgetFactory $factory */
$factory = app(BudgetFactory::class);
$factory->setUser($this->user());
$this->assertNull($factory->find(null, 'I dont exist.' . rand(1, 000)));
}
}

View File

@@ -49,7 +49,8 @@ class TransactionCurrencyFactoryTest extends TestCase
*/
public function testFindByCode()
{
$currency = TransactionCurrency::find(1);
// ;
$currency = TransactionCurrency::inRandomOrder()->whereNull('deleted_at')->first();
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
$result = $factory->find(null, $currency->code);
@@ -61,7 +62,7 @@ class TransactionCurrencyFactoryTest extends TestCase
*/
public function testFindByID()
{
$currency = TransactionCurrency::find(1);
$currency = TransactionCurrency::inRandomOrder()->whereNull('deleted_at')->first();
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
$result = $factory->find($currency->id, null);

View File

@@ -258,9 +258,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextDataUploadConfig()
{
// data
$config = ['stage' => 'upload-config'];
$config = ['stage' => 'upload-config'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -289,9 +289,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextDataUploadInvalid()
{
// data
$config = ['stage' => 'ksksjje'];
$config = ['stage' => 'ksksjje'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -313,9 +313,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextDataUploadMap()
{
// data:
$config = ['stage' => 'map'];
$config = ['stage' => 'map'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -344,9 +344,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextDataUploadReady()
{
// data
$config = ['stage' => 'ready'];
$config = ['stage' => 'ready'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -368,9 +368,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextDataUploadRoles()
{
// data
$config = ['stage' => 'roles'];
$config = ['stage' => 'roles'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -397,9 +397,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextViewInitial()
{
// data
$config = ['stage' => 'initial'];
$config = ['stage' => 'initial'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -426,9 +426,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextViewInvalid()
{
// data
$config = ['stage' => 'slkds903ms90k'];
$config = ['stage' => 'slkds903ms90k'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -450,9 +450,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextViewMap()
{
// data
$config = ['stage' => 'map'];
$config = ['stage' => 'map'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -491,9 +491,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextViewReady()
{
// data
$config = ['stage' => 'ready'];
$config = ['stage' => 'ready'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -515,9 +515,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextViewRoles()
{
// data
$config = ['stage' => 'roles'];
$config = ['stage' => 'roles'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -542,9 +542,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextViewUploadConfig()
{
// data
$config = ['stage' => 'upload-config'];
$config = ['stage' => 'upload-config'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -569,9 +569,9 @@ class FileConfiguratorTest extends TestCase
public function testGetWarningMessage()
{
// data
$config = ['stage' => 'upload-config'];
$config = ['stage' => 'upload-config'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -609,9 +609,9 @@ class FileConfiguratorTest extends TestCase
public function testIsJobConfiguredFalse()
{
// data
$config = ['stage' => 'upload-config'];
$config = ['stage' => 'upload-config'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -648,9 +648,9 @@ class FileConfiguratorTest extends TestCase
public function testIsJobConfiguredTrue()
{
// data
$config = ['stage' => 'ready'];
$config = ['stage' => 'ready'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);

View File

@@ -155,7 +155,7 @@ class AmountTest extends TestCase
'€1,44' => '1.44',
'(33.52)' => '-33.52',
'€(63.12)' => '-63.12',
'($182.77)' => '-182.77',
'($182.77)' => '-182.77',
];
foreach ($values as $value => $expected) {
$converter = new Amount;

View File

@@ -57,7 +57,7 @@ class AssetAccountIbansTest extends TestCase
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => strval(trans('import.map_do_not_map')),
0 => strval(trans('import.map_do_not_map')),
53 => 'Else',
17 => 'IBAN (Something)',
];

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace Tests\Unit\Import\MapperPreProcess;
use FireflyIII\Import\MapperPreProcess\TagsComma;
use FireflyIII\Import\MapperPreProcess\TagsSpace;
use Tests\TestCase;

View File

@@ -1232,7 +1232,7 @@ class BinderTest extends TestCase
{
$tagRepos = $this->mock(TagRepositoryInterface::class);
$tagRepos->shouldReceive('setUser');
$tags = $this->user()->tags()->whereIn('id', [1, 2])->get(['tags.*']);
$tags = $this->user()->tags()->whereIn('id', [1, 2])->get(['tags.*']);
$tagRepos->shouldReceive('get')->once()->andReturn($tags);
Route::middleware(Binder::class)->any(
@@ -1244,7 +1244,6 @@ class BinderTest extends TestCase
$names = join(',', $tags->pluck('tag')->toArray());
$this->be($this->user());
$response = $this->get('/_test/binder/' . $names);
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());

View File

@@ -46,7 +46,6 @@ class IsDemoUserTest extends TestCase
}
/**
* @covers \FireflyIII\Http\Middleware\IsDemoUser::handle
*/

View File

@@ -0,0 +1,99 @@
<?php
/**
* AccountDestroyServiceClass.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Services\Internal\Destroy;
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
use Tests\TestCase;
/**
* Class AccountDestroyServiceTest
*/
class AccountDestroyServiceTest extends TestCase
{
/**
* @covers \FireflyIII\Services\Internal\Destroy\AccountDestroyService
*/
public function testDestroyBasic()
{
$account = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
/** @var AccountDestroyService $service */
$service = app(AccountDestroyService::class);
$service->destroy($account, null);
$this->assertDatabaseMissing('accounts', ['id' => $account->id, 'deleted_at' => null]);
}
/**
* @covers \FireflyIII\Services\Internal\Destroy\AccountDestroyService
*/
public function testDestroyDontMove()
{
// create objects:
$account = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
Transaction::create(['account_id' => $account->id, 'transaction_journal_id' => 1, 'amount' => 10, 'transaction_currency_id' => 1]);
// mock delete service:
$service = $this->mock(JournalDestroyService::class);
$service->shouldReceive('destroy')->once();
/** @var AccountDestroyService $service */
$service = app(AccountDestroyService::class);
$service->destroy($account, null);
$this->assertDatabaseMissing('accounts', ['id' => $account->id, 'deleted_at' => null]);
}
/**
* @covers \FireflyIII\Services\Internal\Destroy\AccountDestroyService
*/
public function testDestroyMove()
{
$account = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
$move = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
$transaction = Transaction::create(['account_id' => $account->id, 'transaction_journal_id' => 1, 'amount' => 10, 'transaction_currency_id' => 1]);
/** @var AccountDestroyService $service */
$service = app(AccountDestroyService::class);
$service->destroy($account, $move);
$this->assertDatabaseMissing('accounts', ['id' => $account->id, 'deleted_at' => null]);
$this->assertDatabaseMissing('transactions', ['account_id' => $account->id]);
$this->assertDatabaseHas('transactions', ['id' => $transaction->id, 'account_id' => $move->id]);
}
}

View File

@@ -0,0 +1,199 @@
<?php
/**
* AccountUpdateServiceTest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Services\Internal\Update;
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\Note;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Services\Internal\Update\AccountUpdateService;
use Tests\TestCase;
/**
* Class AccountUpdateServiceTest
*/
class AccountUpdateServiceTest extends TestCase
{
/**
* @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
*/
public function testDeleteExistingIB()
{
/** @var Account $account */
$account = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
$opposing = $this->user()->accounts()->first();
$journal = TransactionJournal::create(
['user_id' => $this->user()->id, 'transaction_type_id' => 4, 'transaction_currency_id' => 1, 'description' => 'IB',
'date' => '2018-01-01', 'completed' => true,
]
);
// transactions:
Transaction::create(
['account_id' => $account->id, 'transaction_journal_id' => $journal->id,
'transaction_currency_id' => 1, 'amount' => '100', 'identifier' => 0,]
);
Transaction::create(
['account_id' => $opposing->id, 'transaction_journal_id' => $journal->id,
'transaction_currency_id' => 1, 'amount' => '-100', 'identifier' => 0,]
);
$data = [
'name' => 'Some new name #' . rand(1, 1000),
'active' => true,
'virtualBalance' => '0',
'iban' => null,
'accountRole' => 'defaultAsset',
'notes' => 'Hello',
'currency_id' => 1,
];
/** @var AccountUpdateService $service */
$service = app(AccountUpdateService::class);
$account = $service->update($account, $data);
$this->assertEquals($data['name'], $account->name);
$this->assertEquals(0, $account->transactions()->count());
/** @var Note $note */
$note = $account->notes()->first();
$this->assertEquals($data['notes'], $note->text);
}
/**
* @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
*/
public function testUpdateBasic()
{
/** @var Account $account */
$account = $this->user()->accounts()->first();
$data = [
'name' => 'Some new name #' . rand(1, 1000),
'active' => true,
'virtualBalance' => '0',
'iban' => null,
'accountRole' => 'defaultAsset',
];
/** @var AccountUpdateService $service */
$service = app(AccountUpdateService::class);
$account = $service->update($account, $data);
$this->assertEquals($data['name'], $account->name);
}
/**
* @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
*/
public function testUpdateExistingIB()
{
/** @var Account $account */
$account = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
$opposing = $this->user()->accounts()->first();
$journal = TransactionJournal::create(
['user_id' => $this->user()->id, 'transaction_type_id' => 4, 'transaction_currency_id' => 1, 'description' => 'IB',
'date' => '2018-01-01', 'completed' => true,
]
);
// transactions:
Transaction::create(
['account_id' => $account->id, 'transaction_journal_id' => $journal->id,
'transaction_currency_id' => 1, 'amount' => '100', 'identifier' => 0,]
);
Transaction::create(
['account_id' => $opposing->id, 'transaction_journal_id' => $journal->id,
'transaction_currency_id' => 1, 'amount' => '-100', 'identifier' => 0,]
);
$data = [
'name' => 'Some new name #' . rand(1, 1000),
'active' => true,
'virtualBalance' => '0',
'iban' => null,
'accountRole' => 'defaultAsset',
'openingBalance' => '105',
'openingBalanceDate' => new Carbon('2018-01-01'),
'notes' => 'Hello',
'currency_id' => 1,
];
/** @var AccountUpdateService $service */
$service = app(AccountUpdateService::class);
$account = $service->update($account, $data);
$this->assertEquals($data['name'], $account->name);
$this->assertEquals(1, $account->transactions()->count());
$this->assertEquals(105, $account->transactions()->first()->amount);
/** @var Note $note */
$note = $account->notes()->first();
$this->assertEquals($data['notes'], $note->text);
}
/**
* @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
*/
public function testUpdateNewIB()
{
/** @var Account $account */
$account = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
$data = [
'name' => 'Some new name #' . rand(1, 1000),
'active' => true,
'virtualBalance' => '0',
'iban' => null,
'accountRole' => 'defaultAsset',
'openingBalance' => '100',
'openingBalanceDate' => new Carbon('2018-01-01'),
'notes' => 'Hello',
'currency_id' => 1,
];
/** @var AccountUpdateService $service */
$service = app(AccountUpdateService::class);
$account = $service->update($account, $data);
$this->assertEquals($data['name'], $account->name);
$this->assertEquals(1, $account->transactions()->count());
$this->assertEquals(100, $account->transactions()->first()->amount);
/** @var Note $note */
$note = $account->notes()->first();
$this->assertEquals($data['notes'], $note->text);
}
}

View File

@@ -0,0 +1,133 @@
<?php
/**
* JournalUpdateServiceTest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Services\Internal\Update;
use Carbon\Carbon;
use FireflyIII\Factory\BillFactory;
use FireflyIII\Factory\TagFactory;
use FireflyIII\Factory\TransactionFactory;
use FireflyIII\Factory\TransactionJournalMetaFactory;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Services\Internal\Update\JournalUpdateService;
use FireflyIII\Services\Internal\Update\TransactionUpdateService;
use Tests\TestCase;
/**
* Class JournalUpdateServiceTest
*/
class JournalUpdateServiceTest extends TestCase
{
/**
* @covers \FireflyIII\Services\Internal\Update\JournalUpdateService
* @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
*/
public function testUpdateBasic()
{
// mock other stuff:
$transactionFactory = $this->mock(TransactionFactory::class);
$transactionService = $this->mock(TransactionUpdateService::class);
$billFactory = $this->mock(BillFactory::class);
$tagFactory = $this->mock(TagFactory::class);
$metaFactory = $this->mock(TransactionJournalMetaFactory::class);
// mock calls
$billFactory->shouldReceive('setUser');
$billFactory->shouldReceive('find')->andReturn(null);
$transactionService->shouldReceive('setUser');
$transactionFactory->shouldReceive('setUser');
$tagFactory->shouldReceive('setUser');
$metaFactory->shouldReceive('setUser');
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 2)->first();
$data = [
'description' => 'Updated journal #' . rand(1, 1000),
'date' => new Carbon('2018-01-01'),
'bill_id' => null,
'bill_name' => null,
'tags' => [],
'notes' => 'Hello',
'transactions' => [],
];
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$result = $service->update($journal, $data);
$this->assertEquals($data['description'], $result->description);
$this->assertEquals(0, $result->transactions()->count());
}
/**
* @covers \FireflyIII\Services\Internal\Update\JournalUpdateService
* @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
*/
public function testUpdateLotsOfTransactions()
{
// mock other stuff:
$transactionFactory = $this->mock(TransactionFactory::class);
$transactionService = $this->mock(TransactionUpdateService::class);
$billFactory = $this->mock(BillFactory::class);
$tagFactory = $this->mock(TagFactory::class);
$metaFactory = $this->mock(TransactionJournalMetaFactory::class);
// mock calls
$billFactory->shouldReceive('setUser');
$billFactory->shouldReceive('find')->andReturn(null);
$transactionService->shouldReceive('setUser');
$transactionFactory->shouldReceive('setUser');
$transactionService->shouldReceive('update')->times(2);
$transactionFactory->shouldReceive('createPair')->times(2);
$tagFactory->shouldReceive('setUser');
$metaFactory->shouldReceive('setUser');
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->skip(4)->where('transaction_type_id', 1)->first();
$data = [
'description' => 'Updated journal #' . rand(1, 1000),
'date' => new Carbon('2018-01-01'),
'bill_id' => null,
'bill_name' => null,
'tags' => [],
'notes' => 'Hello',
'transactions' => [
['identifier' => 0],
['identifier' => 1],
['identifier' => 2],
],
];
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$result = $service->update($journal, $data);
$this->assertEquals($data['description'], $result->description);
$this->assertEquals(2, $result->transactions()->count());
}
}

View File

@@ -39,14 +39,17 @@ class AddTagTest extends TestCase
*/
public function testActExistingTag()
{
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => 2, 'transaction_journal_id' => 1]);
$tag = Tag::inRandomOrder()->whereNull('deleted_at')->first();
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->tags()->sync([$tag->id]);
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
$ruleAction = new RuleAction;
$ruleAction->action_value = 'housing';
$journal = TransactionJournal::find(1);
$action = new AddTag($ruleAction);
$result = $action->act($journal);
$ruleAction->action_value = $tag->tag;
$action = new AddTag($ruleAction);
$result = $action->act($journal);
$this->assertFalse($result);
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => 2, 'transaction_journal_id' => 1]);
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
}
/**
@@ -54,15 +57,15 @@ class AddTagTest extends TestCase
*/
public function testActNoTag()
{
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$ruleAction = new RuleAction;
$ruleAction->action_value = 'TestTag-' . rand(1, 1000);
$journal = TransactionJournal::find(1);
$action = new AddTag($ruleAction);
$result = $action->act($journal);
$this->assertTrue($result);
// find newly created tag:
$tag = Tag::orderBy('id', 'DESC')->first();
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => 1]);
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
}
}

View File

@@ -41,13 +41,13 @@ class AppendDescriptionTest extends TestCase
$ruleAction = new RuleAction;
$ruleAction->action_value = 'APPEND';
$journal = TransactionJournal::find(1);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$oldDescription = $journal->description;
$action = new AppendDescription($ruleAction);
$result = $action->act($journal);
$this->assertTrue($result);
$journal = TransactionJournal::find(1);
$journal = TransactionJournal::find($journal->id);
$this->assertEquals($oldDescription . 'APPEND', $journal->description);
}
}

View File

@@ -39,7 +39,7 @@ class ClearBudgetTest extends TestCase
public function testAct()
{
// associate budget with journal:
$journal = TransactionJournal::find(5);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$journal->budgets()->save($budget);
$this->assertGreaterThan(0, $journal->budgets()->count());

View File

@@ -39,7 +39,7 @@ class ClearCategoryTest extends TestCase
public function testAct()
{
// associate budget with journal:
$journal = TransactionJournal::find(5);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$category = $journal->user->categories()->first();
$journal->budgets()->save($category);
$this->assertGreaterThan(0, $journal->categories()->count());

View File

@@ -40,7 +40,7 @@ class ClearNotesTest extends TestCase
public function testAct()
{
// give journal a note:
$journal = TransactionJournal::find(6);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$note = $journal->notes()->first();
if (is_null($note)) {
$note = new Note;

View File

@@ -41,7 +41,7 @@ class PrependDescriptionTest extends TestCase
// get journal, give fixed description
$description = 'text' . rand(1, 1000);
$prepend = 'prepend' . rand(1, 1234);
$journal = TransactionJournal::find(7);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->description = $description;
$journal->save();
@@ -51,7 +51,7 @@ class PrependDescriptionTest extends TestCase
$action = new PrependDescription($ruleAction);
$result = $action->act($journal);
$this->assertTrue($result);
$journal = TransactionJournal::find(7);
$journal = TransactionJournal::find($journal->id);
// assert result
$this->assertEquals($prepend . $description, $journal->description);

View File

@@ -40,7 +40,7 @@ class PrependNotesTest extends TestCase
public function testAct()
{
// give journal some notes.
$journal = TransactionJournal::find(8);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$note = $journal->notes()->first();
$start = 'Default note text';
$toPrepend = 'This is prepended';
@@ -69,7 +69,7 @@ class PrependNotesTest extends TestCase
public function testActNewNote()
{
// give journal some notes.
$journal = TransactionJournal::find(4);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$note = $journal->notes()->first();
if (!is_null($note)) {
$note->forceDelete();

View File

@@ -68,7 +68,7 @@ class RemoveTagTest extends TestCase
{
// get journal, link al tags:
/** @var TransactionJournal $journal */
$journal = TransactionJournal::find(11);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$tags = $journal->user->tags()->get();
$journal->tags()->sync($tags->pluck('id')->toArray());
$this->assertEquals($tags->count(), $journal->tags()->get()->count());

View File

@@ -41,7 +41,7 @@ class SetBudgetTest extends TestCase
public function testAct()
{
// get journal, remove all budgets
$journal = TransactionJournal::find(12);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('setUser');

View File

@@ -24,7 +24,6 @@ namespace Tests\Unit\TransactionRules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\TransactionRules\Actions\SetCategory;
use Tests\TestCase;
@@ -40,7 +39,7 @@ class SetCategoryTest extends TestCase
public function testAct()
{
// get journal, remove all budgets
$journal = TransactionJournal::find(13);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$this->assertEquals(0, $journal->categories()->count());

View File

@@ -41,7 +41,7 @@ class SetDescriptionTest extends TestCase
// get journal, give fixed description
$description = 'text' . rand(1, 1000);
$newDescription = 'new description' . rand(1, 1234);
$journal = TransactionJournal::find(14);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->description = $description;
$journal->save();
@@ -51,7 +51,7 @@ class SetDescriptionTest extends TestCase
$action = new SetDescription($ruleAction);
$result = $action->act($journal);
$this->assertTrue($result);
$journal = TransactionJournal::find(14);
$journal = TransactionJournal::find($journal->id);
// assert result
$this->assertEquals($newDescription, $journal->description);

View File

@@ -95,8 +95,8 @@ class SetDestinationAccountTest extends TestCase
*/
public function testActWithdrawalExisting()
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
// select split transactions to exclude them later:
$set = TransactionJournal::where('transaction_type_id', $type->id)->get(['transaction_journals.*']);

View File

@@ -40,7 +40,7 @@ class SetNotesTest extends TestCase
public function testAct()
{
// give journal a note:
$journal = TransactionJournal::find(15);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$note = $journal->notes()->first();
if (is_null($note)) {
$note = new Note;
@@ -69,7 +69,7 @@ class SetNotesTest extends TestCase
public function testActNoNotes()
{
// give journal a note:
$journal = TransactionJournal::find(16);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->forceDelete();
$this->assertEquals(0, $journal->notes()->count());

View File

@@ -49,7 +49,7 @@ class SetSourceAccountTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$type = TransactionType::whereType(TransactionType::DEPOSIT)->first();
$type = TransactionType::whereType(TransactionType::DEPOSIT)->first();
// select split transactions to exclude them later:
$set = TransactionJournal::where('transaction_type_id', $type->id)->get(['transaction_journals.*']);
@@ -107,11 +107,11 @@ class SetSourceAccountTest extends TestCase
}
}
$sourceTr = $journal->transactions()->where('amount', '<', 0)->first();
$source = $sourceTr->account;
$user = $journal->user;
$accountType = AccountType::whereType(AccountType::ASSET)->first();
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first();
$sourceTr = $journal->transactions()->where('amount', '<', 0)->first();
$source = $sourceTr->account;
$user = $journal->user;
$accountType = AccountType::whereType(AccountType::ASSET)->first();
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first();
$this->assertNotEquals($source->id, $account->id);

View File

@@ -36,7 +36,7 @@ class BudgetIsTest extends TestCase
*/
public function testTriggeredJournal()
{
$journal = TransactionJournal::find(17);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$journal->budgets()->save($budget);
@@ -52,7 +52,7 @@ class BudgetIsTest extends TestCase
*/
public function testTriggeredNotJournal()
{
$journal = TransactionJournal::find(18);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$otherBudget = $journal->user->budgets()->where('id', '!=', $budget->id)->first();
$journal->budgets()->detach();
@@ -69,7 +69,7 @@ class BudgetIsTest extends TestCase
*/
public function testTriggeredTransaction()
{
$journal = TransactionJournal::find(19);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->first();
$budget = $journal->user->budgets()->first();

View File

@@ -36,7 +36,7 @@ class CategoryIsTest extends TestCase
*/
public function testTriggeredJournal()
{
$journal = TransactionJournal::find(17);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$journal->categories()->save($category);
@@ -52,7 +52,7 @@ class CategoryIsTest extends TestCase
*/
public function testTriggeredNotJournal()
{
$journal = TransactionJournal::find(18);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$category = $journal->user->categories()->first();
$otherCategory = $journal->user->categories()->where('id', '!=', $category->id)->first();
$journal->categories()->detach();
@@ -69,11 +69,12 @@ class CategoryIsTest extends TestCase
*/
public function testTriggeredTransaction()
{
$journal = TransactionJournal::find(19);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$transaction->categories()->detach();
$transaction->categories()->save($category);
$this->assertEquals(0, $journal->categories()->count());
$this->assertEquals(1, $transaction->categories()->count());

View File

@@ -36,8 +36,12 @@ class FromAccountContainsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(20);
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$count = 0;
while ($count === 0) {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->where('amount', '<', 0)->count();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
}
$account = $transaction->account;
$trigger = FromAccountContains::makeFromStrings($account->name, false);
@@ -50,7 +54,7 @@ class FromAccountContainsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(21);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = FromAccountContains::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);

View File

@@ -36,8 +36,12 @@ class FromAccountEndsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(22);
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$count = 0;
while ($count === 0) {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->where('amount', '<', 0)->count();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
}
$account = $transaction->account;
$trigger = FromAccountEnds::makeFromStrings(substr($account->name, -3), false);
@@ -50,7 +54,7 @@ class FromAccountEndsTest extends TestCase
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(22);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
@@ -64,7 +68,7 @@ class FromAccountEndsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(23);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = FromAccountEnds::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);

View File

@@ -36,7 +36,7 @@ class FromAccountIsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(22);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
@@ -50,7 +50,7 @@ class FromAccountIsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(23);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = FromAccountIs::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);

View File

@@ -36,7 +36,7 @@ class FromAccountStartsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(22);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
@@ -50,7 +50,7 @@ class FromAccountStartsTest extends TestCase
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(22);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
@@ -64,7 +64,7 @@ class FromAccountStartsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(23);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = FromAccountStarts::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);

View File

@@ -36,7 +36,7 @@ class HasAnyBudgetTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(25);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$journal->budgets()->save($budget);
@@ -52,7 +52,7 @@ class HasAnyBudgetTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(24);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->budgets()->detach();
$this->assertEquals(0, $journal->budgets()->count());
$trigger = HasAnyBudget::makeFromStrings('', false);
@@ -65,7 +65,7 @@ class HasAnyBudgetTest extends TestCase
*/
public function testTriggeredTransactions()
{
$journal = TransactionJournal::find(26);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$this->assertEquals(0, $journal->budgets()->count());

View File

@@ -36,7 +36,7 @@ class HasAnyCategoryTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(25);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$journal->categories()->save($category);
@@ -52,7 +52,7 @@ class HasAnyCategoryTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(24);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->categories()->detach();
$this->assertEquals(0, $journal->categories()->count());
$trigger = HasAnyCategory::makeFromStrings('', false);
@@ -65,7 +65,7 @@ class HasAnyCategoryTest extends TestCase
*/
public function testTriggeredTransactions()
{
$journal = TransactionJournal::find(26);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$this->assertEquals(0, $journal->categories()->count());

View File

@@ -36,7 +36,7 @@ class HasAnyTagTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(25);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$tag = $journal->user->tags()->first();
$journal->tags()->detach();
$journal->tags()->save($tag);
@@ -52,7 +52,7 @@ class HasAnyTagTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(24);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->tags()->detach();
$this->assertEquals(0, $journal->tags()->count());
$trigger = HasAnyTag::makeFromStrings('', false);

View File

@@ -36,7 +36,13 @@ class HasAttachmentTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(26);
$count = 0;
while($count === 0) {
// this is kind of cheating but OK.
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->attachments()->count();
}
$attachment = $journal->user->attachments()->first();
$journal->attachments()->save($attachment);
$this->assertEquals(1, $journal->attachments()->count());
@@ -51,7 +57,13 @@ class HasAttachmentTest extends TestCase
*/
public function testTriggeredFalse()
{
$journal = TransactionJournal::find(27);
$count = 0;
while ($count === 0) {
// this is kind of cheating but OK.
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->attachments()->count();
}
$this->assertEquals(0, $journal->attachments()->count());
$trigger = HasAttachment::makeFromStrings('1', false);

View File

@@ -36,7 +36,7 @@ class HasNoBudgetTest extends TestCase
*/
public function testTriggeredBudget()
{
$journal = TransactionJournal::find(28);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$journal->budgets()->save($budget);
@@ -52,7 +52,7 @@ class HasNoBudgetTest extends TestCase
*/
public function testTriggeredNoBudget()
{
$journal = TransactionJournal::find(29);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->budgets()->detach();
$this->assertEquals(0, $journal->budgets()->count());
@@ -66,7 +66,7 @@ class HasNoBudgetTest extends TestCase
*/
public function testTriggeredTransaction()
{
$journal = TransactionJournal::find(30);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->first();
$budget = $journal->user->budgets()->first();

View File

@@ -36,7 +36,7 @@ class HasNoCategoryTest extends TestCase
*/
public function testTriggeredCategory()
{
$journal = TransactionJournal::find(31);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$journal->categories()->save($category);
@@ -52,7 +52,7 @@ class HasNoCategoryTest extends TestCase
*/
public function testTriggeredNoCategory()
{
$journal = TransactionJournal::find(32);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->categories()->detach();
$this->assertEquals(0, $journal->categories()->count());
@@ -66,7 +66,7 @@ class HasNoCategoryTest extends TestCase
*/
public function testTriggeredTransaction()
{
$journal = TransactionJournal::find(33);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->first();
$category = $journal->user->categories()->first();

View File

@@ -36,7 +36,7 @@ class HasNoTagTest extends TestCase
*/
public function testTriggeredNoTag()
{
$journal = TransactionJournal::find(34);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->tags()->detach();
$this->assertEquals(0, $journal->tags()->count());
@@ -50,7 +50,7 @@ class HasNoTagTest extends TestCase
*/
public function testTriggeredTag()
{
$journal = TransactionJournal::find(35);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$tag = $journal->user->tags()->first();
$journal->tags()->detach();
$journal->tags()->save($tag);

View File

@@ -37,7 +37,7 @@ class NotesAnyTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(36);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@@ -53,7 +53,7 @@ class NotesAnyTest extends TestCase
*/
public function testTriggeredEmpty()
{
$journal = TransactionJournal::find(37);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@@ -69,7 +69,7 @@ class NotesAnyTest extends TestCase
*/
public function testTriggeredNone()
{
$journal = TransactionJournal::find(38);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$trigger = NotesAny::makeFromStrings('', false);
$result = $trigger->triggered($journal);

View File

@@ -37,7 +37,7 @@ class NotesAreTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(39);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@@ -53,7 +53,7 @@ class NotesAreTest extends TestCase
*/
public function testTriggeredDifferent()
{
$journal = TransactionJournal::find(41);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@@ -69,7 +69,7 @@ class NotesAreTest extends TestCase
*/
public function testTriggeredEmpty()
{
$journal = TransactionJournal::find(40);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@@ -85,7 +85,7 @@ class NotesAreTest extends TestCase
*/
public function testTriggeredNone()
{
$journal = TransactionJournal::find(42);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$trigger = NotesAre::makeFromStrings('Bla bla', false);
$result = $trigger->triggered($journal);

View File

@@ -37,7 +37,7 @@ class NotesContainTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(43);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@@ -53,7 +53,7 @@ class NotesContainTest extends TestCase
*/
public function testTriggeredDifferent()
{
$journal = TransactionJournal::find(46);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@@ -69,7 +69,7 @@ class NotesContainTest extends TestCase
*/
public function testTriggeredEmpty()
{
$journal = TransactionJournal::find(44);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@@ -85,7 +85,7 @@ class NotesContainTest extends TestCase
*/
public function testTriggeredNone()
{
$journal = TransactionJournal::find(47);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$trigger = NotesContain::makeFromStrings('Bla bla', false);
$result = $trigger->triggered($journal);
@@ -97,7 +97,7 @@ class NotesContainTest extends TestCase
*/
public function testTriggeredPartial()
{
$journal = TransactionJournal::find(45);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);

View File

@@ -37,7 +37,7 @@ class NotesEmptyTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(48);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$trigger = NotesEmpty::makeFromStrings('', false);
$result = $trigger->triggered($journal);
@@ -49,7 +49,7 @@ class NotesEmptyTest extends TestCase
*/
public function testTriggeredEmpty()
{
$journal = TransactionJournal::find(49);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@@ -65,7 +65,7 @@ class NotesEmptyTest extends TestCase
*/
public function testTriggeredPartial()
{
$journal = TransactionJournal::find(50);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);

View File

@@ -37,7 +37,7 @@ class NotesEndTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(51);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@@ -53,7 +53,7 @@ class NotesEndTest extends TestCase
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(53);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@@ -69,7 +69,7 @@ class NotesEndTest extends TestCase
*/
public function testTriggeredNoMatch()
{
$journal = TransactionJournal::find(52);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);

View File

@@ -37,7 +37,7 @@ class NotesStartTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(54);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@@ -53,7 +53,7 @@ class NotesStartTest extends TestCase
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(55);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@@ -69,7 +69,7 @@ class NotesStartTest extends TestCase
*/
public function testTriggeredNoMatch()
{
$journal = TransactionJournal::find(56);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);

View File

@@ -36,7 +36,7 @@ class TagIsTest extends TestCase
*/
public function testNotTriggered()
{
$journal = TransactionJournal::find(58);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->tags()->detach();
$this->assertEquals(0, $journal->tags()->count());
@@ -50,7 +50,7 @@ class TagIsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(57);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->tags()->detach();
$tags = $journal->user->tags()->take(3)->get();
$search = '';

View File

@@ -36,7 +36,7 @@ class ToAccountContainsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(59);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
$trigger = ToAccountContains::makeFromStrings($account->name, false);
@@ -49,7 +49,7 @@ class ToAccountContainsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(60);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = ToAccountContains::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);

View File

@@ -36,10 +36,14 @@ class ToAccountEndsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(61);
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
$count = 0;
while ($count === 0) {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->where('amount', '>', 0)->count();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
}
$account = $transaction->account;
$trigger = ToAccountEnds::makeFromStrings(substr($account->name, -3), false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
@@ -50,8 +54,12 @@ class ToAccountEndsTest extends TestCase
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(62);
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$count = 0;
while ($count === 0) {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->where('amount', '>', 0)->count();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
}
$account = $transaction->account;
$trigger = ToAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
@@ -64,7 +72,7 @@ class ToAccountEndsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(63);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = ToAccountEnds::makeFromStrings(strval(rand(1, 234)), false);
$result = $trigger->triggered($journal);

View File

@@ -36,7 +36,7 @@ class ToAccountIsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(64);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
@@ -50,7 +50,7 @@ class ToAccountIsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(65);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = ToAccountIs::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);

View File

@@ -36,7 +36,7 @@ class ToAccountStartsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(66);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
@@ -50,7 +50,7 @@ class ToAccountStartsTest extends TestCase
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(67);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
@@ -64,7 +64,7 @@ class ToAccountStartsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(68);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = ToAccountStarts::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);

View File

@@ -36,7 +36,7 @@ class TransactionTypeTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(69);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$type = $journal->transactionType->type;
$trigger = TransactionType::makeFromStrings($type, false);
$result = $trigger->triggered($journal);
@@ -48,7 +48,7 @@ class TransactionTypeTest extends TestCase
*/
public function testTriggeredFalse()
{
$journal = TransactionJournal::find(70);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = TransactionType::makeFromStrings('NonExisting', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);

View File

@@ -111,8 +111,8 @@ class PiggyBankEventTransformerTest extends TestCase
$accountMeta = AccountMeta::create(
[
'account_id' => $account->id,
'name' => 'currency_id',
'data' => 1,
'name' => 'currency_id',
'data' => 1,
]
);