Fix tests.

This commit is contained in:
James Cole
2018-08-17 06:45:57 +02:00
parent df0e2dd2a2
commit f319005357
11 changed files with 46 additions and 70 deletions

View File

@@ -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.');

View File

@@ -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'),
];
}

View File

@@ -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);

View File

@@ -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

View File

@@ -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);

View File

@@ -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

View File

@@ -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');
}
}

View File

@@ -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();

View File

@@ -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']));
}
/**

View File

@@ -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

View File

@@ -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);