mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Expand tests.
This commit is contained in:
@@ -32,7 +32,6 @@ use Illuminate\Validation\Validator;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* todo cannot submit using currency not part of source / dest
|
|
||||||
* Class TransactionRequest
|
* Class TransactionRequest
|
||||||
*/
|
*/
|
||||||
class TransactionRequest extends Request
|
class TransactionRequest extends Request
|
||||||
@@ -146,9 +145,6 @@ class TransactionRequest extends Request
|
|||||||
'transactions.*.source_name' => 'between:1,255|nullable',
|
'transactions.*.source_name' => 'between:1,255|nullable',
|
||||||
'transactions.*.destination_id' => ['numeric', 'nullable', new BelongsUser],
|
'transactions.*.destination_id' => ['numeric', 'nullable', new BelongsUser],
|
||||||
'transactions.*.destination_name' => 'between:1,255|nullable',
|
'transactions.*.destination_name' => 'between:1,255|nullable',
|
||||||
|
|
||||||
// todo tags
|
|
||||||
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,12 +45,13 @@ class PiggyBankEventFactory
|
|||||||
*/
|
*/
|
||||||
public function create(TransactionJournal $journal, ?PiggyBank $piggyBank): ?PiggyBankEvent
|
public function create(TransactionJournal $journal, ?PiggyBank $piggyBank): ?PiggyBankEvent
|
||||||
{
|
{
|
||||||
|
Log::debug(sprintf('Now in PiggyBankEventCreate for a %s', $journal->transactionType->type));
|
||||||
if (is_null($piggyBank)) {
|
if (is_null($piggyBank)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// is a transfer?
|
// 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));
|
Log::info(sprintf('Will not connect %s #%d to a piggy bank.', $journal->transactionType->type, $journal->id));
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@@ -78,9 +78,10 @@ class TransactionJournalFactory
|
|||||||
// link bill:
|
// link bill:
|
||||||
$this->connectBill($journal, $data);
|
$this->connectBill($journal, $data);
|
||||||
|
|
||||||
// link piggy bank:
|
// link piggy bank (if transfer)
|
||||||
$this->connectPiggyBank($journal, $data);
|
$this->connectPiggyBank($journal, $data);
|
||||||
|
|
||||||
|
|
||||||
// link tags:
|
// link tags:
|
||||||
$this->connectTags($journal, $data);
|
$this->connectTags($journal, $data);
|
||||||
|
|
||||||
|
@@ -339,6 +339,10 @@ class SingleController extends Controller
|
|||||||
$doSplit = 1 === intval($request->get('split_journal'));
|
$doSplit = 1 === intval($request->get('split_journal'));
|
||||||
$createAnother = 1 === intval($request->get('create_another'));
|
$createAnother = 1 === intval($request->get('create_another'));
|
||||||
$data = $request->getJournalData();
|
$data = $request->getJournalData();
|
||||||
|
|
||||||
|
// todo call factory instead of repository
|
||||||
|
|
||||||
|
|
||||||
$journal = $repository->store($data);
|
$journal = $repository->store($data);
|
||||||
if (null === $journal->id) {
|
if (null === $journal->id) {
|
||||||
// error!
|
// error!
|
||||||
|
@@ -100,7 +100,6 @@ $factory->define(
|
|||||||
'user_id' => 1,
|
'user_id' => 1,
|
||||||
'transaction_type_id' => 1,
|
'transaction_type_id' => 1,
|
||||||
'bill_id' => null,
|
'bill_id' => null,
|
||||||
// TODO update this transaction currency reference.
|
|
||||||
'transaction_currency_id' => 1,
|
'transaction_currency_id' => 1,
|
||||||
'description' => $faker->words(3, true),
|
'description' => $faker->words(3, true),
|
||||||
'date' => '2017-01-01',
|
'date' => '2017-01-01',
|
||||||
|
@@ -34,11 +34,7 @@ use Laravel\Passport\Passport;
|
|||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* todo test bad budget, bad category
|
|
||||||
* todo test bad piggy, bad bill
|
|
||||||
* todo test fire of rules with parameter
|
* todo test fire of rules with parameter
|
||||||
* todo test bad currency, bad foreign currency
|
|
||||||
* todo test reconciled, identifier
|
|
||||||
* Class TransactionControllerTest
|
* Class TransactionControllerTest
|
||||||
*/
|
*/
|
||||||
class TransactionControllerTest extends TestCase
|
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
|
* 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.
|
* 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.
|
* 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.
|
* 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.
|
* 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\Controllers\TransactionController::store
|
||||||
* @covers \FireflyIII\Api\V1\Requests\TransactionRequest
|
* @covers \FireflyIII\Api\V1\Requests\TransactionRequest
|
||||||
|
Reference in New Issue
Block a user