Skip to content

Firefly III: a personal finances manager

Fix #1313

James Cole73fee4eb6bdd
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.
*