. */ declare(strict_types=1); namespace Tests\Feature\Controllers\Json; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Log; use Tests\TestCase; /** * * Class ReconcileControllerTest */ class ReconcileControllerTest extends TestCase { /** * */ public function setUp() { parent::setUp(); Log::debug(sprintf('Now in %s.', \get_class($this))); } /** * Test overview of reconciliation. * * @covers \FireflyIII\Http\Controllers\Json\ReconcileController */ public function testOverview(): void { $transactions = $this->user()->transactions()->inRandomOrder()->take(3)->get(); $repository = $this->mock(JournalRepositoryInterface::class); $repository->shouldReceive('firstNull')->andReturn(new TransactionJournal); $repository->shouldReceive('getTransactionsById')->andReturn($transactions)->twice(); $parameters = [ 'startBalance' => '0', 'endBalance' => '10', 'transactions' => [1, 2, 3], 'cleared' => [4, 5, 6], ]; $this->be($this->user()); $response = $this->get(route('accounts.reconcile.overview', [1, '20170101', '20170131']) . '?' . http_build_query($parameters)); $response->assertStatus(200); } /** * Test overview when it's not an asset. * * @covers \FireflyIII\Http\Controllers\Json\ReconcileController * @expectedExceptionMessage is not an asset account */ public function testOverviewNotAsset(): void { $account = $this->user()->accounts()->where('account_type_id', '!=', 3)->first(); $parameters = [ 'startBalance' => '0', 'endBalance' => '10', 'transactions' => [1, 2, 3], 'cleared' => [4, 5, 6], ]; $this->be($this->user()); $response = $this->get(route('accounts.reconcile.overview', [$account->id, '20170101', '20170131']) . '?' . http_build_query($parameters)); $response->assertStatus(500); } /** * List transactions for reconciliation view. * * @covers \FireflyIII\Http\Controllers\Json\ReconcileController */ public function testTransactions(): void { $repository = $this->mock(CurrencyRepositoryInterface::class); $repository->shouldReceive('findNull')->once()->andReturn(TransactionCurrency::find(1)); $this->be($this->user()); $response = $this->get(route('accounts.reconcile.transactions', [1, '20170101', '20170131'])); $response->assertStatus(200); } /** * @covers \FireflyIII\Http\Controllers\Json\ReconcileController */ public function testTransactionsInitialBalance(): void { $transaction = Transaction::leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') ->where('accounts.user_id', $this->user()->id)->where('accounts.account_type_id', 6)->first(['account_id']); $this->be($this->user()); $response = $this->get(route('accounts.reconcile.transactions', [$transaction->account_id, '20170101', '20170131'])); $response->assertStatus(302); } }