Expand tests

This commit is contained in:
James Cole 2018-12-21 07:36:40 +01:00
parent 8ede404b8a
commit 3c9c46d574
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
3 changed files with 409 additions and 405 deletions

View File

@ -141,12 +141,11 @@ class StageImportDataHandler
* @return array * @return array
* @throws FireflyException * @throws FireflyException
*/ */
private function convertPayment(BunqPayment $payment, int $bunqAccountId, LocalAccount $source): array private function convertPayment(BunqPayment $payment, LocalAccount $source): array
{ {
Log::debug(sprintf('Now at payment with ID #%d', $payment->getId())); Log::debug(sprintf('Now at payment with ID #%d', $payment->getId()));
return $this->converter->convert($payment, $source); return $this->converter->convert($payment, $source);
exit;
} }
/** /**
@ -308,7 +307,7 @@ class StageImportDataHandler
Log::debug('Now looping results from bunq...'); Log::debug('Now looping results from bunq...');
/** @var BunqPayment $payment */ /** @var BunqPayment $payment */
foreach ($response->getValue() as $index => $payment) { foreach ($response->getValue() as $index => $payment) {
$return[] = $this->convertPayment($payment, $bunqAccountId, $localAccount); $return[] = $this->convertPayment($payment, $localAccount);
$paymentId = $payment->getId(); $paymentId = $payment->getId();
/* /*
* If oldest and newest transaction are null, they have to be set: * If oldest and newest transaction are null, they have to be set:
@ -412,7 +411,7 @@ class StageImportDataHandler
*/ */
/** @var BunqPayment $payment */ /** @var BunqPayment $payment */
foreach ($response->getValue() as $payment) { foreach ($response->getValue() as $payment) {
$return[] = $this->convertPayment($payment, $bunqAccountId, $localAccount); $return[] = $this->convertPayment($payment, $localAccount);
$paymentId = $payment->getId(); $paymentId = $payment->getId();
/* /*

View File

@ -33,13 +33,13 @@ use bunq\Model\Generated\Object\Pointer;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory; use FireflyIII\Factory\AccountFactory;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\ImportJob; use FireflyIII\Models\ImportJob;
use FireflyIII\Models\Preference; use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Services\Bunq\ApiContext; use FireflyIII\Services\Bunq\ApiContext;
use FireflyIII\Services\Bunq\Payment; use FireflyIII\Services\Bunq\Payment;
use FireflyIII\Support\Import\Routine\Bunq\PaymentConverter;
use FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler; use FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler;
use Log; use Log;
use Mockery; use Mockery;
@ -121,47 +121,47 @@ class StageImportDataHandlerTest extends TestCase
$value = [$payment]; $value = [$payment];
$list = new BunqResponsePaymentList($value, [], null); $list = new BunqResponsePaymentList($value, [], null);
$expectedTransaction = [
$expectedTransactions = [ 'user' => 1,
[ 'type' => 'Deposit',
'user' => 1, 'date' => $today->format('Y-m-d'),
'type' => 'Deposit', 'timestamp' => $today->toAtomString(),
'date' => $today->format('Y-m-d'), 'description' => $payment->getDescription(),
'description' => $payment->getDescription(), 'piggy_bank_id' => null,
'piggy_bank_id' => null, 'piggy_bank_name' => null,
'piggy_bank_name' => null, 'bill_id' => null,
'bill_id' => null, 'bill_name' => null,
'bill_name' => null, 'tags' => [null, null],
'tags' => [null, null], 'internal_reference' => null,
'internal_reference' => null, 'external_id' => null,
'external_id' => null, 'notes' => null,
'notes' => null, 'bunq_payment_id' => null,
'bunq_payment_id' => null, 'transactions' => [
'transactions' => [ [
[ 'description' => null,
'description' => null, 'amount' => '150',
'amount' => '150', 'currency_id' => null,
'currency_id' => null, 'currency_code' => 'EUR',
'currency_code' => 'EUR', 'foreign_amount' => null,
'foreign_amount' => null, 'foreign_currency_id' => null,
'foreign_currency_id' => null, 'foreign_currency_code' => null,
'foreign_currency_code' => null, 'budget_id' => null,
'budget_id' => null, 'budget_name' => null,
'budget_name' => null, 'category_id' => null,
'category_id' => null, 'category_name' => null,
'category_name' => null, 'source_id' => $deposit->id,
'source_id' => $deposit->id, 'source_name' => null,
'source_name' => null, 'destination_id' => $account->id,
'destination_id' => $account->id, 'destination_name' => null,
'destination_name' => null, 'reconciled' => false,
'reconciled' => false, 'identifier' => 0,
'identifier' => 0,
],
], ],
'original-source' => 'bunq-v' . config('firefly.version'),
], ],
'original-source' => 'bunq-v' . config('firefly.version'),
]; ];
$expectedTransactions = [$expectedTransaction];
// mock used objects: // mock used objects:
$repository = $this->mock(ImportJobRepositoryInterface::class); $repository = $this->mock(ImportJobRepositoryInterface::class);
@ -169,6 +169,7 @@ class StageImportDataHandlerTest extends TestCase
$accountFactory = $this->mock(AccountFactory::class); $accountFactory = $this->mock(AccountFactory::class);
$context = $this->mock(ApiContext::class); $context = $this->mock(ApiContext::class);
$payment = $this->mock(Payment::class); $payment = $this->mock(Payment::class);
$converter = $this->mock(PaymentConverter::class);
// mock calls: // mock calls:
$repository->shouldReceive('setUser')->once(); $repository->shouldReceive('setUser')->once();
@ -176,82 +177,7 @@ class StageImportDataHandlerTest extends TestCase
$accountFactory->shouldReceive('setUser')->once(); $accountFactory->shouldReceive('setUser')->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference); Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference);
$context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once(); $context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once();
$repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once(); $converter->shouldReceive('setImportJob')->atLeast()->once();
$accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once();
$payment->shouldReceive('listing')->once()->andReturn($list);
$accountFactory->shouldReceive('create')->withArgs([$expectedAccount])
->andReturn($deposit)->once();
// set new last transaction ID:
$lastPref = new Preference;
$lastPref->data = 0;
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->times(2);
$lastPref = new Preference;
$lastPref->data = 0;
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-newest-transaction-1234', 0])->andReturn($lastPref)->once();
// todo: improve test thing:
Preferences::shouldReceive('setForUser');
$handler = new StageImportDataHandler;
$handler->setImportJob($job);
try {
$handler->run();
} catch (FireflyException $e) {
$this->assertFalse(true, $e->getMessage());
}
$transactions = $handler->getTransactions();
$this->assertEquals($expectedTransactions, $transactions);
}
/**
* @covers \FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler
*/
public function testRunEmpty(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'sidA_bbunq_' . random_int(1, 10000);
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
$job->file_type = '';
$job->configuration = [];
$job->save();
// fake objects:
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$contextPreference = new Preference;
$contextPreference->name = 'Some name';
$contextPreference->data = '{"a":"b"}';
$config = [
'accounts' => [
['id' => 1234], // bunq account
],
'mapping' => [
1234 => 5678, // Firefly III mapping.
],
];
$expectedTransactions = [];
$value = [];
$list = new BunqResponsePaymentList($value, [], null);
// mock used objects:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$accountFactory = $this->mock(AccountFactory::class);
$context = $this->mock(ApiContext::class);
$payment = $this->mock(Payment::class);
// mock calls:
$repository->shouldReceive('setUser')->once();
$accountRepository->shouldReceive('setUser')->once();
$accountFactory->shouldReceive('setUser')->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference);
$context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once();
$repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once(); $repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once();
$accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once(); $accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once();
$payment->shouldReceive('listing')->once()->andReturn($list); $payment->shouldReceive('listing')->once()->andReturn($list);
@ -260,11 +186,14 @@ class StageImportDataHandlerTest extends TestCase
$lastPref = new Preference; $lastPref = new Preference;
$lastPref->data = 0; $lastPref->data = 0;
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->times(2); Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->times(2);
//
$lastPref = new Preference; $lastPref = new Preference;
$lastPref->data = 0; $lastPref->data = 0;
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-newest-transaction-1234', 0])->andReturn($lastPref)->once(); Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-newest-transaction-1234', 0])->andReturn($lastPref)->once();
// converter should convert:
$converter->shouldReceive('convert')->atLeast()->once()->andReturn($expectedTransaction);
// todo: improve test thing: // todo: improve test thing:
Preferences::shouldReceive('setForUser'); Preferences::shouldReceive('setForUser');
@ -278,293 +207,366 @@ class StageImportDataHandlerTest extends TestCase
} }
$transactions = $handler->getTransactions(); $transactions = $handler->getTransactions();
$this->assertEquals($expectedTransactions, $transactions); $this->assertEquals($expectedTransactions, $transactions);
} }
/** // /**
* @covers \FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler // * @covers \FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler
*/ // */
public function testRunIban(): void // public function testRunEmpty(): void
{ // {
$job = new ImportJob; // $job = new ImportJob;
$job->user_id = $this->user()->id; // $job->user_id = $this->user()->id;
$job->key = 'sidh_bbunq_' . random_int(1, 10000); // $job->key = 'sidA_bbunq_' . random_int(1, 10000);
$job->status = 'new'; // $job->status = 'new';
$job->stage = 'new'; // $job->stage = 'new';
$job->provider = 'bunq'; // $job->provider = 'bunq';
$job->file_type = ''; // $job->file_type = '';
$job->configuration = []; // $job->configuration = [];
$job->save(); // $job->save();
//
// fake objects: // // fake objects:
$deposit = $this->user()->accounts()->where('account_type_id', 5)->first(); // $account = $this->user()->accounts()->where('account_type_id', 3)->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first(); // $contextPreference = new Preference;
$contextPreference = new Preference; // $contextPreference->name = 'Some name';
$contextPreference->name = 'Some name'; // $contextPreference->data = '{"a":"b"}';
$contextPreference->data = '{"a":"b"}'; // $config = [
$config = [ // 'accounts' => [
'accounts' => [ // ['id' => 1234], // bunq account
['id' => 1234], // bunq account // ],
], // 'mapping' => [
'mapping' => [ // 1234 => 5678, // Firefly III mapping.
1234 => 5678, // Firefly III mapping. // ],
], // ];
]; // $expectedTransactions = [];
$today = new Carbon; // $value = [];
$amount = new Amount('150', 'EUR'); // $list = new BunqResponsePaymentList($value, [], null);
$pointer = new Pointer('iban', 'ES2364265841767173822054', 'Test Site'); //
// // mock used objects:
// set new last transaction ID: // $repository = $this->mock(ImportJobRepositoryInterface::class);
$lastPref = new Preference; // $accountRepository = $this->mock(AccountRepositoryInterface::class);
$lastPref->data = 0; // $accountFactory = $this->mock(AccountFactory::class);
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->times(2); // $context = $this->mock(ApiContext::class);
// $payment = $this->mock(Payment::class);
$lastPref = new Preference; //
$lastPref->data = 0; // // mock calls:
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-newest-transaction-1234', 0])->andReturn($lastPref)->once(); // $repository->shouldReceive('setUser')->once();
// $accountRepository->shouldReceive('setUser')->once();
// todo: improve test thing: // $accountFactory->shouldReceive('setUser')->once();
Preferences::shouldReceive('setForUser'); // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference);
// $context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once();
// $repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once();
// ignore the deprecated fields: // $accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once();
$amount->setValue('150'); // $payment->shouldReceive('listing')->once()->andReturn($list);
$amount->setCurrency('EUR'); //
$pointer->setType('iban'); // // set new last transaction ID:
$pointer->setValue('ES2364265841767173822054'); // $lastPref = new Preference;
$pointer->setName('Test Site'); // $lastPref->data = 0;
$labelMonetaryAccount = new LabelMonetaryAccount(); // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->times(2);
$labelMonetaryAccount->setDisplayName('James'); //
$labelUser = new LabelUser('x', 'James', 'NL'); // $lastPref = new Preference;
$labelUser->setDisplayName('James'); // $lastPref->data = 0;
$labelMonetaryAccount->setLabelUser($labelUser); // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-newest-transaction-1234', 0])->andReturn($lastPref)->once();
$labelMonetaryAccount->setIban('RS88844660406878687897'); //
// // todo: improve test thing:
$payment = new BunqPayment($amount, $pointer, 'Some descr', null, null); // Preferences::shouldReceive('setForUser');
$payment->setAmount($amount); //
$payment->setDescription('Some random thing #' . random_int(1, 10000)); // $handler = new StageImportDataHandler;
$payment->setCounterpartyAlias($labelMonetaryAccount); // $handler->setImportJob($job);
$value = [$payment]; // try {
$list = new BunqResponsePaymentList($value, [], null); // $handler->run();
//
$expectedTransactions = [ // } catch (FireflyException $e) {
[ // $this->assertFalse(true, $e->getMessage());
'user' => 1, // }
'type' => 'Deposit', // $transactions = $handler->getTransactions();
'date' => $today->format('Y-m-d'), // $this->assertEquals($expectedTransactions, $transactions);
'description' => $payment->getDescription(), //
'piggy_bank_id' => null, // }
'piggy_bank_name' => null, //
'bill_id' => null, // /**
'bill_name' => null, // * @covers \FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler
'tags' => [null, null], // */
'internal_reference' => null, // public function testRunIban(): void
'external_id' => null, // {
'notes' => null, // $job = new ImportJob;
'bunq_payment_id' => null, // $job->user_id = $this->user()->id;
'transactions' => [ // $job->key = 'sidh_bbunq_' . random_int(1, 10000);
[ // $job->status = 'new';
'description' => null, // $job->stage = 'new';
'amount' => '150', // $job->provider = 'bunq';
'currency_id' => null, // $job->file_type = '';
'currency_code' => 'EUR', // $job->configuration = [];
'foreign_amount' => null, // $job->save();
'foreign_currency_id' => null, //
'foreign_currency_code' => null, // // fake objects:
'budget_id' => null, // $deposit = $this->user()->accounts()->where('account_type_id', 5)->first();
'budget_name' => null, // $account = $this->user()->accounts()->where('account_type_id', 3)->first();
'category_id' => null, // $contextPreference = new Preference;
'category_name' => null, // $contextPreference->name = 'Some name';
'source_id' => $deposit->id, // $contextPreference->data = '{"a":"b"}';
'source_name' => null, // $config = [
'destination_id' => $account->id, // 'accounts' => [
'destination_name' => null, // ['id' => 1234], // bunq account
'reconciled' => false, // ],
'identifier' => 0, // 'mapping' => [
], // 1234 => 5678, // Firefly III mapping.
], // ],
'original-source' => 'bunq-v' . config('firefly.version'), // ];
], // $today = new Carbon;
]; // $amount = new Amount('150', 'EUR');
// $pointer = new Pointer('iban', 'ES2364265841767173822054', 'Test Site');
// mock used objects: //
$repository = $this->mock(ImportJobRepositoryInterface::class); // // set new last transaction ID:
$accountRepository = $this->mock(AccountRepositoryInterface::class); // $lastPref = new Preference;
$accountFactory = $this->mock(AccountFactory::class); // $lastPref->data = 0;
$context = $this->mock(ApiContext::class); // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->times(2);
$payment = $this->mock(Payment::class); //
// $lastPref = new Preference;
// mock calls: // $lastPref->data = 0;
$repository->shouldReceive('setUser')->once(); // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-newest-transaction-1234', 0])->andReturn($lastPref)->once();
$accountRepository->shouldReceive('setUser')->once(); //
$accountFactory->shouldReceive('setUser')->once(); // // todo: improve test thing:
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference); // Preferences::shouldReceive('setForUser');
$context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once(); //
$repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once(); //
$accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once(); // // ignore the deprecated fields:
$payment->shouldReceive('listing')->once()->andReturn($list); // $amount->setValue('150');
$accountRepository->shouldReceive('findByIbanNull')->withArgs(['RS88844660406878687897', [AccountType::REVENUE]])->once()->andReturn($deposit); // $amount->setCurrency('EUR');
// $pointer->setType('iban');
// $pointer->setValue('ES2364265841767173822054');
$handler = new StageImportDataHandler; // $pointer->setName('Test Site');
$handler->setImportJob($job); // $labelMonetaryAccount = new LabelMonetaryAccount();
try { // $labelMonetaryAccount->setDisplayName('James');
$handler->run(); // $labelUser = new LabelUser('x', 'James', 'NL');
// $labelUser->setDisplayName('James');
} catch (FireflyException $e) { // $labelMonetaryAccount->setLabelUser($labelUser);
$this->assertFalse(true, $e->getMessage()); // $labelMonetaryAccount->setIban('RS88844660406878687897');
} //
$transactions = $handler->getTransactions(); // $payment = new BunqPayment($amount, $pointer, 'Some descr', null, null);
$this->assertEquals($expectedTransactions, $transactions); // $payment->setAmount($amount);
} // $payment->setDescription('Some random thing #' . random_int(1, 10000));
// $payment->setCounterpartyAlias($labelMonetaryAccount);
/** // $value = [$payment];
* @covers \FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler // $list = new BunqResponsePaymentList($value, [], null);
*/ //
public function testRunIbanAsset(): void // $expectedTransactions = [
{ // [
$job = new ImportJob; // 'user' => 1,
$job->user_id = $this->user()->id; // 'type' => 'Deposit',
$job->key = 'sidh_bbunq_' . random_int(1, 10000); // 'date' => $today->format('Y-m-d'),
$job->status = 'new'; // 'description' => $payment->getDescription(),
$job->stage = 'new'; // 'piggy_bank_id' => null,
$job->provider = 'bunq'; // 'piggy_bank_name' => null,
$job->file_type = ''; // 'bill_id' => null,
$job->configuration = []; // 'bill_name' => null,
$job->save(); // 'tags' => [null, null],
// 'internal_reference' => null,
// fake objects: // 'external_id' => null,
$account = $this->user()->accounts()->where('account_type_id', 3)->first(); // 'notes' => null,
$asset = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $account->id)->first(); // 'bunq_payment_id' => null,
$contextPreference = new Preference; // 'transactions' => [
$contextPreference->name = 'Some name'; // [
$contextPreference->data = '{"a":"b"}'; // 'description' => null,
$config = [ // 'amount' => '150',
'accounts' => [ // 'currency_id' => null,
['id' => 1234], // bunq account // 'currency_code' => 'EUR',
], // 'foreign_amount' => null,
'mapping' => [ // 'foreign_currency_id' => null,
1234 => 5678, // Firefly III mapping. // 'foreign_currency_code' => null,
], // 'budget_id' => null,
]; // 'budget_name' => null,
$amount = new Amount('150', 'EUR'); // 'category_id' => null,
$pointer = new Pointer('iban', 'ES2364265841767173822054', 'Test Site'); // 'category_name' => null,
$expectedAccount = [ // 'source_id' => $deposit->id,
'user_id' => 1, // 'source_name' => null,
'iban' => null, // 'destination_id' => $account->id,
'name' => 'James', // 'destination_name' => null,
'account_type_id' => null, // 'reconciled' => false,
'accountType' => 'Revenue account', // 'identifier' => 0,
'virtualBalance' => null, // ],
'active' => true, // ],
]; // 'original-source' => 'bunq-v' . config('firefly.version'),
// ],
// ignore the deprecated fields: // ];
$amount->setValue('150'); //
$amount->setCurrency('EUR'); // // mock used objects:
$pointer->setType('iban'); // $repository = $this->mock(ImportJobRepositoryInterface::class);
$pointer->setValue('ES2364265841767173822054'); // $accountRepository = $this->mock(AccountRepositoryInterface::class);
$pointer->setName('Test Site'); // $accountFactory = $this->mock(AccountFactory::class);
$labelMonetaryAccount = new LabelMonetaryAccount(); // $context = $this->mock(ApiContext::class);
$labelMonetaryAccount->setDisplayName('James'); // $payment = $this->mock(Payment::class);
$labelUser = new LabelUser('x', 'James', 'NL'); //
$labelUser->setDisplayName('James'); // // mock calls:
$labelMonetaryAccount->setLabelUser($labelUser); // $repository->shouldReceive('setUser')->once();
$labelMonetaryAccount->setIban('RS88844660406878687897'); // $accountRepository->shouldReceive('setUser')->once();
$today = new Carbon; // $accountFactory->shouldReceive('setUser')->once();
$payment = new BunqPayment($amount, $pointer, 'Some descr', null, null); // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference);
$payment->setAmount($amount); // $context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once();
$payment->setCounterpartyAlias($labelMonetaryAccount); // $repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once();
$payment->setDescription('Random transfer #' . random_int(1, 10000)); // $accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once();
$value = [$payment]; // $payment->shouldReceive('listing')->once()->andReturn($list);
$list = new BunqResponsePaymentList($value, [], null); // $accountRepository->shouldReceive('findByIbanNull')->withArgs(['RS88844660406878687897', [AccountType::REVENUE]])->once()->andReturn($deposit);
//
// set new last transaction ID: //
$lastPref = new Preference; // $handler = new StageImportDataHandler;
$lastPref->data = 0; // $handler->setImportJob($job);
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->once(); // try {
// $handler->run();
$expectedTransactions = [ //
[ // } catch (FireflyException $e) {
'user' => 1, // $this->assertFalse(true, $e->getMessage());
'type' => 'Transfer', // }
'date' => $today->format('Y-m-d'), // $transactions = $handler->getTransactions();
'description' => $payment->getDescription(), // $this->assertEquals($expectedTransactions, $transactions);
'piggy_bank_id' => null, // }
'piggy_bank_name' => null, //
'bill_id' => null, // /**
'bill_name' => null, // * @covers \FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler
'tags' => [null, null], // */
'internal_reference' => null, // public function testRunIbanAsset(): void
'external_id' => null, // {
'notes' => null, // $job = new ImportJob;
'bunq_payment_id' => null, // $job->user_id = $this->user()->id;
'transactions' => [ // $job->key = 'sidh_bbunq_' . random_int(1, 10000);
[ // $job->status = 'new';
'description' => null, // $job->stage = 'new';
'amount' => '150', // $job->provider = 'bunq';
'currency_id' => null, // $job->file_type = '';
'currency_code' => 'EUR', // $job->configuration = [];
'foreign_amount' => null, // $job->save();
'foreign_currency_id' => null, //
'foreign_currency_code' => null, // // fake objects:
'budget_id' => null, // $account = $this->user()->accounts()->where('account_type_id', 3)->first();
'budget_name' => null, // $asset = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $account->id)->first();
'category_id' => null, // $contextPreference = new Preference;
'category_name' => null, // $contextPreference->name = 'Some name';
'source_id' => $asset->id, // $contextPreference->data = '{"a":"b"}';
'source_name' => null, // $config = [
'destination_id' => $account->id, // 'accounts' => [
'destination_name' => null, // ['id' => 1234], // bunq account
'reconciled' => false, // ],
'identifier' => 0, // 'mapping' => [
], // 1234 => 5678, // Firefly III mapping.
], // ],
], // ];
]; // $amount = new Amount('150', 'EUR');
// $pointer = new Pointer('iban', 'ES2364265841767173822054', 'Test Site');
// mock used objects: // $expectedAccount = [
$repository = $this->mock(ImportJobRepositoryInterface::class); // 'user_id' => 1,
$accountRepository = $this->mock(AccountRepositoryInterface::class); // 'iban' => null,
$accountFactory = $this->mock(AccountFactory::class); // 'name' => 'James',
$context = $this->mock(ApiContext::class); // 'account_type_id' => null,
$payment = $this->mock(Payment::class); // 'accountType' => 'Revenue account',
// 'virtualBalance' => null,
// mock calls: // 'active' => true,
$repository->shouldReceive('setUser')->once(); // ];
$accountRepository->shouldReceive('setUser')->once(); //
$accountFactory->shouldReceive('setUser')->once(); // // ignore the deprecated fields:
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference); // $amount->setValue('150');
$context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once(); // $amount->setCurrency('EUR');
$repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once(); // $pointer->setType('iban');
$accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once(); // $pointer->setValue('ES2364265841767173822054');
$payment->shouldReceive('listing')->once()->andReturn($list); // $pointer->setName('Test Site');
$accountRepository->shouldReceive('findByIbanNull')->withArgs(['RS88844660406878687897', [AccountType::REVENUE]])->once()->andReturnNull(); // $labelMonetaryAccount = new LabelMonetaryAccount();
$accountRepository->shouldReceive('findByIbanNull')->withArgs(['RS88844660406878687897', [AccountType::ASSET]])->once()->andReturn($asset); // $labelMonetaryAccount->setDisplayName('James');
// $labelUser = new LabelUser('x', 'James', 'NL');
// $labelUser->setDisplayName('James');
// set new last transaction ID: // $labelMonetaryAccount->setLabelUser($labelUser);
$lastPref = new Preference; // $labelMonetaryAccount->setIban('RS88844660406878687897');
$lastPref->data = 0; // $today = new Carbon;
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->times(1); // $payment = new BunqPayment($amount, $pointer, 'Some descr', null, null);
// $payment->setAmount($amount);
$lastPref = new Preference; // $payment->setCounterpartyAlias($labelMonetaryAccount);
$lastPref->data = 0; // $payment->setDescription('Random transfer #' . random_int(1, 10000));
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-newest-transaction-1234', 0])->andReturn($lastPref)->once(); // $value = [$payment];
// $list = new BunqResponsePaymentList($value, [], null);
// todo: improve test thing: //
Preferences::shouldReceive('setForUser'); // // set new last transaction ID:
// $lastPref = new Preference;
$handler = new StageImportDataHandler; // $lastPref->data = 0;
$handler->setImportJob($job); // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->once();
try { //
$handler->run(); // $expectedTransactions = [
// [
} catch (FireflyException $e) { // 'user' => 1,
$this->assertFalse(true, $e->getMessage()); // 'type' => 'Transfer',
} // 'date' => $today->format('Y-m-d'),
$transactions = $handler->getTransactions(); // 'description' => $payment->getDescription(),
//$this->assertEquals($expectedTransactions, $transactions); // 'piggy_bank_id' => null,
} // 'piggy_bank_name' => null,
// 'bill_id' => null,
// 'bill_name' => null,
// 'tags' => [null, null],
// 'internal_reference' => null,
// 'external_id' => null,
// 'notes' => null,
// 'bunq_payment_id' => null,
// 'transactions' => [
// [
// 'description' => null,
// 'amount' => '150',
// 'currency_id' => null,
// 'currency_code' => 'EUR',
// 'foreign_amount' => null,
// 'foreign_currency_id' => null,
// 'foreign_currency_code' => null,
// 'budget_id' => null,
// 'budget_name' => null,
// 'category_id' => null,
// 'category_name' => null,
// 'source_id' => $asset->id,
// 'source_name' => null,
// 'destination_id' => $account->id,
// 'destination_name' => null,
// 'reconciled' => false,
// 'identifier' => 0,
// ],
// ],
// ],
// ];
//
// // mock used objects:
// $repository = $this->mock(ImportJobRepositoryInterface::class);
// $accountRepository = $this->mock(AccountRepositoryInterface::class);
// $accountFactory = $this->mock(AccountFactory::class);
// $context = $this->mock(ApiContext::class);
// $payment = $this->mock(Payment::class);
//
// // mock calls:
// $repository->shouldReceive('setUser')->once();
// $accountRepository->shouldReceive('setUser')->once();
// $accountFactory->shouldReceive('setUser')->once();
// Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference);
// $context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once();
// $repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once();
// $accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once();
// $payment->shouldReceive('listing')->once()->andReturn($list);
// $accountRepository->shouldReceive('findByIbanNull')->withArgs(['RS88844660406878687897', [AccountType::REVENUE]])->once()->andReturnNull();
// $accountRepository->shouldReceive('findByIbanNull')->withArgs(['RS88844660406878687897', [AccountType::ASSET]])->once()->andReturn($asset);
//
//
// // set new last transaction ID:
// $lastPref = new Preference;
// $lastPref->data = 0;
// Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->times(1);
//
// $lastPref = new Preference;
// $lastPref->data = 0;
// Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-newest-transaction-1234', 0])->andReturn($lastPref)->once();
//
// // todo: improve test thing:
// Preferences::shouldReceive('setForUser');
//
// $handler = new StageImportDataHandler;
// $handler->setImportJob($job);
// try {
// $handler->run();
//
// } catch (FireflyException $e) {
// $this->assertFalse(true, $e->getMessage());
// }
// $transactions = $handler->getTransactions();
// //$this->assertEquals($expectedTransactions, $transactions);
// }
} }

View File

@ -211,6 +211,7 @@ class StageNewHandlerTest extends TestCase
'default_avatar_status' => null, 'default_avatar_status' => null,
'restriction_chat' => null, 'restriction_chat' => null,
], ],
'iban' => 'SM72C9584723533916792029340'
], ],
], ],
]; ];
@ -297,7 +298,9 @@ class StageNewHandlerTest extends TestCase
'default_avatar_status' => null, 'default_avatar_status' => null,
'restriction_chat' => null, 'restriction_chat' => null,
], ],
'iban' => 'SM72C9584723533916792029340'
], ],
], ],
]; ];