Fix the unit tests.

This commit is contained in:
James Cole
2017-08-18 15:32:11 +02:00
parent 7d8876f03c
commit 9b17715175
8 changed files with 101 additions and 70 deletions

View File

@@ -143,12 +143,15 @@ class ExportControllerTest extends TestCase
$processor->shouldReceive('collectOldUploads')->once();
$processor->shouldReceive('collectAttachments')->once();
$job = new ExportJob;
$job->user = $this->user();
$repository->shouldReceive('changeStatus')->andReturn(true);
$repository->shouldReceive('findByKey')->andReturn(new ExportJob);
$repository->shouldReceive('findByKey')->andReturn($job);
$this->be($this->user());
$response = $this->post(route('export.export'), $data);
$response = $this->post(route('export.submit'), $data);
$response->assertStatus(200);
$response->assertSee('ok');
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* AutoCompleteControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Json;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase;
/**
* Class AutoCompleteControllerTest
*
* @package Tests\Feature\Controllers\Json
*/
class AutoCompleteControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController::allAccounts
*/
public function testAllAccounts()
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')
->withArgs([[AccountType::REVENUE, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::DEFAULT, AccountType::ASSET]])
->andReturn(new Collection);
$this->be($this->user());
$response = $this->get(route('json.all-accounts'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController::expenseAccounts
*/
public function testExpenseAccounts()
{
// mock stuff
$account = factory(Account::class)->make();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->once()->andReturn(
new Collection([$account])
);
$this->be($this->user());
$response = $this->get(route('json.expense-accounts'));
$response->assertStatus(200);
$response->assertExactJson([$account->name]);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController::revenueAccounts
*/
public function testRevenueAccounts()
{
// mock stuff
$account = factory(Account::class)->make();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn(
new Collection([$account])
);
$this->be($this->user());
$response = $this->get(route('json.revenue-accounts'));
$response->assertStatus(200);
$response->assertExactJson([$account->name]);
}
}

View File

@@ -54,21 +54,6 @@ class JsonControllerTest extends TestCase
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\JsonController::allAccounts
*/
public function testAllAccounts()
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')
->withArgs([[AccountType::REVENUE, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::DEFAULT, AccountType::ASSET]])
->andReturn(new Collection);
$this->be($this->user());
$response = $this->get(route('json.all-accounts'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\JsonController::allTransactionJournals()
*/
@@ -210,45 +195,6 @@ class JsonControllerTest extends TestCase
$response->assertExactJson([$category->name]);
}
/**
* @covers \FireflyIII\Http\Controllers\JsonController::expenseAccounts
*/
public function testExpenseAccounts()
{
// mock stuff
$account = factory(Category::class)->make();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->once()->andReturn(
new Collection([$account])
);
$this->be($this->user());
$response = $this->get(route('json.expense-accounts'));
$response->assertStatus(200);
$response->assertExactJson([$account->name]);
}
/**
* @covers \FireflyIII\Http\Controllers\JsonController::revenueAccounts
*/
public function testRevenueAccounts()
{
// mock stuff
$account = factory(Category::class)->make();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn(
new Collection([$account])
);
$this->be($this->user());
$response = $this->get(route('json.revenue-accounts'));
$response->assertStatus(200);
$response->assertExactJson([$account->name]);
}
/**
* @covers \FireflyIII\Http\Controllers\JsonController::tags