Files
firefly-iii/tests/Api/V1/Controllers/TransactionControllerTest.php

2929 lines
113 KiB
PHP
Raw Normal View History

2018-02-18 10:31:15 +01:00
<?php
/**
* TransactionControllerTest.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;
2018-09-27 06:26:03 +02:00
use Exception;
use FireflyIII\Events\StoredTransactionJournal;
use FireflyIII\Events\UpdatedTransactionJournal;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Models\TransactionCurrency;
2018-02-28 20:18:47 +01:00
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
2018-12-12 20:30:25 +01:00
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
2018-02-18 10:31:15 +01:00
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
2018-12-16 13:55:19 +01:00
use FireflyIII\Transformers\AttachmentTransformer;
use FireflyIII\Transformers\PiggyBankEventTransformer;
use FireflyIII\Transformers\TransactionTransformer;
2018-12-12 20:30:25 +01:00
use Illuminate\Pagination\LengthAwarePaginator;
2018-02-18 10:31:15 +01:00
use Illuminate\Support\Collection;
use Laravel\Passport\Passport;
2018-02-28 20:18:47 +01:00
use Log;
2018-02-18 10:31:15 +01:00
use Tests\TestCase;
/**
* Class TransactionControllerTest
*/
class TransactionControllerTest extends TestCase
{
/**
*
*/
2018-09-02 20:13:25 +02:00
public function setUp(): void
2018-02-18 10:31:15 +01:00
{
parent::setUp();
Passport::actingAs($this->user());
2019-04-09 20:05:20 +02:00
Log::info(sprintf('Now in %s.', get_class($this)));
2018-02-18 10:31:15 +01:00
}
2018-02-19 20:02:27 +01:00
/**
* Submit with bad currency code
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-19 20:02:27 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testFailCurrencyCode(): void
2018-02-19 20:02:27 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls:
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-19 20:02:27 +01:00
'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.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-19 20:02:27 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testFailCurrencyId(): void
2018-02-19 20:02:27 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls:
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-19 20:02:27 +01:00
'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.',
],
],
]
);
}
2018-02-18 10:31:15 +01:00
/**
* Empty descriptions
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testFailEmptyDescriptions(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls:
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$data = [
'description' => '',
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'description' => '',
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(422);
$response->assertExactJson(
[
'message' => 'The given data was invalid.',
'errors' => [
'description' => [
'The description field is required.',
'The description must be between 1 and 255 characters.',
],
'transactions.0.description' => [
2018-02-28 20:18:47 +01:00
'Transaction description should not equal global description.',
],
],
]
);
}
/**
* Submit all empty descriptions for transactions.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testFailEmptySplitDescriptions(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls:
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$data = [
'description' => 'Split journal #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'description' => '',
],
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'description' => '',
],
],
];
// 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.description' => [
'The transaction description field is required.',
],
'transactions.1.description' => [
'The transaction description field is required.',
],
],
]
);
}
/**
* Submitted expense account instead of asset account.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-18 20:40:32 +01:00
* @covers \FireflyIII\Rules\BelongsUser
*/
2018-05-11 19:58:10 +02:00
public function testFailExpenseID(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 4)->first();
// mock calls:
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'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.source_id' => [
'This value is invalid for this field.',
],
],
]
);
}
/**
* Submitted expense account name instead of asset account name.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testFailExpenseName(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);
2018-04-27 11:29:09 +02:00
$accountRepos->shouldReceive('findByName')->andReturn(null);
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
2018-02-28 20:18:47 +01:00
'source_name' => 'Expense name',
],
],
];
// 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.source_name' => [
'This value is invalid for this field.',
],
],
]
);
}
/**
* Submit no asset account info at all.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testFailNoAsset(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
],
],
];
// 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.source_id' => [
'The transactions.0.source_id field is required.',
],
],
]
);
}
/**
* Submit no transactions.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testFailNoData(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(422);
$response->assertExactJson(
[
'message' => 'The given data was invalid.',
'errors' => [
'description' => [
'Need at least one transaction.',
],
],
]
);
}
/**
* Submit foreign currency without foreign currency info.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testFailNoForeignCurrencyInfo(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
// mock stuff:
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$data = [
'description' => 'Split journal #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'foreign_amount' => 10,
'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.foreign_amount' => [
'The content of this field is invalid without currency information.',
],
],
]
);
}
/**
* Submit revenue ID instead of expense ID.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testFailOpposingRevenueID(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$opposing = $this->user()->accounts()->where('account_type_id', 5)->first();
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$opposing]));
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'destination_id' => $opposing->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.destination_id' => [
'This value is invalid for this field.',
],
],
]
2018-02-18 20:40:32 +01:00
);
}
/**
* Submit journal with a bill ID that is not yours.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Rules\BelongsUser
2018-02-18 20:40:32 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testFailOwnershipBillId(): void
2018-02-18 20:40:32 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
2018-02-18 20:40:32 +01:00
// move account to other user
2018-02-28 20:18:47 +01:00
$bill = $this->user()->bills()->first();
2018-02-18 20:40:32 +01:00
$bill->user_id = $this->emptyUser()->id;
$bill->save();
// submit with another account.
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-18 20:40:32 +01:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'bill_id' => $bill->id,
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'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' => [
'bill_id' => [
'This value is invalid for this field.',
],
],
]
);
// put bill back:
$bill->user_id = $this->user()->id;
$bill->save();
}
/**
2018-07-01 09:27:22 +02:00
* Submit journal with a bill name that is not yours.
2018-02-18 20:40:32 +01:00
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Rules\BelongsUser
2018-02-18 20:40:32 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testFailOwnershipBillName(): void
2018-02-18 20:40:32 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
2018-02-18 20:40:32 +01:00
// move account to other user
2018-02-28 20:18:47 +01:00
$bill = $this->user()->bills()->first();
2018-02-18 20:40:32 +01:00
$bill->user_id = $this->emptyUser()->id;
$bill->save();
// submit with another account.
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-18 20:40:32 +01:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'bill_name' => $bill->name,
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'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' => [
'bill_name' => [
'This value is invalid for this field.',
],
],
]
);
// put bill back:
$bill->user_id = $this->user()->id;
$bill->save();
}
/**
* Submit journal with a budget ID that is not yours.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Rules\BelongsUser
2018-02-18 20:40:32 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testFailOwnershipBudgetId(): void
2018-02-18 20:40:32 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
2018-02-18 20:40:32 +01:00
// move account to other user
2018-02-28 20:18:47 +01:00
$budget = $this->user()->budgets()->first();
2018-02-18 20:40:32 +01:00
$budget->user_id = $this->emptyUser()->id;
$budget->save();
// submit with another account.
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-18 20:40:32 +01:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'budget_id' => $budget->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.budget_id' => [
'This value is invalid for this field.',
],
],
]
);
// put budget back:
$budget->user_id = $this->user()->id;
$budget->save();
}
/**
* Submit journal with a budget name that is not yours.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Rules\BelongsUser
2018-02-18 20:40:32 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testFailOwnershipBudgetName(): void
2018-02-18 20:40:32 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
2018-02-18 20:40:32 +01:00
// move account to other user
2018-02-28 20:18:47 +01:00
$budget = $this->user()->budgets()->first();
2018-02-18 20:40:32 +01:00
$budget->user_id = $this->emptyUser()->id;
$budget->save();
// submit with another account.
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-18 20:40:32 +01:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'budget_name' => $budget->name,
],
],
];
// 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.budget_name' => [
'This value is invalid for this field.',
],
],
]
);
// put bill back:
$budget->user_id = $this->user()->id;
$budget->save();
}
/**
* Submit journal with a category ID that is not yours.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Rules\BelongsUser
2018-02-18 20:40:32 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testFailOwnershipCategoryId(): void
2018-02-18 20:40:32 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
2018-02-18 20:40:32 +01:00
// move account to other user
2018-02-28 20:18:47 +01:00
$category = $this->user()->categories()->first();
2018-02-18 20:40:32 +01:00
$category->user_id = $this->emptyUser()->id;
$category->save();
// submit with another account.
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-18 20:40:32 +01:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'category_id' => $category->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.category_id' => [
'This value is invalid for this field.',
],
],
]
);
// put category back:
$category->user_id = $this->user()->id;
$category->save();
}
/**
* Submit journal with a piggy bank that is not yours.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Rules\BelongsUser
2018-02-18 20:40:32 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testFailOwnershipPiggyBankID(): void
2018-02-18 20:40:32 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-18 20:40:32 +01:00
// move account to other user
2018-02-28 20:18:47 +01:00
$move = $this->user()->accounts()->where('account_type_id', 3)->first();
2018-02-18 20:40:32 +01:00
$move->user_id = $this->emptyUser()->id;
2018-02-28 20:18:47 +01:00
$piggyBank = $this->user()->piggyBanks()->first();
2018-02-18 20:40:32 +01:00
$oldId = $piggyBank->account_id;
$piggyBank->account_id = $move->id;
$move->save();
$piggyBank->save();
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
2018-02-18 20:40:32 +01:00
// submit with another account.
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-18 20:40:32 +01:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'piggy_bank_id' => $piggyBank->id,
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'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' => [
'piggy_bank_id' => [
'This value is invalid for this field.',
],
],
]
);
// put account back:
$move->user_id = $this->user()->id;
$move->save();
$piggyBank->account_id = $oldId;
$piggyBank->save();
}
/**
* Submit journal with a piggy bank that is not yours.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Rules\BelongsUser
2018-02-18 20:40:32 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testFailOwnershipPiggyBankName(): void
2018-02-18 20:40:32 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-18 20:40:32 +01:00
// move account to other user
2018-02-28 20:18:47 +01:00
$move = $this->user()->accounts()->where('account_type_id', 3)->first();
2018-02-18 20:40:32 +01:00
$move->user_id = $this->emptyUser()->id;
2018-02-28 20:18:47 +01:00
$piggyBank = $this->user()->piggyBanks()->first();
2018-02-18 20:40:32 +01:00
$oldId = $piggyBank->account_id;
$piggyBank->account_id = $move->id;
$move->save();
$piggyBank->save();
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
2018-02-18 20:40:32 +01:00
// submit with another account.
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-18 20:40:32 +01:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'piggy_bank_name' => $piggyBank->name,
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'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' => [
'piggy_bank_name' => [
'This value is invalid for this field.',
],
],
]
);
// put account back:
$move->user_id = $this->user()->id;
$move->save();
$piggyBank->account_id = $oldId;
$piggyBank->save();
}
/**
* Submitted revenue account instead of asset account in deposit.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-18 20:40:32 +01:00
* @covers \FireflyIII\Rules\BelongsUser
*/
2018-05-11 19:58:10 +02:00
public function testFailRevenueID(): void
2018-02-18 20:40:32 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 4)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-18 20:40:32 +01:00
'date' => '2018-01-01',
'type' => 'deposit',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'destination_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.destination_id' => [
'This value is invalid for this field.',
],
],
]
);
}
2018-02-20 18:03:02 +01:00
/**
* Try to store a withdrawal with different source accounts.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-20 18:03:02 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testFailSplitDeposit(): void
2018-02-20 18:03:02 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$second = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $account->id)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$second]));
$data = [
'description' => 'Some deposit #' . random_int(1, 10000),
2018-02-20 18:03:02 +01:00
'date' => '2018-01-01',
'type' => 'deposit',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'destination_id' => $account->id,
'description' => 'Part 1',
],
[
'amount' => '10',
'currency_id' => 1,
'destination_id' => $second->id,
'description' => 'Part 2',
],
],
];
// 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.destination_id' => [
'All accounts in this field must be equal.',
],
],
]
);
}
/**
* Try to store a withdrawal with different source accounts.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-20 18:03:02 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testFailSplitTransfer(): void
2018-02-20 18:03:02 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$second = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $account->id)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$second]));
$data = [
'description' => 'Some transfer #' . random_int(1, 10000),
2018-02-20 18:03:02 +01:00
'date' => '2018-01-01',
'type' => 'transfer',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'destination_id' => $second->id,
'description' => 'Part 1',
],
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $second->id,
'destination_id' => $account->id,
'description' => 'Part 2',
],
],
];
// 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.source_id' => [
'All accounts in this field must be equal.',
],
'transactions.0.destination_id' => [
'All accounts in this field must be equal.',
],
2018-03-24 06:08:50 +01:00
'transactions.1.destination_id' => [
2018-07-01 09:27:22 +02:00
'The source account equals the destination account.',
2018-03-24 06:08:50 +01:00
],
2018-02-20 18:03:02 +01:00
],
]
);
}
/**
* Try to store a withdrawal with different source accounts.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-20 18:03:02 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testFailSplitWithdrawal(): void
2018-02-20 18:03:02 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$second = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $account->id)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$second]));
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-20 18:03:02 +01:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'description' => 'Part 1',
],
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $second->id,
'description' => 'Part 2',
],
],
];
// 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.source_id' => [
'All accounts in this field must be equal.',
],
],
]
);
}
2018-02-18 10:31:15 +01:00
/**
* Submit a transaction (withdrawal) with attached bill ID
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-18 10:31:15 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testSuccessBillId(): void
2018-02-18 10:31:15 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
// default journal:
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
2018-12-12 20:30:25 +01:00
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]))->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$bill = $this->user()->bills()->first();
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-18 10:31:15 +01:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'bill_id' => $bill->id,
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
/**
* Submit a transaction (withdrawal) with attached bill ID
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-18 10:31:15 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testSuccessBillName(): void
2018-02-18 10:31:15 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
// default journal:
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
2018-12-12 20:30:25 +01:00
$accountRepos->shouldReceive('setUser')->once();
2018-02-28 20:18:47 +01:00
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-02-28 20:18:47 +01:00
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$bill = $this->user()->bills()->first();
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-18 10:31:15 +01:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'bill_name' => $bill->name,
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
2018-03-03 08:12:18 +01:00
/**
* Add opposing account by a new name.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-03-03 08:12:18 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testSuccessNewStoreOpposingName(): void
2018-03-03 08:12:18 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-03-03 08:12:18 +01:00
$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);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-03-03 08:12:18 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-03-03 08:12:18 +01:00
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-03-03 08:12:18 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-03-03 08:12:18 +01:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'destination_name' => 'New expense account #' . random_int(1, 10000),
2018-03-03 08:12:18 +01:00
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
2018-02-18 10:31:15 +01:00
/**
* Submit the minimum amount of data required to create a withdrawal.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreAccountName(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
// default journal:
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-02-28 20:18:47 +01:00
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_name' => $account->name,
],
],
];
// 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.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-18 10:31:15 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreBasic(): void
2018-02-18 10:31:15 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
// default journal:
2018-03-03 08:12:18 +01:00
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 1)->first();
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-02-28 20:18:47 +01:00
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-18 10:31:15 +01:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
2018-03-28 19:38:20 +02:00
/**
* Submit the minimum amount of data required to create a withdrawal.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-03-28 19:38:20 +02:00
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreBasicByName(): void
2018-03-28 19:38:20 +02:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-03-28 19:38:20 +02:00
// default journal:
$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);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-03-28 19:38:20 +02:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);
2018-04-27 11:29:09 +02:00
$accountRepos->shouldReceive('findByName')->andReturn($account);
2018-03-28 19:38:20 +02:00
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-03-28 19:38:20 +02:00
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-03-28 19:38:20 +02:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-03-28 19:38:20 +02:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_name' => $account->name,
],
],
];
// 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 deposit.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreBasicDeposit(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
// default journal:
2018-03-03 08:12:18 +01:00
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 2)->first();
2018-02-28 20:18:47 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-02-28 20:18:47 +01:00
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'deposit',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'destination_id' => $account->id,
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
/**
* Submit with existing budget ID, see it reflected in output.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreBudgetId(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$budget = $this->user()->budgets()->first();
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'budget_id' => $budget->id,
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
/**
* Submit with existing budget name, see it reflected in output.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreBudgetName(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$budget = $this->user()->budgets()->first();
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-02-28 20:18:47 +01:00
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'budget_name' => $budget->name,
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
/**
* Submit with existing category ID, see it reflected in output.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreCategoryID(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$category = $this->user()->categories()->first();
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'category_id' => $category->id,
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
/**
2018-02-19 19:45:13 +01:00
* Submit with existing category name, see it reflected in output.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreCategoryName(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$category = $this->user()->categories()->first();
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'category_name' => $category->name,
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
/**
* Add foreign amount information.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreForeignAmount(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$currency = TransactionCurrency::first();
$foreign = TransactionCurrency::where('id', '!=', $currency->id)->first();
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-12-09 20:54:11 +01:00
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => $currency->id,
'foreign_currency_id' => $foreign->id,
'foreign_amount' => 23,
'source_id' => $account->id,
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
/**
* Add all available meta data fields.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreMetaData(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
2018-12-16 13:55:19 +01:00
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-12-09 20:54:11 +01:00
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
// store date meta fields (if present):
'interest_date' => '2017-08-02',
'book_date' => '2017-08-03',
'process_date' => '2017-08-04',
'due_date' => '2017-08-05',
'payment_date' => '2017-08-06',
'invoice_date' => '2017-08-07',
'internal_reference' => 'I are internal ref!',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
],
],
];
// test API
$response = $this->post('/api/v1/transactions?include=journal_meta', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
2018-02-19 19:45:13 +01:00
/**
* Submit with NEW category name, see it reflected in output.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-19 19:45:13 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreNewCategoryName(): void
2018-02-19 19:45:13 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
2018-12-16 13:55:19 +01:00
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-02-28 20:18:47 +01:00
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
$name = 'Some new category #' . random_int(1, 10000);
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-19 19:45:13 +01:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'category_name' => $name,
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
/**
* Add opposing account by name.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreNewOpposingName(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$opposing = $this->user()->accounts()->where('account_type_id', 4)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$opposing]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-03-28 19:38:20 +02:00
$name = 'New opposing account #' . random_int(1, 10000);
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'destination_name' => $name,
],
],
];
// 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.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreNotes(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-02-28 20:18:47 +01:00
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'notes' => 'I am a note',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
/**
* Add opposing account by ID.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreOpposingID(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$opposing = $this->user()->accounts()->where('account_type_id', 4)->first();
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$opposing]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'destination_id' => $opposing->id,
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
/**
* Add opposing account by name.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreOpposingName(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$opposing = $this->user()->accounts()->where('account_type_id', 4)->first();
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$opposing]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-02-28 20:18:47 +01:00
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'destination_name' => $opposing->name,
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
2018-02-19 20:02:27 +01:00
/**
* 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.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-19 20:02:27 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStorePiggyDeposit(): void
2018-02-19 20:02:27 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
2018-12-16 13:55:19 +01:00
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$piggy = $this->user()->piggyBanks()->first();
2018-02-19 20:02:27 +01:00
$data = [
'description' => 'Some deposit #' . random_int(1, 10000),
2018-02-19 20:02:27 +01:00
'date' => '2018-01-01',
'type' => 'deposit',
'piggy_bank_name' => $piggy->name,
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
2018-02-28 20:18:47 +01:00
'destination_id' => $account->id,
2018-02-19 20:02:27 +01:00
],
],
];
// 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);
}
2018-02-18 10:31:15 +01:00
/**
* 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.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-18 10:31:15 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStorePiggyId(): void
2018-02-18 10:31:15 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$source = $this->user()->accounts()->where('account_type_id', 3)->first();
$dest = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $source->id)->first();
$journal = $this->user()->transactionJournals()->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$source]), new Collection([$dest]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-02-28 20:18:47 +01:00
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-02-28 20:18:47 +01:00
$piggy = $this->user()->piggyBanks()->first();
$data = [
'description' => 'Some transfer #' . random_int(1, 10000),
2018-02-18 10:31:15 +01:00
'date' => '2018-01-01',
'type' => 'transfer',
'piggy_bank_id' => $piggy->id,
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $source->id,
'destination_id' => $dest->id,
],
],
];
// test API
$response = $this->post('/api/v1/transactions?include=piggy_bank_events', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
/**
* 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.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-18 10:31:15 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStorePiggyName(): void
2018-02-18 10:31:15 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$source = $this->user()->accounts()->where('account_type_id', 3)->first();
$dest = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $source->id)->first();
$journal = $this->user()->transactionJournals()->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$source]), new Collection([$dest]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-02-28 20:18:47 +01:00
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
$piggy = $this->user()->piggyBanks()->first();
$data = [
'description' => 'Some transfer #' . random_int(1, 10000),
2018-02-18 10:31:15 +01:00
'date' => '2018-01-01',
'type' => 'transfer',
'piggy_bank_name' => $piggy->name,
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $source->id,
'destination_id' => $dest->id,
],
],
];
// test API
$response = $this->post('/api/v1/transactions?include=piggy_bank_events', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
/**
* Set a different reconciled var
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreReconciled(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'reconciled' => true,
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
2018-02-20 18:03:02 +01:00
/**
* Submit the data required for a split withdrawal.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-02-20 18:03:02 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreSplit(): void
2018-02-20 18:03:02 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-02-28 20:18:47 +01:00
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-02-20 18:03:02 +01:00
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'description' => 'Part 1',
],
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'description' => 'Part 2',
],
],
];
// test API
$response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']);
$json = $response->json();
$response->assertStatus(200);
}
/**
* Submit the minimum amount of data required to create a withdrawal.
* Add some tags as well. Expect to see them in the result.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
*/
2018-05-11 19:58:10 +02:00
public function testSuccessStoreTags(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$tags = [
'TagOne' . random_int(1, 10000),
'TagTwoBlarg' . random_int(1, 10000),
'SomeThreeTag' . random_int(1, 10000),
];
2018-02-28 20:18:47 +01:00
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-02-28 20:18:47 +01:00
$journalRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(StoredTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
2018-04-02 14:17:11 +02:00
'tags' => implode(',', $tags),
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
],
],
];
// test API
$response = $this->post('/api/v1/transactions?include=tags', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
2018-03-03 08:12:18 +01:00
/**
* Fire enough to trigger an update. Since the create code already fires on the Request, no
* need to verify all of that.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-03-03 08:12:18 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testUpdateBasicDeposit(): void
2018-03-03 08:12:18 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-03-07 10:18:50 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$repository = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-12 20:30:25 +01:00
$collector = $this->mock(TransactionCollectorInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-03-07 10:18:50 +01:00
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$account->id]])->andReturn(new Collection([$account]));
2018-12-10 21:45:44 +01:00
$data = [
'description' => 'Some deposit #' . random_int(1, 10000),
2018-03-03 08:12:18 +01:00
'date' => '2018-01-01',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'destination_id' => $account->id,
],
],
];
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(UpdatedTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-09-02 20:13:25 +02:00
$deposit = $this->getRandomDeposit();
2018-03-03 08:12:18 +01:00
$transaction = $deposit->transactions()->first();
$repository->shouldReceive('setUser');
$repository->shouldReceive('update')->andReturn($deposit)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-03-03 08:12:18 +01:00
// 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.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*
2018-03-03 08:12:18 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testUpdateBasicWithdrawal(): void
2018-03-03 08:12:18 +01:00
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
2018-12-12 20:30:25 +01:00
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
2018-03-07 10:18:50 +01:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-12-16 13:55:19 +01:00
$transformer = $this->mock(TransactionTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
2018-12-12 20:30:25 +01:00
2018-03-07 10:18:50 +01:00
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$account->id]])->andReturn(new Collection([$account]));
2018-09-27 06:26:03 +02:00
try {
$this->expectsEvents(UpdatedTransactionJournal::class);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-03-28 19:38:20 +02:00
$data = [
'description' => 'Some transaction #' . random_int(1, 10000),
2018-03-03 08:12:18 +01:00
'date' => '2018-01-01',
'transactions' => [
[
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
],
],
];
2018-03-07 10:18:50 +01:00
2018-09-02 20:13:25 +02:00
$withdrawal = $this->getRandomWithdrawal();
2018-03-03 08:12:18 +01:00
$transaction = $withdrawal->transactions()->first();
$repository->shouldReceive('setUser');
$repository->shouldReceive('update')->andReturn($withdrawal)->once();
2018-12-12 20:30:25 +01:00
// collector stuff:
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
2018-03-03 08:12:18 +01:00
// call API
$response = $this->put('/api/v1/transactions/' . $transaction->id, $data);
$response->assertStatus(200);
}
2018-03-04 15:14:29 +01:00
}