mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 22:21:42 +00:00
make sure randomly selected journals match prerequisites.
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.*']);
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user