Fix tests for account

This commit is contained in:
James Cole
2021-03-20 07:02:06 +01:00
parent e32f14578c
commit 836f0ecf3f
23 changed files with 399 additions and 275 deletions

View File

@@ -120,7 +120,13 @@ trait AccountServiceTrait
if (null === $data['account_role']) {
$data['account_role'] = $this->accountRepository->getMetaValue($account, 'account_role');
}
if ($account->accountType->type === AccountType::ASSET && isset($data['account_role']) && 'ccAsset' === $data['account_role']) {
// only asset account may have a role:
if ($account->accountType->type !== AccountType::ASSET) {
$data['account_role'] = '';
}
if ($account->accountType->type === AccountType::ASSET && array_key_exists('account_role', $data) && 'ccAsset' === $data['account_role']) {
$fields = $this->validCCFields; // @codeCoverageIgnore
}
/** @var AccountMetaFactory $factory */

View File

@@ -119,15 +119,23 @@ class AccountUpdateService
private function updateAccount(Account $account, array $data): Account
{
// update the account itself:
$account->name = $data['name'] ?? $account->name;
$account->active = $data['active'] ?? $account->active;
$account->iban = $data['iban'] ?? $account->iban;
if(array_key_exists('name', $data)) {
$account->name = $data['name'];
}
if(array_key_exists('active', $data)) {
$account->active = $data['active'];
}
if(array_key_exists('iban', $data)) {
$account->iban = $data['iban'];
}
// liability stuff:
$liabilityType = $data['liability_type'] ?? '';
if ($this->isLiability($account) && $this->isLiabilityType($liabilityType)) {
$type = $this->getAccountType($liabilityType);
$account->account_type_id = $type->id;
// set liability, but account must already be a liability.
//$liabilityType = $data['liability_type'] ?? '';
if ($this->isLiability($account) && array_key_exists('liability_type', $data)) {
$type = $this->getAccountType($data['liability_type']);
if(null !== $type) {
$account->account_type_id = $type->id;
}
}
// update virtual balance (could be set to zero if empty string).