From 73fee4eb6bdd27f6b3522466b875e4c74a3f1814 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 3 Apr 2018 19:15:06 +0200 Subject: [PATCH] Fix #1313 --- app/Factory/AccountFactory.php | 5 ++++ tests/Unit/Factory/AccountFactoryTest.php | 34 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/app/Factory/AccountFactory.php b/app/Factory/AccountFactory.php index 1687fb03b1..8c035c8548 100644 --- a/app/Factory/AccountFactory.php +++ b/app/Factory/AccountFactory.php @@ -73,6 +73,11 @@ class AccountFactory $databaseData['virtual_balance'] = '0'; } + // fix virtual balance when it's empty + if ($databaseData['virtual_balance'] === '') { + $databaseData['virtual_balance'] = '0'; + } + $newAccount = Account::create($databaseData); $this->updateMetaData($newAccount, $data); diff --git a/tests/Unit/Factory/AccountFactoryTest.php b/tests/Unit/Factory/AccountFactoryTest.php index 06bfd5df98..e088e42a23 100644 --- a/tests/Unit/Factory/AccountFactoryTest.php +++ b/tests/Unit/Factory/AccountFactoryTest.php @@ -68,6 +68,40 @@ class AccountFactoryTest extends TestCase $this->assertEquals('defaultAsset', $account->getMeta('accountRole')); } + /** + * Test minimal set of data to make factory work (asset account). + * + * @covers \FireflyIII\Factory\AccountFactory + * @covers \FireflyIII\Factory\AccountMetaFactory + * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait + */ + public function testCreateBasicEmptyVb() + { + + $data = [ + 'account_type_id' => null, + 'accountType' => 'asset', + 'iban' => null, + 'name' => 'Basic asset account #' . random_int(1, 1000), + 'virtualBalance' => '', + 'active' => true, + 'accountRole' => 'defaultAsset', + ]; + + /** @var AccountFactory $factory */ + $factory = app(AccountFactory::class); + $factory->setUser($this->user()); + $account = $factory->create($data); + + // assert stuff about account: + $this->assertEquals($account->name, $data['name']); + $this->assertEquals(AccountType::ASSET, $account->accountType->type); + $this->assertEquals('', $account->iban); + $this->assertTrue($account->active); + $this->assertEquals('0', $account->virtual_balance); + $this->assertEquals('defaultAsset', $account->getMeta('accountRole')); + } + /** * Test creation of CC asset. *