Fix some tests for account API

This commit is contained in:
James Cole
2021-03-13 12:01:01 +01:00
parent 668b169a5e
commit 7118abe28d
29 changed files with 992 additions and 315 deletions

View File

@@ -586,16 +586,25 @@ class AccountRepository implements AccountRepositoryInterface
/**
* @inheritDoc
*/
public function resetAccountOrder(array $types): void
public function resetAccountOrder(): void
{
$list = $this->getAccountsByType($types);
/**
* @var int $index
* @var Account $account
*/
foreach ($list as $index => $account) {
$account->order = $index + 1;
$account->save();
$sets = [
[AccountType::DEFAULT, AccountType::ASSET],
[AccountType::EXPENSE, AccountType::BENEFICIARY],
[AccountType::REVENUE],
[AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE],
[AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION],
];
foreach ($sets as $set) {
$list = $this->getAccountsByType($set);
$index = 1;
foreach ($list as $account) {
if ($index !== $account->order) {
$account->order = $index;
$account->save();
}
$index++;
}
}
}
@@ -753,4 +762,12 @@ class AccountRepository implements AccountRepositoryInterface
return $service->update($account, $data);
}
/**
* @inheritDoc
*/
public function maxOrder(array $types): int
{
return (int)$this->getAccountsByType($types)->max('order');
}
}