mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Expand test coverage for bunq.
This commit is contained in:
@@ -81,7 +81,7 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
|
||||
$mapping = $data['account_mapping'] ?? [];
|
||||
$final = [];
|
||||
if (\count($accounts) === 0) {
|
||||
throw new FireflyException('No bunq accounts found. Import cannot continue.');
|
||||
throw new FireflyException('No bunq accounts found. Import cannot continue.'); // @codeCoverageIgnore
|
||||
}
|
||||
if (\count($mapping) === 0) {
|
||||
$messages = new MessageBag;
|
||||
@@ -115,7 +115,7 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
|
||||
$config = $this->repository->getConfiguration($this->importJob);
|
||||
$accounts = $config['accounts'] ?? [];
|
||||
if (\count($accounts) === 0) {
|
||||
throw new FireflyException('No bunq accounts found. Import cannot continue.');
|
||||
throw new FireflyException('No bunq accounts found. Import cannot continue.'); // @codeCoverageIgnore
|
||||
}
|
||||
// list the users accounts:
|
||||
$collection = $this->accountRepository->getAccountsByType([AccountType::ASSET]);
|
||||
@@ -140,6 +140,8 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* Get the view for this stage.
|
||||
*
|
||||
* @return string
|
||||
|
@@ -23,19 +23,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Import\Routine\Bunq;
|
||||
|
||||
use bunq\Context\ApiContext;
|
||||
use bunq\Context\BunqContext;
|
||||
use bunq\Exception\BadRequestException;
|
||||
use bunq\Exception\BunqException;
|
||||
use bunq\Model\Generated\Endpoint\MonetaryAccount;
|
||||
use bunq\Model\Generated\Endpoint\MonetaryAccount as BunqMonetaryAccount;
|
||||
use bunq\Model\Generated\Endpoint\MonetaryAccountBank;
|
||||
use bunq\Model\Generated\Object\Pointer;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use Log;
|
||||
use FireflyIII\Services\Bunq\ApiContext;
|
||||
use FireflyIII\Services\Bunq\MonetaryAccount;
|
||||
|
||||
/**
|
||||
* Class StageNewHandler
|
||||
@@ -56,19 +52,9 @@ class StageNewHandler
|
||||
$preference = app('preferences')->getForUser($this->importJob->user, 'bunq_api_context', null);
|
||||
if (null !== $preference && '' !== (string)$preference->data) {
|
||||
// restore API context
|
||||
try {
|
||||
$apiContext = ApiContext::fromJson($preference->data);
|
||||
BunqContext::loadApiContext($apiContext);
|
||||
} catch (BadRequestException|BunqException|Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
$message = $e->getMessage();
|
||||
if (stripos($message, 'Generating a new private key failed')) {
|
||||
$message = 'Could not generate key-material. Please make sure OpenSSL is installed and configured: http://bit.ly/FF3-openSSL';
|
||||
|
||||
}
|
||||
throw new FireflyException($message);
|
||||
}
|
||||
/** @var ApiContext $apiContext */
|
||||
$apiContext = app(ApiContext::class);
|
||||
$apiContext->fromJson($preference->data);
|
||||
|
||||
// list bunq accounts:
|
||||
$accounts = $this->listAccounts();
|
||||
@@ -97,13 +83,17 @@ class StageNewHandler
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function listAccounts(): array
|
||||
{
|
||||
$accounts = [];
|
||||
$monetaryAccountList = MonetaryAccount::listing();
|
||||
/** @var MonetaryAccount $monetaryAccount */
|
||||
foreach ($monetaryAccountList->getValue() as $monetaryAccount) {
|
||||
$accounts = [];
|
||||
/** @var MonetaryAccount $lister */
|
||||
$lister = app(MonetaryAccount::class);
|
||||
$result = $lister->listing();
|
||||
|
||||
/** @var BunqMonetaryAccount $monetaryAccount */
|
||||
foreach ($result->getValue() as $monetaryAccount) {
|
||||
$mab = $monetaryAccount->getMonetaryAccountBank();
|
||||
$array = $this->processMab($mab);
|
||||
$accounts[] = $array;
|
||||
|
Reference in New Issue
Block a user