mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Implement user API and first tests.
This commit is contained in:
@@ -37,7 +37,6 @@ use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* todo test fire of rules with parameter
|
||||
* Class TransactionControllerTest
|
||||
*/
|
||||
class TransactionControllerTest extends TestCase
|
||||
@@ -1526,6 +1525,46 @@ class TransactionControllerTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add opposing account by a new name.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController::store
|
||||
* @covers \FireflyIII\Api\V1\Requests\TransactionRequest
|
||||
*/
|
||||
public function testSuccessNewStoreOpposingName()
|
||||
{
|
||||
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 1)->first();
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$journalRepos->shouldReceive('setUser')->once();
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
|
||||
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
|
||||
|
||||
$data = [
|
||||
'description' => 'Some transaction #' . rand(1, 1000),
|
||||
'date' => '2018-01-01',
|
||||
'type' => 'withdrawal',
|
||||
'transactions' => [
|
||||
[
|
||||
'amount' => '10',
|
||||
'currency_id' => 1,
|
||||
'source_id' => $account->id,
|
||||
'destination_name' => 'New expense account #' . rand(1, 1000),
|
||||
],
|
||||
|
||||
|
||||
],
|
||||
];
|
||||
|
||||
// test API
|
||||
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the minimum amount of data required to create a withdrawal.
|
||||
*
|
||||
@@ -1574,7 +1613,7 @@ class TransactionControllerTest extends TestCase
|
||||
public function testSuccessStoreBasic()
|
||||
{
|
||||
// default journal:
|
||||
$journal = $this->user()->transactionJournals()->first();
|
||||
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 1)->first();
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
@@ -1613,7 +1652,7 @@ class TransactionControllerTest extends TestCase
|
||||
public function testSuccessStoreBasicDeposit()
|
||||
{
|
||||
// default journal:
|
||||
$journal = $this->user()->transactionJournals()->first();
|
||||
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 2)->first();
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
@@ -2330,4 +2369,78 @@ class TransactionControllerTest extends TestCase
|
||||
$response = $this->post('/api/v1/transactions?include=tags', $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire enough to trigger an update. Since the create code already fires on the Request, no
|
||||
* need to verify all of that.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController::update
|
||||
* @covers \FireflyIII\Api\V1\Requests\TransactionRequest
|
||||
*/
|
||||
public function testUpdateBasicDeposit()
|
||||
{
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$data = [
|
||||
'description' => 'Some deposit #' . rand(1, 1000),
|
||||
'date' => '2018-01-01',
|
||||
'transactions' => [
|
||||
[
|
||||
'amount' => '10',
|
||||
'currency_id' => 1,
|
||||
'destination_id' => $account->id,
|
||||
],
|
||||
],
|
||||
];
|
||||
do {
|
||||
/** @var TransactionJournal $deposit */
|
||||
$deposit = $this->user()->transactionJournals()->where('transaction_type_id', 2)->first();
|
||||
$count = $deposit->transactions()->count();
|
||||
} while ($count !== 2);
|
||||
|
||||
$transaction = $deposit->transactions()->first();
|
||||
$repository->shouldReceive('setUser');
|
||||
$repository->shouldReceive('update')->andReturn($deposit)->once();
|
||||
|
||||
// call API
|
||||
$response = $this->put('/api/v1/transactions/' . $transaction->id, $data);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire enough to trigger an update. Since the create code already fires on the Request, no
|
||||
* need to verify all of that.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController::update
|
||||
* @covers \FireflyIII\Api\V1\Requests\TransactionRequest
|
||||
*/
|
||||
public function testUpdateBasicWithdrawal()
|
||||
{
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$data = [
|
||||
'description' => 'Some transaction #' . rand(1, 1000),
|
||||
'date' => '2018-01-01',
|
||||
'transactions' => [
|
||||
[
|
||||
'amount' => '10',
|
||||
'currency_id' => 1,
|
||||
'source_id' => $account->id,
|
||||
],
|
||||
],
|
||||
];
|
||||
do {
|
||||
/** @var TransactionJournal $withdrawal */
|
||||
$withdrawal = $this->user()->transactionJournals()->where('transaction_type_id', 1)->first();
|
||||
$count = $withdrawal->transactions()->count();
|
||||
} while ($count !== 2);
|
||||
|
||||
$transaction = $withdrawal->transactions()->first();
|
||||
$repository->shouldReceive('setUser');
|
||||
$repository->shouldReceive('update')->andReturn($withdrawal)->once();
|
||||
|
||||
// call API
|
||||
$response = $this->put('/api/v1/transactions/' . $transaction->id, $data);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
||||
35
tests/Api/V1/Controllers/UserControllerTest.php
Normal file
35
tests/Api/V1/Controllers/UserControllerTest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* UserControllerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class UserControllerTest
|
||||
*/
|
||||
class UserControllerTest extends TestCase
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user