mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-14 16:13:54 +00:00
Expand tests.
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user