mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-17 07:08:19 +00:00
Re-implement transaction and transaction link tests.
This commit is contained in:
@@ -63,9 +63,6 @@ class TransactionControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreFailDescription(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$source = $this->getRandomAsset();
|
||||
|
||||
@@ -116,9 +113,6 @@ class TransactionControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreFailDestination(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$source = $this->getRandomAsset();
|
||||
|
||||
@@ -172,9 +166,6 @@ class TransactionControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreFailForeignCurrencyAmount(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$source = $this->getRandomAsset();
|
||||
|
||||
@@ -226,9 +217,6 @@ class TransactionControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreFailForeignCurrencyInfo(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$source = $this->getRandomAsset();
|
||||
|
||||
@@ -280,9 +268,6 @@ class TransactionControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreFailSource(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$source = $this->getRandomAsset();
|
||||
|
||||
@@ -335,9 +320,6 @@ class TransactionControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreFailStoreGroupTitle(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$source = $this->getRandomAsset();
|
||||
|
||||
@@ -395,9 +377,6 @@ class TransactionControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreFailStoreNoTransactions(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock repository
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
@@ -434,9 +413,6 @@ class TransactionControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreFailTypes(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$source = $this->getRandomAsset();
|
||||
|
||||
@@ -497,9 +473,6 @@ class TransactionControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreFailTypesDeposit(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$source = $this->getRandomAsset();
|
||||
|
||||
@@ -561,9 +534,6 @@ class TransactionControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreFailTypesTransfer(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$source = $this->getRandomAsset();
|
||||
$dest = $this->getRandomAsset($source->id);
|
||||
@@ -629,9 +599,6 @@ class TransactionControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreOK(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$source = $this->getRandomAsset();
|
||||
$group = $this->getRandomWithdrawalGroup();
|
||||
@@ -713,21 +680,22 @@ class TransactionControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdateFailBadJournal(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$group = $this->getRandomWithdrawalGroup();
|
||||
|
||||
// mock repository
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$this->mock(AccountValidator::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['invalid'])->atLeast()->once();
|
||||
$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$data = [
|
||||
'group_title' => 'Empty',
|
||||
'transactions' => [
|
||||
@@ -756,8 +724,8 @@ class TransactionControllerTest extends TestCase
|
||||
$response->assertExactJson(
|
||||
[
|
||||
'errors' => [
|
||||
'transactions.0.source_name' => ['When updating a transaction with splits, each split must have a valid transaction journal id (field "transaction_journal_id").'],
|
||||
'transactions.1.source_name' => ['When updating a transaction with splits, each split must have a valid transaction journal id (field "transaction_journal_id").'],
|
||||
'transactions.0.source_name' => ['Each split must have transaction_journal_id (either valid ID or 0).'],
|
||||
'transactions.1.source_name' => ['Each split must have transaction_journal_id (either valid ID or 0).'],
|
||||
],
|
||||
'message' => 'The given data was invalid.',
|
||||
]
|
||||
@@ -765,133 +733,6 @@ class TransactionControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update transaction but fail to submit equal destination accounts for a deposit.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Requests\TransactionUpdateRequest
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testUpdateFailDepositDestination(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$group = $this->getRandomWithdrawalGroup();
|
||||
|
||||
// mock repository
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$this->mock(AccountValidator::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
$data = [
|
||||
'group_title' => 'Empty',
|
||||
'transactions' => [
|
||||
[
|
||||
'transaction_journal_id' => 0,
|
||||
'order' => 0,
|
||||
'reconciled' => 'false',
|
||||
'tags' => [],
|
||||
'interest_date' => '2019-01-01',
|
||||
'type' => 'deposit',
|
||||
'destination_name' => 'A',
|
||||
'description' => 'Some new description',
|
||||
],
|
||||
[
|
||||
'transaction_journal_id' => 0,
|
||||
'order' => 0,
|
||||
'reconciled' => 'false',
|
||||
'tags' => [],
|
||||
'interest_date' => '2019-01-01',
|
||||
'type' => 'deposit',
|
||||
'destination_name' => 'B',
|
||||
'description' => 'Some new description',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// test API
|
||||
$response = $this->put(sprintf('/api/v1/transactions/%d', $group->id), $data, ['Accept' => 'application/json']);
|
||||
|
||||
$response->assertExactJson(
|
||||
[
|
||||
'errors' => [
|
||||
'transactions.0.destination_id' => ['All accounts in this field must be equal.'],
|
||||
],
|
||||
'message' => 'The given data was invalid.',
|
||||
]
|
||||
);
|
||||
$response->assertStatus(422);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update transaction but fail to submit equal destination accounts for a deposit.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Requests\TransactionUpdateRequest
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testUpdateFailTransferDestination(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$group = $this->getRandomWithdrawalGroup();
|
||||
|
||||
// mock repository
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$this->mock(AccountValidator::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
$data = [
|
||||
'group_title' => 'Empty',
|
||||
'transactions' => [
|
||||
[
|
||||
'transaction_journal_id' => 0,
|
||||
'order' => 0,
|
||||
'reconciled' => 'false',
|
||||
'tags' => [],
|
||||
'interest_date' => '2019-01-01',
|
||||
'type' => 'transfer',
|
||||
'destination_name' => 'A',
|
||||
'description' => 'Some new description',
|
||||
],
|
||||
[
|
||||
'transaction_journal_id' => 0,
|
||||
'order' => 0,
|
||||
'reconciled' => 'false',
|
||||
'tags' => [],
|
||||
'interest_date' => '2019-01-01',
|
||||
'type' => 'transfer',
|
||||
'destination_name' => 'B',
|
||||
'description' => 'Some new description',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// test API
|
||||
$response = $this->put(sprintf('/api/v1/transactions/%d', $group->id), $data, ['Accept' => 'application/json']);
|
||||
|
||||
$response->assertExactJson(
|
||||
[
|
||||
'errors' => [
|
||||
'transactions.0.destination_id' => ['All accounts in this field must be equal.'],
|
||||
'transactions.0.source_id' => ['All accounts in this field must be equal.'],
|
||||
],
|
||||
'message' => 'The given data was invalid.',
|
||||
]
|
||||
);
|
||||
$response->assertStatus(422);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update transaction but fail to submit equal transaction types.
|
||||
*
|
||||
@@ -900,16 +741,18 @@ class TransactionControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdateFailTypes(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$group = $this->getRandomWithdrawalGroup();
|
||||
|
||||
// mock repository
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$this->mock(AccountValidator::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['deposit'])->atLeast()->once();
|
||||
$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
@@ -953,69 +796,6 @@ class TransactionControllerTest extends TestCase
|
||||
$response->assertStatus(422);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update transaction but fail to submit equal source accounts for a withdrawal.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Requests\TransactionUpdateRequest
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testUpdateFailWithdrawalSource(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$group = $this->getRandomWithdrawalGroup();
|
||||
|
||||
// mock repository
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$this->mock(AccountValidator::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
$data = [
|
||||
'group_title' => 'Empty',
|
||||
'transactions' => [
|
||||
[
|
||||
'transaction_journal_id' => 0,
|
||||
'order' => 0,
|
||||
'reconciled' => 'false',
|
||||
'tags' => [],
|
||||
'interest_date' => '2019-01-01',
|
||||
'type' => 'withdrawal',
|
||||
'source_name' => 'A',
|
||||
'description' => 'Some new description',
|
||||
],
|
||||
[
|
||||
'transaction_journal_id' => 0,
|
||||
'order' => 0,
|
||||
'reconciled' => 'false',
|
||||
'tags' => [],
|
||||
'interest_date' => '2019-01-01',
|
||||
'type' => 'withdrawal',
|
||||
'source_name' => 'B',
|
||||
'description' => 'Some new description',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// test API
|
||||
$response = $this->put(sprintf('/api/v1/transactions/%d', $group->id), $data, ['Accept' => 'application/json']);
|
||||
|
||||
$response->assertExactJson(
|
||||
[
|
||||
'errors' => [
|
||||
'transactions.0.source_id' => ['All accounts in this field must be equal.'],
|
||||
],
|
||||
'message' => 'The given data was invalid.',
|
||||
]
|
||||
);
|
||||
$response->assertStatus(422);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the minimum amount of data to update a single withdrawal.
|
||||
*
|
||||
@@ -1024,9 +804,6 @@ class TransactionControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdateOK(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock data:
|
||||
$group = $this->getRandomWithdrawalGroup();
|
||||
|
||||
@@ -1034,9 +811,13 @@ class TransactionControllerTest extends TestCase
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionGroupTransformer::class);
|
||||
$this->mock(AccountValidator::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['invalid'])->atLeast()->once();
|
||||
$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
|
||||
|
||||
Reference in New Issue
Block a user