Fix tests.

This commit is contained in:
James Cole 2017-09-27 15:46:08 +02:00
parent a1a93d9bbb
commit b80b026246
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
3 changed files with 26 additions and 93 deletions

View File

@ -84,6 +84,7 @@ class UserControllerTest extends TestCase
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('changePassword')->once();
$repository->shouldReceive('changeStatus')->once();
$repository->shouldReceive('updateEmail')->once();
$data = [
'id' => 1,
'email' => 'test@example.com',

View File

@ -151,6 +151,13 @@ class BudgetControllerTest extends TestCase
// set budget limit to current month:
$budgetLimit->start_date = Carbon::now()->startOfMonth();
$budgetLimit->end_date = Carbon::now()->endOfMonth();
$budgetInfo = [
$budget->id => [
'spent' => '0',
'budgeted' => '0',
'currentRep' => false,
],
];
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
@ -163,6 +170,7 @@ class BudgetControllerTest extends TestCase
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
@ -187,6 +195,13 @@ class BudgetControllerTest extends TestCase
// mock stuff
$budget = factory(Budget::class)->make();
$budgetLimit = factory(BudgetLimit::class)->make();
$budgetInfo = [
$budget->id => [
'spent' => '0',
'budgeted' => '0',
'currentRep' => false,
],
];
// set budget limit to current month:
$budgetLimit->start_date = Carbon::now()->startOfMonth();
@ -204,6 +219,7 @@ class BudgetControllerTest extends TestCase
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
$this->be($this->user());
@ -231,6 +247,13 @@ class BudgetControllerTest extends TestCase
// set budget limit to current month:
$budgetLimit->start_date = Carbon::now()->startOfMonth();
$budgetLimit->end_date = Carbon::now()->endOfMonth();
$budgetInfo = [
$budget->id => [
'spent' => '0',
'budgeted' => '0',
'currentRep' => false,
],
];
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
@ -244,6 +267,7 @@ class BudgetControllerTest extends TestCase
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
$this->be($this->user());
@ -373,7 +397,7 @@ class BudgetControllerTest extends TestCase
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('setAvailableBudget');
$data = ['amount' => '200','start' => '2017-01-01','end' => '2017-01-31'];
$data = ['amount' => '200', 'start' => '2017-01-01', 'end' => '2017-01-31'];
$this->be($this->user());
$response = $this->post(route('budgets.income.post'), $data);
$response->assertStatus(302);

View File

@ -52,98 +52,6 @@ class JsonControllerTest extends TestCase
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\JsonController::boxBillsPaid
*/
public function testBoxBillsPaid()
{
// mock stuff
$billRepos = $this->mock(BillRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$billRepos->shouldReceive('getBillsPaidInRange')->andReturn('-100');
$this->be($this->user());
$currency = Amount::getDefaultCurrency();
$response = $this->get(route('json.box.paid'));
$response->assertStatus(200);
$response->assertExactJson(['amount' => Amount::formatAnything($currency, '100', false), 'amount_raw' => '100', 'box' => 'bills-paid']);
}
/**
* @covers \FireflyIII\Http\Controllers\JsonController::boxBillsUnpaid
*/
public function testBoxBillsUnpaid()
{
// mock stuff
$billRepos = $this->mock(BillRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$billRepos->shouldReceive('getBillsUnpaidInRange')->andReturn('100');
$this->be($this->user());
$currency = Amount::getDefaultCurrency();
$response = $this->get(route('json.box.unpaid'));
$response->assertStatus(200);
$response->assertExactJson(['amount' => Amount::formatAnything($currency, '100', false), 'amount_raw' => '100', 'box' => 'bills-unpaid']);
}
/**
* @covers \FireflyIII\Http\Controllers\JsonController::boxIn
*/
public function testBoxIn()
{
// mock stuff
$collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$transaction = factory(Transaction::class)->make();
$transaction->transaction_amount = '100.00';
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->once();
$collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction]))->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->once();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once();
$this->be($this->user());
$currency = Amount::getDefaultCurrency();
$response = $this->get(route('json.box.in'));
$response->assertStatus(200);
$response->assertExactJson(['amount' => Amount::formatAnything($currency, '100', false), 'amount_raw' => '100', 'box' => 'in']);
}
/**
* @covers \FireflyIII\Http\Controllers\JsonController::boxOut
*/
public function testBoxOut()
{
// mock stuff
$collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$transaction = factory(Transaction::class)->make();
$transaction->transaction_amount = '100.00';
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->once();
$collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction]))->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once();
$this->be($this->user());
$currency = Amount::getDefaultCurrency();
$response = $this->get(route('json.box.out'));
$response->assertStatus(200);
$response->assertExactJson(['amount' => Amount::formatAnything($currency, '100', false), 'amount_raw' => '100', 'box' => 'out']);
}
/**
* @covers \FireflyIII\Http\Controllers\JsonController::budgets
*/