Skip to content

Firefly III: a personal finances manager

Fix tests.

James Colef31900535766
diff --git a/app/Api/V1/Controllers/AvailableBudgetController.php b/app/Api/V1/Controllers/AvailableBudgetController.php
index 9ea09b38e0..b91dae8c5f 100644
--- a/app/Api/V1/Controllers/AvailableBudgetController.php
+++ b/app/Api/V1/Controllers/AvailableBudgetController.php
@@ -152,9 +152,9 @@ class AvailableBudgetController extends Controller
public function store(AvailableBudgetRequest $request): JsonResponse
{
$data = $request->getAll();
- $currency = $this->currencyRepository->findNull($data['transaction_currency_id']);
+ $currency = $this->currencyRepository->findNull($data['currency_id']);
if (null === $currency) {
- $this->currencyRepository->findByCodeNull($data['transaction_currency_code']);
+ $this->currencyRepository->findByCodeNull($data['currency_code']);
}
if (null === $currency) {
throw new FireflyException('Could not find the indicated currency.');
diff --git a/app/Api/V1/Requests/AvailableBudgetRequest.php b/app/Api/V1/Requests/AvailableBudgetRequest.php
index 2ad7fe1367..865b2b7fd5 100644
--- a/app/Api/V1/Requests/AvailableBudgetRequest.php
+++ b/app/Api/V1/Requests/AvailableBudgetRequest.php
@@ -47,11 +47,11 @@ class AvailableBudgetRequest extends Request
public function getAll(): array
{
return [
- 'transaction_currency_id' => $this->integer('currency_id'),
- 'transaction_currency_code' => $this->string('currency_code'),
- 'amount' => $this->string('amount'),
- 'start_date' => $this->date('start_date'),
- 'end_date' => $this->date('end_date'),
+ 'currency_id' => $this->integer('currency_id'),
+ 'currency_code' => $this->string('currency_code'),
+ 'amount' => $this->string('amount'),
+ 'start_date' => $this->date('start_date'),
+ 'end_date' => $this->date('end_date'),
];
}
diff --git a/app/Services/Internal/Destroy/AccountDestroyService.php b/app/Services/Internal/Destroy/AccountDestroyService.php
index 674ddc29fc..daf3546323 100644
--- a/app/Services/Internal/Destroy/AccountDestroyService.php
+++ b/app/Services/Internal/Destroy/AccountDestroyService.php
@@ -51,8 +51,8 @@ class AccountDestroyService
DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]);
// also update recurring transactions:
- DB::table('recurrences_transactions')->where('source_id', $account->id)->update(['source_id', $moveTo->id]);
- DB::table('recurrences_transactions')->where('destination_id', $account->id)->update(['destination_id', $moveTo->id]);
+ DB::table('recurrences_transactions')->where('source_id', $account->id)->update(['source_id' => $moveTo->id]);
+ DB::table('recurrences_transactions')->where('destination_id', $account->id)->update(['destination_id' => $moveTo->id]);
}
$service = app(JournalDestroyService::class);
diff --git a/app/Support/Import/Routine/Bunq/StageNewHandler.php b/app/Support/Import/Routine/Bunq/StageNewHandler.php
index 08dc20dd4e..05debeba55 100644
--- a/app/Support/Import/Routine/Bunq/StageNewHandler.php
+++ b/app/Support/Import/Routine/Bunq/StageNewHandler.php
@@ -68,7 +68,6 @@ class StageNewHandler
$config = $this->repository->getConfiguration($this->importJob);
$config['accounts'] = $accounts;
$this->repository->setConfiguration($this->importJob, $config);
-
return;
}
throw new FireflyException('The bunq API context is unexpectedly empty.'); // @codeCoverageIgnore
diff --git a/public/js/ff/reports/index.js b/public/js/ff/reports/index.js
index 971a31f1f7..6bc886c102 100644
--- a/public/js/ff/reports/index.js
+++ b/public/js/ff/reports/index.js
@@ -108,7 +108,7 @@ function setOptionalFromCookies() {
if ((readCookie('report-categories') !== null)) {
arr = readCookie('report-categories').split(',');
arr.forEach(function (val) {
- $('#inputCategories').find('option[value="' + val + '"]').prop('selected', true);
+ $('#inputCategories').find('option[value="' + encodeURI(val) + '"]').prop('selected', true);
});
}
$('#inputCategories').multiselect(defaultMultiSelect);
@@ -117,7 +117,7 @@ function setOptionalFromCookies() {
if ((readCookie('report-budgets') !== null)) {
arr = readCookie('report-budgets').split(',');
arr.forEach(function (val) {
- $('#inputBudgets').find('option[value="' + val + '"]').prop('selected', true);
+ $('#inputBudgets').find('option[value="' + encodeURI(val) + '"]').prop('selected', true);
});
}
$('#inputBudgets').multiselect(defaultMultiSelect);
@@ -126,7 +126,7 @@ function setOptionalFromCookies() {
if ((readCookie('report-tags') !== null)) {
arr = readCookie('report-tags').split(',');
arr.forEach(function (val) {
- $('#inputTags').find('option[value="' + val + '"]').prop('selected', true);
+ $('#inputTags').find('option[value="' + encodeURI(val) + '"]').prop('selected', true);
});
}
$('#inputTags').multiselect(defaultMultiSelect);
@@ -135,7 +135,7 @@ function setOptionalFromCookies() {
if ((readCookie('report-exp-rev') !== null)) {
arr = readCookie('report-exp-rev').split(',');
arr.forEach(function (val) {
- $('#inputExpRevAccounts').find('option[value="' + val + '"]').prop('selected', true);
+ $('#inputExpRevAccounts').find('option[value="' + encodeURI(val) + '"]').prop('selected', true);
});
}
$('#inputExpRevAccounts').multiselect(defaultMultiSelect);
diff --git a/tests/Api/V1/Controllers/AvailableBudgetControllerTest.php b/tests/Api/V1/Controllers/AvailableBudgetControllerTest.php
index cf1d849e7e..ea52b0aef1 100644
--- a/tests/Api/V1/Controllers/AvailableBudgetControllerTest.php
+++ b/tests/Api/V1/Controllers/AvailableBudgetControllerTest.php
@@ -133,10 +133,10 @@ class AvailableBudgetControllerTest extends TestCase
// data to submit
$data = [
- 'transaction_currency_id' => '1',
- 'amount' => '100',
- 'start_date' => '2018-01-01',
- 'end_date' => '2018-01-31',
+ 'currency_id' => '1',
+ 'amount' => '100',
+ 'start_date' => '2018-01-01',
+ 'end_date' => '2018-01-31',
];
@@ -148,37 +148,6 @@ class AvailableBudgetControllerTest extends TestCase
$response->assertHeader('Content-Type', 'application/vnd.api+json');
}
- /**
- * Store new available budget but the budget currency is invalid.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
- * @covers \FireflyIII\Api\V1\Requests\AvailableBudgetRequest
- */
- public function testStoreInvalidCurrency(): void
- {
- // mock stuff:
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $currencyRepository->shouldReceive('findNull')->andReturn(null);
-
- // data to submit
- $data = [
- 'transaction_currency_id' => '1',
- 'amount' => '100',
- 'start_date' => '2018-01-01',
- 'end_date' => '2018-01-31',
- ];
-
-
- // test API
- $response = $this->post('/api/v1/available_budgets', $data, ['Accept' => 'application/json']);
- $response->assertStatus(500);
- $response->assertSee('Could not find the indicated currency.');
- $response->assertHeader('Content-Type', 'application/json');
- }
/**
* Update available budget.
@@ -203,10 +172,10 @@ class AvailableBudgetControllerTest extends TestCase
// data to submit
$data = [
- 'transaction_currency_id' => '1',
- 'amount' => '100',
- 'start_date' => '2018-01-01',
- 'end_date' => '2018-01-31',
+ 'currency_id' => '1',
+ 'amount' => '100',
+ 'start_date' => '2018-01-01',
+ 'end_date' => '2018-01-31',
];
// test API
diff --git a/tests/Api/V1/Controllers/JournalLinkControllerTest.php b/tests/Api/V1/Controllers/JournalLinkControllerTest.php
index ea176dc744..c424ac1144 100644
--- a/tests/Api/V1/Controllers/JournalLinkControllerTest.php
+++ b/tests/Api/V1/Controllers/JournalLinkControllerTest.php
@@ -158,8 +158,8 @@ class JournalLinkControllerTest extends TestCase
$collector = $this->mock(TransactionCollectorInterface::class);
// mock calls:
- $repository->shouldReceive('setUser')->once();
- $journalRepos->shouldReceive('setUser')->once();
+ $repository->shouldReceive('setUser');
+ $journalRepos->shouldReceive('setUser');
$collector->shouldReceive('setUser')->withAnyArgs();
$collector->shouldReceive('setUser')->withAnyArgs();
@@ -171,6 +171,7 @@ class JournalLinkControllerTest extends TestCase
$journalRepos->shouldReceive('findNull')->andReturn($journal);
$repository->shouldReceive('storeLink')->once()->andReturn($journalLink);
+ $repository->shouldReceive('findLink')->once()->andReturn(false);
// data to submit
@@ -206,8 +207,8 @@ class JournalLinkControllerTest extends TestCase
$collector = $this->mock(TransactionCollectorInterface::class);
// mock calls:
- $repository->shouldReceive('setUser')->once();
- $journalRepos->shouldReceive('setUser')->once();
+ $repository->shouldReceive('setUser');
+ $journalRepos->shouldReceive('setUser');
$collector->shouldReceive('setUser')->withAnyArgs();
$collector->shouldReceive('setUser')->withAnyArgs();
@@ -230,8 +231,8 @@ class JournalLinkControllerTest extends TestCase
// test API
$response = $this->post('/api/v1/journal_links', $data, ['Accept' => 'application/json']);
- $response->assertStatus(500);
- $response->assertSee('Source or destination is NULL.'); // error message
+ $response->assertStatus(422);
+ $response->assertSee('Invalid inward ID.'); // error message
$response->assertHeader('Content-Type', 'application/json');
}
@@ -256,7 +257,7 @@ class JournalLinkControllerTest extends TestCase
// mock calls:
$repository->shouldReceive('setUser');
- $journalRepos->shouldReceive('setUser')->once();
+ $journalRepos->shouldReceive('setUser');
$collector->shouldReceive('setUser')->withAnyArgs();
$collector->shouldReceive('setUser')->withAnyArgs();
@@ -268,6 +269,7 @@ class JournalLinkControllerTest extends TestCase
$journalRepos->shouldReceive('findNull')->andReturn($journal);
$repository->shouldReceive('updateLink')->once()->andReturn($journalLink);
+ $repository->shouldReceive('findLink')->once()->andReturn(false);
// data to submit
$data = [
@@ -305,7 +307,7 @@ class JournalLinkControllerTest extends TestCase
// mock calls:
$repository->shouldReceive('setUser');
- $journalRepos->shouldReceive('setUser')->once();
+ $journalRepos->shouldReceive('setUser');
$collector->shouldReceive('setUser')->withAnyArgs();
$collector->shouldReceive('setUser')->withAnyArgs();
@@ -327,8 +329,8 @@ class JournalLinkControllerTest extends TestCase
// test API
$response = $this->put('/api/v1/journal_links/' . $journalLink->id, $data, ['Accept' => 'application/json']);
- $response->assertStatus(500);
- $response->assertSee('Source or destination is NULL.'); // the creation moment.
+ $response->assertStatus(422);
+ $response->assertSee('Invalid inward ID.'); // the creation moment.
$response->assertHeader('Content-Type', 'application/json');
}
}
diff --git a/tests/Feature/Controllers/HelpControllerTest.php b/tests/Feature/Controllers/HelpControllerTest.php
index e244a6d34c..345984fc98 100644
--- a/tests/Feature/Controllers/HelpControllerTest.php
+++ b/tests/Feature/Controllers/HelpControllerTest.php
@@ -112,10 +112,12 @@ class HelpControllerTest extends TestCase
$help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->once();
$help->shouldReceive('getFromGithub')->withArgs(['index', 'en_US'])->andReturn('')->once();
+ $help->shouldReceive('putInCache')->once();
+
$this->be($this->user());
$response = $this->get(route('help.show', ['index']));
$response->assertStatus(200);
- $response->assertSee('Er is geen hulptekst voor deze pagina.'); // Dutch
+ $response->assertSee('Deze helptekst is nog niet beschikbaar in het Nederlands.'); // Dutch
// put English back:
Preference::where('user_id', $this->user()->id)->where('name', 'language')->delete();
diff --git a/tests/Feature/Controllers/ReportControllerTest.php b/tests/Feature/Controllers/ReportControllerTest.php
index 6a0ded4d20..38f6bf75a4 100644
--- a/tests/Feature/Controllers/ReportControllerTest.php
+++ b/tests/Feature/Controllers/ReportControllerTest.php
@@ -564,6 +564,7 @@ class ReportControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
+ /** @var Tag $tag */
$tag = $this->user()->tags()->find(1);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
@@ -579,7 +580,7 @@ class ReportControllerTest extends TestCase
$this->be($this->user());
$response = $this->post(route('reports.index.post'), $data);
$response->assertStatus(302);
- $response->assertRedirect(route('reports.report.tag', ['1', $tag->tag, '20160101', '20160131']));
+ $response->assertRedirect(route('reports.report.tag', ['1', $tag->id, '20160101', '20160131']));
}
/**
diff --git a/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php
index ba705646fa..0014f6a0ff 100644
--- a/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php
+++ b/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php
@@ -138,6 +138,7 @@ class ChooseAccountsHandlerTest extends TestCase
];
$expected = $config;
$expected['mapping'][1234] = 456;
+ $expected['bunq-iban'] = [];
// mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -148,7 +149,7 @@ class ChooseAccountsHandlerTest extends TestCase
$repository->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser')->once();
$currencyRepos->shouldReceive('setUser')->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->times(2);
+ $repository->shouldReceive('getConfiguration')->andReturn($config)->times(3);
$repository->shouldReceive('setConfiguration')->withArgs([Mockery::any(), $expected])->once();
$accountRepos->shouldReceive('findNull')->withArgs([456])->andReturn(new Account)->once();
@@ -192,6 +193,7 @@ class ChooseAccountsHandlerTest extends TestCase
];
$expected = $config;
$expected['mapping'][0] = 456;
+ $expected['bunq-iban'] = [];
// mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -202,7 +204,7 @@ class ChooseAccountsHandlerTest extends TestCase
$repository->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser')->once();
$currencyRepos->shouldReceive('setUser')->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->times(2);
+ $repository->shouldReceive('getConfiguration')->andReturn($config)->times(3);
$repository->shouldReceive('setConfiguration')->withArgs([Mockery::any(), $expected])->once();
$accountRepos->shouldReceive('findNull')->withArgs([456])->andReturn(new Account)->once();
@@ -246,6 +248,7 @@ class ChooseAccountsHandlerTest extends TestCase
];
$expected = $config;
$expected['mapping'][1234] = 0;
+ $expected['bunq-iban'] = [];
// mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class);
@@ -256,7 +259,7 @@ class ChooseAccountsHandlerTest extends TestCase
$repository->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser')->once();
$currencyRepos->shouldReceive('setUser')->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->times(2);
+ $repository->shouldReceive('getConfiguration')->andReturn($config)->times(3);
$repository->shouldReceive('setConfiguration')->withArgs([Mockery::any(), $expected])->once();
$accountRepos->shouldReceive('findNull')->withArgs([456])->andReturnNull()->once();
@@ -291,7 +294,6 @@ class ChooseAccountsHandlerTest extends TestCase
0 => ['id' => 1234, 'name' => 'bunq'],
],
'apply-rules' => true,
-
];
// mock stuff
diff --git a/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php b/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php
index 6ba32b9bfb..2fe4812a70 100644
--- a/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php
+++ b/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php
@@ -97,6 +97,7 @@ class StageNewHandlerTest extends TestCase
'balance' => null,
'status' => null,
'type' => 'MonetaryAccountBank',
+ 'iban' => 'SM72C9584723533916792029340',
'aliases' => [
[
'name' => $alias->getName(),
@@ -124,8 +125,8 @@ class StageNewHandlerTest extends TestCase
$repository->shouldReceive('setUser')->once();
$mAccount->shouldReceive('listing')->andReturn($list)->once();
$repository->shouldReceive('getConfiguration')->once()->andReturn([]);
- $repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $expectedConfig]);
+ $repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $expectedConfig]);
$handler = new StageNewHandler;
$handler->setImportJob($job);