mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expand tests.
This commit is contained in:
parent
e389d0f7fa
commit
cae4faad0a
@ -32,7 +32,6 @@ use Illuminate\Validation\Validator;
|
||||
|
||||
|
||||
/**
|
||||
* todo cannot submit using currency not part of source / dest
|
||||
* Class TransactionRequest
|
||||
*/
|
||||
class TransactionRequest extends Request
|
||||
@ -146,9 +145,6 @@ class TransactionRequest extends Request
|
||||
'transactions.*.source_name' => 'between:1,255|nullable',
|
||||
'transactions.*.destination_id' => ['numeric', 'nullable', new BelongsUser],
|
||||
'transactions.*.destination_name' => 'between:1,255|nullable',
|
||||
|
||||
// todo tags
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -45,12 +45,13 @@ class PiggyBankEventFactory
|
||||
*/
|
||||
public function create(TransactionJournal $journal, ?PiggyBank $piggyBank): ?PiggyBankEvent
|
||||
{
|
||||
Log::debug(sprintf('Now in PiggyBankEventCreate for a %s', $journal->transactionType->type));
|
||||
if (is_null($piggyBank)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// is a transfer?
|
||||
if (!TransactionType::TRANSFER === $journal->transactionType->type) {
|
||||
if (!(TransactionType::TRANSFER === $journal->transactionType->type)) {
|
||||
Log::info(sprintf('Will not connect %s #%d to a piggy bank.', $journal->transactionType->type, $journal->id));
|
||||
|
||||
return null;
|
||||
|
@ -78,9 +78,10 @@ class TransactionJournalFactory
|
||||
// link bill:
|
||||
$this->connectBill($journal, $data);
|
||||
|
||||
// link piggy bank:
|
||||
// link piggy bank (if transfer)
|
||||
$this->connectPiggyBank($journal, $data);
|
||||
|
||||
|
||||
// link tags:
|
||||
$this->connectTags($journal, $data);
|
||||
|
||||
|
@ -339,6 +339,10 @@ class SingleController extends Controller
|
||||
$doSplit = 1 === intval($request->get('split_journal'));
|
||||
$createAnother = 1 === intval($request->get('create_another'));
|
||||
$data = $request->getJournalData();
|
||||
|
||||
// todo call factory instead of repository
|
||||
|
||||
|
||||
$journal = $repository->store($data);
|
||||
if (null === $journal->id) {
|
||||
// error!
|
||||
|
@ -100,7 +100,6 @@ $factory->define(
|
||||
'user_id' => 1,
|
||||
'transaction_type_id' => 1,
|
||||
'bill_id' => null,
|
||||
// TODO update this transaction currency reference.
|
||||
'transaction_currency_id' => 1,
|
||||
'description' => $faker->words(3, true),
|
||||
'date' => '2017-01-01',
|
||||
|
@ -34,11 +34,7 @@ use Laravel\Passport\Passport;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* todo test bad budget, bad category
|
||||
* todo test bad piggy, bad bill
|
||||
* todo test fire of rules with parameter
|
||||
* todo test bad currency, bad foreign currency
|
||||
* todo test reconciled, identifier
|
||||
* Class TransactionControllerTest
|
||||
*/
|
||||
class TransactionControllerTest extends TestCase
|
||||
@ -76,6 +72,80 @@ class TransactionControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit with bad currency code
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController::store
|
||||
* @covers \FireflyIII\Api\V1\Requests\TransactionRequest
|
||||
*/
|
||||
public function testFailCurrencyCode()
|
||||
{
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||
$data = [
|
||||
'description' => 'Some transaction #' . rand(1, 1000),
|
||||
'date' => '2018-01-01',
|
||||
'type' => 'withdrawal',
|
||||
'transactions' => [
|
||||
[
|
||||
'amount' => '10',
|
||||
'currency_code' => 'FU2',
|
||||
'source_id' => $account->id,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// test API
|
||||
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(422);
|
||||
$response->assertExactJson(
|
||||
[
|
||||
'message' => 'The given data was invalid.',
|
||||
'errors' => [
|
||||
'transactions.0.currency_code' => [
|
||||
'The selected transactions.0.currency_code is invalid.',
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit with bad currency ID.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController::store
|
||||
* @covers \FireflyIII\Api\V1\Requests\TransactionRequest
|
||||
*/
|
||||
public function testFailCurrencyId()
|
||||
{
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||
$data = [
|
||||
'description' => 'Some transaction #' . rand(1, 1000),
|
||||
'date' => '2018-01-01',
|
||||
'type' => 'withdrawal',
|
||||
'transactions' => [
|
||||
[
|
||||
'amount' => '10',
|
||||
'currency_id' => 1991,
|
||||
'source_id' => $account->id,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// test API
|
||||
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(422);
|
||||
$response->assertExactJson(
|
||||
[
|
||||
'message' => 'The given data was invalid.',
|
||||
'errors' => [
|
||||
'transactions.0.currency_id' => [
|
||||
'The selected transactions.0.currency_id is invalid.',
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty descriptions
|
||||
*
|
||||
@ -1852,6 +1922,54 @@ class TransactionControllerTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the minimum amount of data required to create a withdrawal.
|
||||
* When sending a piggy bank by name, this must be reflected in the output.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController::store
|
||||
* @covers \FireflyIII\Api\V1\Requests\TransactionRequest
|
||||
*/
|
||||
public function testSuccessStorePiggyDeposit()
|
||||
{
|
||||
$dest = auth()->user()->accounts()->where('account_type_id', 3)->first();
|
||||
$piggy = auth()->user()->piggyBanks()->first();
|
||||
$data = [
|
||||
'description' => 'Some deposit #' . rand(1, 1000),
|
||||
'date' => '2018-01-01',
|
||||
'type' => 'deposit',
|
||||
'piggy_bank_name' => $piggy->name,
|
||||
'transactions' => [
|
||||
[
|
||||
'amount' => '10',
|
||||
'currency_id' => 1,
|
||||
'destination_id' => $dest->id,
|
||||
],
|
||||
],
|
||||
];
|
||||
// test API
|
||||
$response = $this->post('/api/v1/transactions?include=piggy_bank_events', $data, ['Accept' => 'application/json']);
|
||||
$this->assertFalse(isset($response->json()['included']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
[
|
||||
'data' => [
|
||||
'type' => 'transactions',
|
||||
'attributes' => [
|
||||
'description' => $data['description'],
|
||||
'date' => $data['date'],
|
||||
'type' => 'Deposit',
|
||||
'destination_id' => $dest->id,
|
||||
'destination_name' => $dest->name,
|
||||
'destination_type' => 'Asset account',
|
||||
'amount' => 10,
|
||||
],
|
||||
'links' => [],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the minimum amount of data required to create a withdrawal.
|
||||
* When sending a piggy bank by name, this must be reflected in the output.
|
||||
@ -1914,7 +2032,6 @@ class TransactionControllerTest extends TestCase
|
||||
/**
|
||||
* Submit the minimum amount of data required to create a withdrawal.
|
||||
* When sending a piggy bank by name, this must be reflected in the output.
|
||||
* TODO only when sending a transfer. Ignore it with withdrawals.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController::store
|
||||
* @covers \FireflyIII\Api\V1\Requests\TransactionRequest
|
||||
|
Loading…
Reference in New Issue
Block a user