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

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