mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code cleanup and realign.
This commit is contained in:
@@ -174,7 +174,7 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
|
||||
|
||||
// test API
|
||||
$response = $this->post('/api/v1/available_budgets', $data,['Accept' => 'application/json']);
|
||||
$response = $this->post('/api/v1/available_budgets', $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Could not find the indicated currency.');
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
|
@@ -127,6 +127,7 @@ class BillControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* Store with minimum amount more than maximum amount
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BillRequest
|
||||
*/
|
||||
|
@@ -124,7 +124,7 @@ class BudgetLimitControllerTest extends TestCase
|
||||
'start' => '2018-01-01',
|
||||
'end' => '2018-01-31',
|
||||
];
|
||||
$uri = '/api/v1/budget_limits?' . http_build_query($params);
|
||||
$uri = '/api/v1/budget_limits?' . http_build_query($params);
|
||||
$response = $this->get($uri);
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
@@ -149,9 +149,9 @@ class BudgetLimitControllerTest extends TestCase
|
||||
|
||||
// call API
|
||||
$params = [
|
||||
'budget_id' => $budget->id,
|
||||
'start' => '2018-01-01',
|
||||
'end' => '2018-01-31',
|
||||
'budget_id' => $budget->id,
|
||||
'start' => '2018-01-01',
|
||||
'end' => '2018-01-31',
|
||||
];
|
||||
$response = $this->get('/api/v1/budget_limits?' . http_build_query($params));
|
||||
$response->assertStatus(200);
|
||||
|
@@ -97,7 +97,8 @@ class CurrencyControllerTest extends TestCase
|
||||
$response = $this->get('/api/v1/currencies');
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson([
|
||||
$response->assertJson(
|
||||
[
|
||||
'meta' => [
|
||||
'pagination' => [
|
||||
'total' => $collection->count(),
|
||||
|
@@ -103,40 +103,6 @@ class CurrencyExchangeRateControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController
|
||||
*/
|
||||
public function testIndexBadSource(): void
|
||||
{
|
||||
// mock repository
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$service = $this->mock(ExchangeRateInterface::class);
|
||||
|
||||
$rate = new CurrencyExchangeRate();
|
||||
$rate->date = new Carbon();
|
||||
$rate->updated_at = new Carbon();
|
||||
$rate->created_at = new Carbon();
|
||||
$rate->rate = '0.5';
|
||||
$rate->to_currency_id = 1;
|
||||
$rate->from_currency_id = 2;
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(null)->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['USD'])->andReturn(TransactionCurrency::whereCode('USD')->first())->once();
|
||||
|
||||
// test API
|
||||
$params = [
|
||||
'from' => 'EUR',
|
||||
'to' => 'USD',
|
||||
'date' => '2018-01-01',
|
||||
];
|
||||
$response = $this->get('/api/v1/cer?' . http_build_query($params), ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Unknown source currency.');
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController
|
||||
*/
|
||||
@@ -170,4 +136,38 @@ class CurrencyExchangeRateControllerTest extends TestCase
|
||||
$response->assertSee('Unknown destination currency.');
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController
|
||||
*/
|
||||
public function testIndexBadSource(): void
|
||||
{
|
||||
// mock repository
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$service = $this->mock(ExchangeRateInterface::class);
|
||||
|
||||
$rate = new CurrencyExchangeRate();
|
||||
$rate->date = new Carbon();
|
||||
$rate->updated_at = new Carbon();
|
||||
$rate->created_at = new Carbon();
|
||||
$rate->rate = '0.5';
|
||||
$rate->to_currency_id = 1;
|
||||
$rate->from_currency_id = 2;
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(null)->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['USD'])->andReturn(TransactionCurrency::whereCode('USD')->first())->once();
|
||||
|
||||
// test API
|
||||
$params = [
|
||||
'from' => 'EUR',
|
||||
'to' => 'USD',
|
||||
'date' => '2018-01-01',
|
||||
];
|
||||
$response = $this->get('/api/v1/cer?' . http_build_query($params), ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Unknown source currency.');
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
@@ -749,12 +749,12 @@ class RecurrenceControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
* Add a recurring but refer to an asset as destination.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
*/
|
||||
public function testStoreFailInvalidWeekly(): void
|
||||
public function testStoreFailInvalidDestinationId(): void
|
||||
{
|
||||
/** @var Recurrence $recurrence */
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
@@ -776,6 +776,19 @@ class RecurrenceControllerTest extends TestCase
|
||||
// used by the validator to find the source_id:
|
||||
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
|
||||
->andReturn(new Collection([$assetAccount]));
|
||||
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$assetAccount->id]])->once()
|
||||
->andReturn(new Collection([$assetAccount]));
|
||||
|
||||
|
||||
// entries used by the transformer
|
||||
$repository->shouldReceive('getNoteText')->andReturn('Note text');
|
||||
$repository->shouldReceive('repetitionDescription')->andReturn('Some description.');
|
||||
$repository->shouldReceive('getXOccurrences')->andReturn([]);
|
||||
|
||||
// entries used by the transformer (the fake entry has a category + a budget):
|
||||
$factory->shouldReceive('findOrCreate')->andReturn(null);
|
||||
$budgetRepos->shouldReceive('findNull')->andReturn(null);
|
||||
|
||||
|
||||
// data to submit
|
||||
$firstDate = new Carbon;
|
||||
@@ -788,16 +801,17 @@ class RecurrenceControllerTest extends TestCase
|
||||
'active' => 1,
|
||||
'transactions' => [
|
||||
[
|
||||
'amount' => '100',
|
||||
'currency_id' => '1',
|
||||
'description' => 'Test description',
|
||||
'source_id' => '1',
|
||||
'amount' => '100',
|
||||
'currency_id' => '1',
|
||||
'description' => 'Test description',
|
||||
'source_id' => '1',
|
||||
'destination_id' => $assetAccount->id,
|
||||
],
|
||||
],
|
||||
'repetitions' => [
|
||||
[
|
||||
'type' => 'weekly',
|
||||
'moment' => '8',
|
||||
'type' => 'daily',
|
||||
'moment' => '',
|
||||
'skip' => '0',
|
||||
'weekend' => '1',
|
||||
|
||||
@@ -811,8 +825,8 @@ class RecurrenceControllerTest extends TestCase
|
||||
[
|
||||
'message' => 'The given data was invalid.',
|
||||
'errors' => [
|
||||
'repetitions.0.moment' => [
|
||||
'Invalid repetition moment for this type of repetition.',
|
||||
'transactions.0.destination_id' => [
|
||||
'This value is invalid for this field.',
|
||||
],
|
||||
],
|
||||
]
|
||||
@@ -967,6 +981,79 @@ class RecurrenceControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
*/
|
||||
public function testStoreFailInvalidNdomCount(): void
|
||||
{
|
||||
/** @var Recurrence $recurrence */
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$factory = $this->mock(CategoryFactory::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
$factory->shouldReceive('setUser');
|
||||
$budgetRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
|
||||
// used by the validator to find the source_id:
|
||||
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
|
||||
->andReturn(new Collection([$assetAccount]));
|
||||
|
||||
// data to submit
|
||||
$firstDate = new Carbon;
|
||||
$firstDate->addDays(2);
|
||||
$data = [
|
||||
'type' => 'withdrawal',
|
||||
'title' => 'Hello',
|
||||
'first_date' => $firstDate->format('Y-m-d'),
|
||||
'apply_rules' => 1,
|
||||
'active' => 1,
|
||||
'transactions' => [
|
||||
[
|
||||
'amount' => '100',
|
||||
'currency_id' => '1',
|
||||
'description' => 'Test description',
|
||||
'source_id' => '1',
|
||||
],
|
||||
],
|
||||
'repetitions' => [
|
||||
[
|
||||
'type' => 'ndom',
|
||||
'moment' => '9',
|
||||
'skip' => '0',
|
||||
'weekend' => '1',
|
||||
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// test API
|
||||
$response = $this->post('/api/v1/recurrences', $data, ['Accept' => 'application/json']);
|
||||
$response->assertExactJson(
|
||||
[
|
||||
'message' => 'The given data was invalid.',
|
||||
'errors' => [
|
||||
'repetitions.0.moment' => [
|
||||
'Invalid repetition moment for this type of repetition.',
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
$response->assertStatus(422);
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
@@ -1046,7 +1133,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
*/
|
||||
public function testStoreFailInvalidNdomCount(): void
|
||||
public function testStoreFailInvalidWeekly(): void
|
||||
{
|
||||
/** @var Recurrence $recurrence */
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
@@ -1088,8 +1175,8 @@ class RecurrenceControllerTest extends TestCase
|
||||
],
|
||||
'repetitions' => [
|
||||
[
|
||||
'type' => 'ndom',
|
||||
'moment' => '9',
|
||||
'type' => 'weekly',
|
||||
'moment' => '8',
|
||||
'skip' => '0',
|
||||
'weekend' => '1',
|
||||
|
||||
@@ -1113,93 +1200,6 @@ class RecurrenceControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a recurring but refer to an asset as destination.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
*/
|
||||
public function testStoreFailInvalidDestinationId(): void
|
||||
{
|
||||
/** @var Recurrence $recurrence */
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$factory = $this->mock(CategoryFactory::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
$factory->shouldReceive('setUser');
|
||||
$budgetRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
|
||||
// used by the validator to find the source_id:
|
||||
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
|
||||
->andReturn(new Collection([$assetAccount]));
|
||||
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$assetAccount->id]])->once()
|
||||
->andReturn(new Collection([$assetAccount]));
|
||||
|
||||
|
||||
// entries used by the transformer
|
||||
$repository->shouldReceive('getNoteText')->andReturn('Note text');
|
||||
$repository->shouldReceive('repetitionDescription')->andReturn('Some description.');
|
||||
$repository->shouldReceive('getXOccurrences')->andReturn([]);
|
||||
|
||||
// entries used by the transformer (the fake entry has a category + a budget):
|
||||
$factory->shouldReceive('findOrCreate')->andReturn(null);
|
||||
$budgetRepos->shouldReceive('findNull')->andReturn(null);
|
||||
|
||||
|
||||
// data to submit
|
||||
$firstDate = new Carbon;
|
||||
$firstDate->addDays(2);
|
||||
$data = [
|
||||
'type' => 'withdrawal',
|
||||
'title' => 'Hello',
|
||||
'first_date' => $firstDate->format('Y-m-d'),
|
||||
'apply_rules' => 1,
|
||||
'active' => 1,
|
||||
'transactions' => [
|
||||
[
|
||||
'amount' => '100',
|
||||
'currency_id' => '1',
|
||||
'description' => 'Test description',
|
||||
'source_id' => '1',
|
||||
'destination_id' => $assetAccount->id,
|
||||
],
|
||||
],
|
||||
'repetitions' => [
|
||||
[
|
||||
'type' => 'daily',
|
||||
'moment' => '',
|
||||
'skip' => '0',
|
||||
'weekend' => '1',
|
||||
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// test API
|
||||
$response = $this->post('/api/v1/recurrences', $data, ['Accept' => 'application/json']);
|
||||
$response->assertExactJson(
|
||||
[
|
||||
'message' => 'The given data was invalid.',
|
||||
'errors' => [
|
||||
'transactions.0.destination_id' => [
|
||||
'This value is invalid for this field.',
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
$response->assertStatus(422);
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit without a source account.
|
||||
*
|
||||
|
Reference in New Issue
Block a user