mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-18 10:16:49 +00:00
Tests also validate existing data.
This commit is contained in:
@@ -184,7 +184,7 @@ class StoreControllerTest extends TestCase
|
||||
*
|
||||
* storeDataProvider / emptyDataProvider
|
||||
*
|
||||
* @dataProvider storeDataProvider
|
||||
* @dataProvider emptyDataProvider
|
||||
*/
|
||||
public function testStore(array $submission): void
|
||||
{
|
||||
|
@@ -84,14 +84,11 @@ class UpdateControllerTest extends TestCase
|
||||
$fieldSet->addField(Field::createBasic('include_net_worth', 'boolean'));
|
||||
$configuration->addOptionalFieldSet('include_net_worth', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('virtual_balance', 'random-amount'));
|
||||
$configuration->addOptionalFieldSet('virtual_balance', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('virtual_balance', 'random-amount'));
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('virtual_balance', 'random-amount');
|
||||
$field->ignorableFields = ['current_balance'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('virtual_balance', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
@@ -99,7 +96,7 @@ class UpdateControllerTest extends TestCase
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'currency_id';
|
||||
$field->fieldType = 'random-currency-id';
|
||||
$field->ignorableFields = ['currency_code'];
|
||||
$field->ignorableFields = ['currency_code', 'currency_symbol', 'current_balance'];
|
||||
$field->title = 'currency_id';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
|
||||
@@ -109,7 +106,7 @@ class UpdateControllerTest extends TestCase
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'currency_code';
|
||||
$field->fieldType = 'random-currency-code';
|
||||
$field->ignorableFields = ['currency_id'];
|
||||
$field->ignorableFields = ['currency_id', 'currency_symbol', 'current_balance'];
|
||||
$field->title = 'currency_code';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
|
||||
@@ -131,9 +128,11 @@ class UpdateControllerTest extends TestCase
|
||||
$fieldSet->addField(Field::createBasic('zoom_level', 'random-zoom_level'));
|
||||
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('opening_balance', 'random-amount'));
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('opening_balance', 'random-amount');
|
||||
$field->ignorableFields = ['current_balance'];
|
||||
$fieldSet->addField($field);
|
||||
$fieldSet->addField(Field::createBasic('opening_balance_date', 'random-past-date'));
|
||||
$configuration->addOptionalFieldSet('ob', $fieldSet);
|
||||
|
||||
|
@@ -62,7 +62,7 @@ class StoreControllerTest extends TestCase
|
||||
*
|
||||
* emptyDataProvider / storeDataProvider
|
||||
*
|
||||
* @dataProvider storeDataProvider
|
||||
* @dataProvider emptyDataProvider
|
||||
*/
|
||||
public function testStore(array $submission): void
|
||||
{
|
||||
|
@@ -101,7 +101,7 @@ class StoreControllerTest extends TestCase
|
||||
*
|
||||
* emptyDataProvider / storeDataProvider
|
||||
*
|
||||
* @dataProvider storeDataProvider
|
||||
* @dataProvider emptyDataProvider
|
||||
*/
|
||||
public function testStore(array $submission): void
|
||||
{
|
||||
|
@@ -84,7 +84,7 @@ class UpdateControllerTest extends TestCase
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'currency_id';
|
||||
$field->fieldType = 'random-currency-id';
|
||||
$field->ignorableFields = ['currency_code'];
|
||||
$field->ignorableFields = ['currency_code','currency_symbol'];
|
||||
$field->title = 'currency_id';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
|
||||
@@ -94,7 +94,7 @@ class UpdateControllerTest extends TestCase
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'currency_code';
|
||||
$field->fieldType = 'random-currency-code';
|
||||
$field->ignorableFields = ['currency_id'];
|
||||
$field->ignorableFields = ['currency_id','currency_symbol'];
|
||||
$field->title = 'currency_code';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
|
||||
|
@@ -164,7 +164,7 @@ class StoreControllerTest extends TestCase
|
||||
*
|
||||
* emptyDataProvider / storeDataProvider
|
||||
*
|
||||
* @dataProvider storeDataProvider
|
||||
* @dataProvider emptyDataProvider
|
||||
*/
|
||||
public function testStore(array $submission): void
|
||||
{
|
||||
|
@@ -146,7 +146,7 @@ class UpdateControllerTest extends TestCase
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'currency_id';
|
||||
$field->fieldType = 'random-currency-id';
|
||||
$field->ignorableFields = ['currency_code'];
|
||||
$field->ignorableFields = ['currency_code','currency_symbol'];
|
||||
$field->title = 'currency_id';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
|
||||
@@ -156,7 +156,7 @@ class UpdateControllerTest extends TestCase
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'currency_code';
|
||||
$field->fieldType = 'random-currency-code';
|
||||
$field->ignorableFields = ['currency_id'];
|
||||
$field->ignorableFields = ['currency_id','currency_symbol'];
|
||||
$field->title = 'currency_code';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
|
||||
|
@@ -119,7 +119,7 @@ class StoreControllerTest extends TestCase
|
||||
*
|
||||
* emptyDataProvider / storeDataProvider
|
||||
*
|
||||
* @dataProvider storeDataProvider
|
||||
* @dataProvider emptyDataProvider
|
||||
*/
|
||||
public function testStore(array $submission): void
|
||||
{
|
||||
|
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\BudgetLimit;
|
||||
use Faker\Factory;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\Objects\Field;
|
||||
use Tests\Objects\FieldSet;
|
||||
use Tests\Objects\TestConfiguration;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\CollectsValues;
|
||||
|
||||
@@ -61,102 +64,74 @@ class StoreControllerTest extends TestCase
|
||||
*/
|
||||
public function storeDataProvider(): array
|
||||
{
|
||||
$minimalSets = $this->minimalSets();
|
||||
$optionalSets = $this->optionalSets();
|
||||
$regenConfig = [
|
||||
'start' => function () {
|
||||
$faker = Factory::create();
|
||||
// some test configs:
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
return $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d');
|
||||
},
|
||||
'end' => function () {
|
||||
$faker = Factory::create();
|
||||
// default test set:
|
||||
$defaultSet = new FieldSet();
|
||||
$defaultSet->title = 'default_budget_limit';
|
||||
$defaultSet->addField(Field::createBasic('start', 'random-date-two-year'));
|
||||
$defaultSet->addField(Field::createBasic('end', 'random-date-one-year'));
|
||||
$defaultSet->addField(Field::createBasic('amount', 'random-amount'));
|
||||
$configuration->addMandatoryFieldSet($defaultSet);
|
||||
|
||||
return $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d');
|
||||
},
|
||||
];
|
||||
// optional tests
|
||||
$fieldSet = new FieldSet;
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'currency_id';
|
||||
$field->fieldType = 'random-currency-id';
|
||||
$field->ignorableFields = ['currency_code'];
|
||||
$field->title = 'currency_id';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
|
||||
|
||||
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
|
||||
$fieldSet = new FieldSet;
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'currency_code';
|
||||
$field->fieldType = 'random-currency-code';
|
||||
$field->ignorableFields = ['currency_id'];
|
||||
$field->title = 'currency_code';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('start', 'random-date-two-year'));
|
||||
$configuration->addOptionalFieldSet('start', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('end', 'random-date-one-year'));
|
||||
$configuration->addOptionalFieldSet('end', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('amount', 'random-amount'));
|
||||
$configuration->addOptionalFieldSet('amount', $fieldSet);
|
||||
|
||||
return $configuration->generateAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function minimalSets(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
|
||||
return [
|
||||
'default_bl' => [
|
||||
'parameters' => [1],
|
||||
'fields' => [
|
||||
'start' => $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d'),
|
||||
'end' => $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d'),
|
||||
'amount' => number_format($faker->randomFloat(2, 10, 100), 2),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \array[][]
|
||||
*/
|
||||
private function optionalSets(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$currencies = [
|
||||
1 => 'EUR',
|
||||
2 => 'HUF',
|
||||
3 => 'GBP',
|
||||
4 => 'UAH',
|
||||
];
|
||||
$rand = rand(1, 4);
|
||||
|
||||
return [
|
||||
'currency_id' => [
|
||||
'fields' => [
|
||||
'currency_id' => $rand,
|
||||
],
|
||||
],
|
||||
'currency_code' => [
|
||||
'fields' => [
|
||||
'currency_code' => $currencies[$rand],
|
||||
],
|
||||
],
|
||||
'start' => [
|
||||
'fields' => [
|
||||
'start' => $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d'),
|
||||
],
|
||||
],
|
||||
'end' => [
|
||||
'fields' => [
|
||||
'end' => $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d'),
|
||||
],
|
||||
],
|
||||
'amount' => [
|
||||
'fields' => [
|
||||
'amount' => number_format($faker->randomFloat(2, 10, 100), 2),
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $submission
|
||||
*
|
||||
* emptyDataProvider / storeDataProvider
|
||||
*
|
||||
* @dataProvider storeDataProvider
|
||||
* @dataProvider emptyDataProvider
|
||||
*/
|
||||
public function testStore(array $submission): void
|
||||
{
|
||||
if ([] === $submission) {
|
||||
$this->markTestSkipped('Empty data provider');
|
||||
$this->markTestSkipped('Empty provider.');
|
||||
}
|
||||
Log::debug('testStoreUpdated()');
|
||||
Log::debug('submission :', $submission['submission']);
|
||||
Log::debug('expected :', $submission['expected']);
|
||||
Log::debug('ignore :', $submission['ignore']);
|
||||
// run account store with a minimal data set:
|
||||
$route = 'api.v1.budgets.limits.store';
|
||||
$this->storeAndCompare($route, $submission);
|
||||
$address = route('api.v1.budgets.limits.store', [1]);
|
||||
$this->assertPOST($address, $submission);
|
||||
}
|
||||
|
||||
}
|
@@ -22,12 +22,13 @@
|
||||
namespace Tests\Api\Models\BudgetLimit;
|
||||
|
||||
|
||||
use Faker\Factory;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\Objects\Field;
|
||||
use Tests\Objects\FieldSet;
|
||||
use Tests\Objects\TestConfiguration;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\CollectsValues;
|
||||
|
||||
use Tests\Traits\TestHelpers;
|
||||
|
||||
/**
|
||||
@@ -53,12 +54,17 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate(array $submission): void
|
||||
{
|
||||
$ignore = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
$route = route('api.v1.budgets.limits.update', [$submission['id'], $submission['bl_id']]);
|
||||
$this->updateAndCompare($route, $submission, $ignore);
|
||||
if ([] === $submission) {
|
||||
$this->markTestSkipped('Empty provider.');
|
||||
}
|
||||
Log::debug('testStoreUpdated()');
|
||||
Log::debug('submission :', $submission['submission']);
|
||||
Log::debug('expected :', $submission['expected']);
|
||||
Log::debug('ignore :', $submission['ignore']);
|
||||
Log::debug('parameters :', $submission['parameters']);
|
||||
|
||||
$route = route('api.v1.budgets.limits.update', $submission['parameters']);
|
||||
$this->assertPUT($route, $submission);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,83 +73,44 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function updateDataProvider(): array
|
||||
{
|
||||
$submissions = [];
|
||||
$all = $this->updateDataSet();
|
||||
foreach ($all as $name => $data) {
|
||||
$submissions[] = [$data];
|
||||
}
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
return $submissions;
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1, 1];
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'currency_id';
|
||||
$field->fieldType = 'random-currency-id';
|
||||
$field->ignorableFields = ['currency_code', 'currency_name', 'currency_symbol', 'spent'];
|
||||
$field->title = 'currency_id';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1, 1];
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'currency_code';
|
||||
$field->fieldType = 'random-currency-code';
|
||||
$field->ignorableFields = ['currency_id', 'currency_name', 'currency_symbol', 'spent'];
|
||||
$field->title = 'currency_code';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1, 1];
|
||||
$fieldSet->addField(Field::createBasic('start', 'random-date-two-year'));
|
||||
$configuration->addOptionalFieldSet('start', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1, 1];
|
||||
$fieldSet->addField(Field::createBasic('end', 'random-date-one-year'));
|
||||
$configuration->addOptionalFieldSet('end', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1, 1];
|
||||
$fieldSet->addField(Field::createBasic('amount', 'random-amount'));
|
||||
$configuration->addOptionalFieldSet('amount', $fieldSet);
|
||||
|
||||
return $configuration->generateAll();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function updateDataSet(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$currencies = [
|
||||
1 => 'EUR',
|
||||
2 => 'HUF',
|
||||
3 => 'GBP',
|
||||
4 => 'UAH',
|
||||
];
|
||||
$repeatFreqs = ['yearly', 'weekly', 'monthly'];
|
||||
$repeatFreq = $repeatFreqs[rand(0, count($repeatFreqs) - 1)];
|
||||
$objectGroupId = $faker->numberBetween(1, 2);
|
||||
$objectGroupName = sprintf('Object group %d', $objectGroupId);
|
||||
$rand = rand(1, 4);
|
||||
|
||||
$autoBudgetTypes = ['reset', 'rollover'];
|
||||
$autoBudgetType = $autoBudgetTypes[rand(0, count($autoBudgetTypes) - 1)];
|
||||
|
||||
$set = [
|
||||
'currency_id' => [
|
||||
'id' => 1,
|
||||
'bl_id' => 1,
|
||||
'fields' => [
|
||||
'currency_id' => ['test_value' => (string)$rand],
|
||||
],
|
||||
'extra_ignore' => ['currency_code', 'currency_name', 'currency_symbol'],
|
||||
],
|
||||
'currency_code' => [
|
||||
'id' => 1,
|
||||
'bl_id' => 1,
|
||||
'fields' => [
|
||||
'currency_code' => ['test_value' => $currencies[$rand]],
|
||||
],
|
||||
'extra_ignore' => ['currency_id', 'currency_name', 'currency_symbol'],
|
||||
],
|
||||
'start' => [
|
||||
'id' => 1,
|
||||
'bl_id' => 1,
|
||||
'fields' => [
|
||||
'start' => ['test_value' => $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d')],
|
||||
],
|
||||
'extra_ignore' => ['spent'],
|
||||
],
|
||||
'end' => [
|
||||
'id' => 1,
|
||||
'bl_id' => 1,
|
||||
'fields' => [
|
||||
'end' => ['test_value' => $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d')],
|
||||
],
|
||||
'extra_ignore' => ['spent'],
|
||||
],
|
||||
'amount' => [
|
||||
'id' => 1,
|
||||
'bl_id' => 1,
|
||||
'fields' => [
|
||||
'amount' => ['test_value' => number_format($faker->randomFloat(2, 10, 100), 2)],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\Category;
|
||||
use Faker\Factory;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\Objects\Field;
|
||||
use Tests\Objects\FieldSet;
|
||||
use Tests\Objects\TestConfiguration;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\CollectsValues;
|
||||
|
||||
@@ -61,66 +64,44 @@ class StoreControllerTest extends TestCase
|
||||
*/
|
||||
public function storeDataProvider(): array
|
||||
{
|
||||
$minimalSets = $this->minimalSets();
|
||||
$optionalSets = $this->optionalSets();
|
||||
$regenConfig = [
|
||||
'name' => function () {
|
||||
$faker = Factory::create();
|
||||
// some test configs:
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
return $faker->uuid;
|
||||
},
|
||||
];
|
||||
// default test set:
|
||||
$defaultSet = new FieldSet();
|
||||
$defaultSet->title = 'default_cat';
|
||||
$defaultSet->addField(Field::createBasic('name', 'uuid'));
|
||||
$configuration->addMandatoryFieldSet($defaultSet);
|
||||
|
||||
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
|
||||
// add optional set
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||
|
||||
return $configuration->generateAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function minimalSets(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
|
||||
return [
|
||||
'default_cat' => [
|
||||
'parameters' => [1],
|
||||
'fields' => [
|
||||
'name' => $faker->uuid,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \array[][]
|
||||
*/
|
||||
private function optionalSets(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
|
||||
return [
|
||||
'notes' => [
|
||||
'fields' => [
|
||||
'notes' => join(' ', $faker->words(5)),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $submission
|
||||
*
|
||||
* emptyDataProvider / storeDataProvider
|
||||
*
|
||||
* @dataProvider storeDataProvider
|
||||
* @dataProvider emptyDataProvider
|
||||
*/
|
||||
public function testStore(array $submission): void
|
||||
{
|
||||
if ([] === $submission) {
|
||||
$this->markTestSkipped('Empty data provider');
|
||||
$this->markTestSkipped('Empty provider.');
|
||||
}
|
||||
$route = 'api.v1.categories.store';
|
||||
$this->storeAndCompare($route, $submission);
|
||||
Log::debug('testStoreUpdated()');
|
||||
Log::debug('submission :', $submission['submission']);
|
||||
Log::debug('expected :', $submission['expected']);
|
||||
Log::debug('ignore :', $submission['ignore']);
|
||||
// run account store with a minimal data set:
|
||||
$address = route('api.v1.categories.store');
|
||||
$this->assertPOST($address, $submission);
|
||||
}
|
||||
|
||||
}
|
@@ -22,12 +22,13 @@
|
||||
namespace Tests\Api\Models\Category;
|
||||
|
||||
|
||||
use Faker\Factory;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\Objects\Field;
|
||||
use Tests\Objects\FieldSet;
|
||||
use Tests\Objects\TestConfiguration;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\CollectsValues;
|
||||
|
||||
use Tests\Traits\TestHelpers;
|
||||
|
||||
/**
|
||||
@@ -53,13 +54,19 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate(array $submission): void
|
||||
{
|
||||
$ignore = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
$route = route('api.v1.categories.update', [$submission['id']]);
|
||||
if ([] === $submission) {
|
||||
$this->markTestSkipped('Empty provider.');
|
||||
}
|
||||
Log::debug('testStoreUpdated()');
|
||||
Log::debug('submission :', $submission['submission']);
|
||||
Log::debug('expected :', $submission['expected']);
|
||||
Log::debug('ignore :', $submission['ignore']);
|
||||
Log::debug('parameters :', $submission['parameters']);
|
||||
|
||||
$route = route('api.v1.categories.update', $submission['parameters']);
|
||||
$this->assertPUT($route, $submission);
|
||||
|
||||
|
||||
$this->updateAndCompare($route, $submission, $ignore);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,40 +75,20 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function updateDataProvider(): array
|
||||
{
|
||||
$submissions = [];
|
||||
$all = $this->updateDataSet();
|
||||
foreach ($all as $name => $data) {
|
||||
$submissions[] = [$data];
|
||||
}
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
return $submissions;
|
||||
}
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('name', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('name', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('notes', 'boolean'));
|
||||
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function updateDataSet(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$set = [
|
||||
'name' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'name' => ['test_value' => $faker->uuid],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'notes' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'notes' => ['test_value' => join(' ', $faker->words(5))],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
];
|
||||
return $configuration->generateAll();
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\ObjectGroup;
|
||||
use Faker\Factory;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\Objects\Field;
|
||||
use Tests\Objects\FieldSet;
|
||||
use Tests\Objects\TestConfiguration;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\CollectsValues;
|
||||
|
||||
@@ -53,13 +56,17 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate(array $submission): void
|
||||
{
|
||||
$ignore = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
$route = route('api.v1.object-groups.update', [$submission['id']]);
|
||||
if ([] === $submission) {
|
||||
$this->markTestSkipped('Empty provider.');
|
||||
}
|
||||
Log::debug('testStoreUpdated()');
|
||||
Log::debug('submission :', $submission['submission']);
|
||||
Log::debug('expected :', $submission['expected']);
|
||||
Log::debug('ignore :', $submission['ignore']);
|
||||
Log::debug('parameters :', $submission['parameters']);
|
||||
|
||||
$this->updateAndCompare($route, $submission, $ignore);
|
||||
$route = route('api.v1.object-groups.update', $submission['parameters']);
|
||||
$this->assertPUT($route, $submission);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,42 +75,19 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function updateDataProvider(): array
|
||||
{
|
||||
$submissions = [];
|
||||
$all = $this->updateDataSet();
|
||||
foreach ($all as $name => $data) {
|
||||
$submissions[] = [$data];
|
||||
}
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
return $submissions;
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('title', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('title', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('order', 'order'));
|
||||
$configuration->addOptionalFieldSet('order', $fieldSet);
|
||||
|
||||
return $configuration->generateAll();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function updateDataSet(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$set = [
|
||||
'title' => [
|
||||
'id' => 3,
|
||||
'fields' => [
|
||||
'title' => ['test_value' => $faker->uuid],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'order' => [
|
||||
'id' => 3,
|
||||
'fields' => [
|
||||
'order' => ['test_value' => $faker->numberBetween(1, 2)],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -25,9 +25,11 @@ namespace Tests\Api\Models\PiggyBank;
|
||||
use Faker\Factory;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\Objects\Field;
|
||||
use Tests\Objects\FieldSet;
|
||||
use Tests\Objects\TestConfiguration;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\CollectsValues;
|
||||
|
||||
use Tests\Traits\TestHelpers;
|
||||
|
||||
/**
|
||||
@@ -61,85 +63,64 @@ class StoreControllerTest extends TestCase
|
||||
*/
|
||||
public function storeDataProvider(): array
|
||||
{
|
||||
$minimalSets = $this->minimalSets();
|
||||
$optionalSets = $this->optionalSets();
|
||||
$regenConfig = [
|
||||
'name' => function () {
|
||||
$faker = Factory::create();
|
||||
// some test configs:
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
return $faker->uuid;
|
||||
},
|
||||
];
|
||||
// default test set:
|
||||
$defaultSet = new FieldSet();
|
||||
$defaultSet->title = 'default_object';
|
||||
$defaultSet->addField(Field::createBasic('name', 'uuid'));
|
||||
$defaultSet->addField(Field::createBasic('account_id', 'random-piggy-account'));
|
||||
$defaultSet->addField(Field::createBasic('target_amount', 'random-amount-max'));
|
||||
$configuration->addMandatoryFieldSet($defaultSet);
|
||||
|
||||
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
|
||||
}
|
||||
// add optional set
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('current_amount', 'random-amount-min'));
|
||||
$configuration->addOptionalFieldSet('current_amount', $fieldSet);
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function minimalSets(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('start_date', 'random-past-date'));
|
||||
$configuration->addOptionalFieldSet('start_date', $fieldSet);
|
||||
|
||||
return [
|
||||
'default_piggy' => [
|
||||
'parameters' => [],
|
||||
'fields' => [
|
||||
'name' => $faker->uuid,
|
||||
'account_id' => $faker->numberBetween(1, 3),
|
||||
'target_amount' => number_format($faker->randomFloat(2, 50, 100), 2),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('target_date', 'random-future-date'));
|
||||
$configuration->addOptionalFieldSet('target_date', $fieldSet);
|
||||
|
||||
/**
|
||||
* @return \array[][]
|
||||
*/
|
||||
private function optionalSets(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('order', 'order'));
|
||||
$configuration->addOptionalFieldSet('order', $fieldSet);
|
||||
|
||||
$objectGroupId = $faker->numberBetween(1, 2);
|
||||
$objectGroupName = sprintf('Object group %d', $objectGroupId);
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'object_group_id';
|
||||
$field->fieldType = 'random-og-id';
|
||||
$field->ignorableFields = ['object_group_title'];
|
||||
$field->title = 'object_group_id';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('object_group_id', $fieldSet);
|
||||
|
||||
return [
|
||||
'current_amount' => [
|
||||
'fields' => [
|
||||
'current_amount' => number_format($faker->randomFloat(2, 10, 50), 2),
|
||||
],
|
||||
],
|
||||
'start_date' => [
|
||||
'fields' => [
|
||||
'start_date' => $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d'),
|
||||
],
|
||||
],
|
||||
'target_date' => [
|
||||
'fields' => [
|
||||
'target_date' => $faker->dateTimeBetween('+1 year', '+2 year')->format('Y-m-d'),
|
||||
],
|
||||
],
|
||||
'order' => [
|
||||
'fields' => [
|
||||
'order' => $faker->numberBetween(1, 5),
|
||||
],
|
||||
],
|
||||
'object_group_id' => [
|
||||
'fields' => [
|
||||
'object_group_id' => $objectGroupId,
|
||||
],
|
||||
],
|
||||
'object_group_title' => [
|
||||
'fields' => [
|
||||
'object_group_title' => $objectGroupName,
|
||||
],
|
||||
],
|
||||
'notes' => [
|
||||
'fields' => [
|
||||
'notes' => join(' ', $faker->words(5)),
|
||||
],
|
||||
],
|
||||
];
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'object_group_title';
|
||||
$field->fieldType = 'uuid';
|
||||
$field->ignorableFields = ['object_group_id'];
|
||||
$field->title = 'object_group_id';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('object_group_title', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||
|
||||
return $configuration->generateAll();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,15 +128,20 @@ class StoreControllerTest extends TestCase
|
||||
*
|
||||
* emptyDataProvider / storeDataProvider
|
||||
*
|
||||
* @dataProvider storeDataProvider
|
||||
* @dataProvider emptyDataProvider
|
||||
*/
|
||||
public function testStore(array $submission): void
|
||||
{
|
||||
if ([] === $submission) {
|
||||
$this->markTestSkipped('Empty data provider');
|
||||
$this->markTestSkipped('Empty provider.');
|
||||
}
|
||||
$route = 'api.v1.piggy_banks.store';
|
||||
$this->storeAndCompare($route, $submission);
|
||||
Log::debug('testStoreUpdated()');
|
||||
Log::debug('submission :', $submission['submission']);
|
||||
Log::debug('expected :', $submission['expected']);
|
||||
Log::debug('ignore :', $submission['ignore']);
|
||||
// run account store with a minimal data set:
|
||||
$address = route('api.v1.piggy_banks.store');
|
||||
$this->assertPOST($address, $submission);
|
||||
}
|
||||
|
||||
}
|
@@ -22,12 +22,13 @@
|
||||
namespace Tests\Api\Models\PiggyBank;
|
||||
|
||||
|
||||
use Faker\Factory;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\Objects\Field;
|
||||
use Tests\Objects\FieldSet;
|
||||
use Tests\Objects\TestConfiguration;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\CollectsValues;
|
||||
|
||||
use Tests\Traits\TestHelpers;
|
||||
|
||||
/**
|
||||
@@ -53,13 +54,17 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate(array $submission): void
|
||||
{
|
||||
$ignore = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
$route = route('api.v1.piggy_banks.update', [$submission['id']]);
|
||||
if ([] === $submission) {
|
||||
$this->markTestSkipped('Empty provider.');
|
||||
}
|
||||
Log::debug('testStoreUpdated()');
|
||||
Log::debug('submission :', $submission['submission']);
|
||||
Log::debug('expected :', $submission['expected']);
|
||||
Log::debug('ignore :', $submission['ignore']);
|
||||
Log::debug('parameters :', $submission['parameters']);
|
||||
|
||||
$this->updateAndCompare($route, $submission, $ignore);
|
||||
$route = route('api.v1.piggy_banks.update', $submission['parameters']);
|
||||
$this->assertPUT($route, $submission);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,99 +73,76 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function updateDataProvider(): array
|
||||
{
|
||||
$submissions = [];
|
||||
$all = $this->updateDataSet();
|
||||
foreach ($all as $name => $data) {
|
||||
$submissions[] = [$data];
|
||||
}
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
return $submissions;
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('name', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('name', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('account_id', 'random-piggy-account');
|
||||
$field->ignorableFields = ['account_name'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('account_id', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('target_amount', 'random-amount-max');
|
||||
$field->ignorableFields = ['percentage', 'current_amount', 'left_to_save', 'save_per_month'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('target_amount', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('current_amount', 'random-amount-min');
|
||||
$field->ignorableFields = ['percentage', 'left_to_save','save_per_month'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('current_amount', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('start_date', 'random-past-date'));
|
||||
$configuration->addOptionalFieldSet('start_date', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('target_date', 'random-future-date');
|
||||
$field->ignorableFields = ['save_per_month'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('target_date', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('order', 'order'));
|
||||
$configuration->addOptionalFieldSet('order', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'object_group_id';
|
||||
$field->fieldType = 'random-og-id';
|
||||
$field->ignorableFields = ['object_group_title', 'object_group_order'];
|
||||
$field->title = 'object_group_id';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('object_group_id', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'object_group_title';
|
||||
$field->fieldType = 'uuid';
|
||||
$field->ignorableFields = ['object_group_id', 'object_group_order'];
|
||||
$field->title = 'object_group_id';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('object_group_title', $fieldSet);
|
||||
|
||||
return $configuration->generateAll();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function updateDataSet(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$objectGroupId = $faker->numberBetween(1, 2);
|
||||
$objectGroupName = sprintf('Object group %d', $objectGroupId);
|
||||
$set = [
|
||||
'name' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'name' => ['test_value' => $faker->uuid],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'account_id' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'account_id' => ['test_value' => (string)$faker->numberBetween(1, 3)],
|
||||
],
|
||||
'extra_ignore' => ['account_name', 'currency_id', 'currency_code'],
|
||||
],
|
||||
'target_amount' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'target_amount' => ['test_value' => number_format($faker->randomFloat(2, 50, 100), 2)],
|
||||
],
|
||||
'extra_ignore' => ['percentage', 'current_amount', 'left_to_save'],
|
||||
],
|
||||
'current_amount' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'current_amount' => ['test_value' => number_format($faker->randomFloat(2, 5, 10), 2)],
|
||||
],
|
||||
'extra_ignore' => ['percentage', 'left_to_save'],
|
||||
],
|
||||
'start_date' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'start_date' => ['test_value' => $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d')],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'target_date' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'target_date' => ['test_value' => $faker->dateTimeBetween('+1 year', '+2 year')->format('Y-m-d')],
|
||||
],
|
||||
'extra_ignore' => ['save_per_month'],
|
||||
],
|
||||
'order' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'order' => ['test_value' => $faker->numberBetween(1, 5)],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'notes' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'notes' => ['test_value' => join(' ', $faker->words(5))],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'object_group_id' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'object_group_id' => ['test_value' => (string)$objectGroupId],
|
||||
],
|
||||
'extra_ignore' => ['object_group_order', 'object_group_title'],
|
||||
],
|
||||
'object_group_title' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'object_group_title' => ['test_value' => $objectGroupName],
|
||||
],
|
||||
'extra_ignore' => ['object_group_order', 'object_group_id'],
|
||||
],
|
||||
];
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\Recurrence;
|
||||
use Faker\Factory;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\Objects\Field;
|
||||
use Tests\Objects\FieldSet;
|
||||
use Tests\Objects\TestConfiguration;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\CollectsValues;
|
||||
|
||||
@@ -61,127 +64,110 @@ class StoreControllerTest extends TestCase
|
||||
*/
|
||||
public function storeDataProvider(): array
|
||||
{
|
||||
$minimalSets = $this->minimalSets();
|
||||
$optionalSets = $this->optionalSets();
|
||||
$regenConfig = [
|
||||
'title' => function () {
|
||||
$faker = Factory::create();
|
||||
// some test configs:
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
return $faker->uuid;
|
||||
},
|
||||
];
|
||||
// default test set:
|
||||
$defaultSet = new FieldSet();
|
||||
$defaultSet->title = 'default_withdrawal';
|
||||
$defaultSet->addField(Field::createBasic('type', 'static-withdrawal'));
|
||||
$defaultSet->addField(Field::createBasic('title', 'uuid'));
|
||||
$defaultSet->addField(Field::createBasic('first_date', 'random-future-date'));
|
||||
$defaultSet->addField(Field::createBasic('repeat_until', 'random-future-date'));
|
||||
$defaultSet->addField(Field::createBasic('repetitions/0/type', 'static-type-weekly'));
|
||||
$defaultSet->addField(Field::createBasic('repetitions/0/moment', 'static-one'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/description', 'uuid'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/amount', 'random-amount'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/source_id', 'random-asset-id'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/destination_id', 'random-expense-id'));
|
||||
$configuration->addMandatoryFieldSet($defaultSet);
|
||||
|
||||
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
|
||||
}
|
||||
$defaultSet = new FieldSet();
|
||||
$defaultSet->title = 'default_withdrawal_2';
|
||||
$defaultSet->addField(Field::createBasic('type', 'static-withdrawal'));
|
||||
$defaultSet->addField(Field::createBasic('title', 'uuid'));
|
||||
$defaultSet->addField(Field::createBasic('first_date', 'random-future-date'));
|
||||
$defaultSet->addField(Field::createBasic('nr_of_repetitions', 'random-nr-of-reps'));
|
||||
$defaultSet->addField(Field::createBasic('repetitions/0/type', 'static-type-weekly'));
|
||||
$defaultSet->addField(Field::createBasic('repetitions/0/moment', 'static-one'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/description', 'uuid'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/amount', 'random-amount'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/source_id', 'random-asset-id'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/destination_id', 'random-expense-id'));
|
||||
$configuration->addMandatoryFieldSet($defaultSet);
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function minimalSets(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
// three sets:
|
||||
$combis = [
|
||||
['withdrawal', 1, 8],
|
||||
['deposit', 9, 1],
|
||||
['transfer', 1, 2],
|
||||
];
|
||||
|
||||
$types = [
|
||||
['daily', ''],
|
||||
['weekly', (string)$faker->numberBetween(1, 7)],
|
||||
['ndom', (string)$faker->numberBetween(1, 4) . ',' . $faker->numberBetween(1, 7)],
|
||||
['monthly', (string)$faker->numberBetween(1, 31)],
|
||||
['yearly', $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d')],
|
||||
];
|
||||
$set = [];
|
||||
$defaultSet = new FieldSet();
|
||||
$defaultSet->title = 'default_deposit';
|
||||
$defaultSet->addField(Field::createBasic('type', 'static-deposit'));
|
||||
$defaultSet->addField(Field::createBasic('title', 'uuid'));
|
||||
$defaultSet->addField(Field::createBasic('first_date', 'random-future-date'));
|
||||
$defaultSet->addField(Field::createBasic('repeat_until', 'random-future-date'));
|
||||
$defaultSet->addField(Field::createBasic('repetitions/0/type', 'static-type-weekly'));
|
||||
$defaultSet->addField(Field::createBasic('repetitions/0/moment', 'static-one'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/description', 'uuid'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/amount', 'random-amount'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/source_id', 'random-revenue-id'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/destination_id', 'random-asset-id'));
|
||||
$configuration->addMandatoryFieldSet($defaultSet);
|
||||
|
||||
foreach ($combis as $combi) {
|
||||
foreach ($types as $type) {
|
||||
$set[] = [
|
||||
'parameters' => [],
|
||||
'fields' => [
|
||||
'type' => $combi[0],
|
||||
'title' => $faker->uuid,
|
||||
'first_date' => $faker->date(),
|
||||
'repeat_until' => $faker->date(),
|
||||
'repetitions' => [
|
||||
[
|
||||
'type' => $type[0],
|
||||
'moment' => $type[1],
|
||||
],
|
||||
],
|
||||
'transactions' => [
|
||||
[
|
||||
'description' => $faker->uuid,
|
||||
'amount' => number_format($faker->randomFloat(2, 10, 100), 2),
|
||||
'source_id' => $combi[1],
|
||||
'destination_id' => $combi[2],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
$defaultSet = new FieldSet();
|
||||
$defaultSet->title = 'default_transfer';
|
||||
$defaultSet->addField(Field::createBasic('type', 'static-transfer'));
|
||||
$defaultSet->addField(Field::createBasic('title', 'uuid'));
|
||||
$defaultSet->addField(Field::createBasic('first_date', 'random-future-date'));
|
||||
$defaultSet->addField(Field::createBasic('repeat_until', 'random-future-date'));
|
||||
$defaultSet->addField(Field::createBasic('repetitions/0/type', 'static-type-weekly'));
|
||||
$defaultSet->addField(Field::createBasic('repetitions/0/moment', 'static-one'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/description', 'uuid'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/amount', 'random-amount'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/source_id', 'random-other-asset-id'));
|
||||
$defaultSet->addField(Field::createBasic('transactions/0/destination_id', 'random-asset-id'));
|
||||
$configuration->addMandatoryFieldSet($defaultSet);
|
||||
|
||||
return $set;
|
||||
}
|
||||
// add optional set
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->addField(Field::createBasic('description', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('description', $fieldSet);
|
||||
|
||||
/**
|
||||
* @return \array[][]
|
||||
*/
|
||||
private function optionalSets(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->addField(Field::createBasic('apply_rules', 'boolean'));
|
||||
$configuration->addOptionalFieldSet('apply_rules', $fieldSet);
|
||||
|
||||
return [
|
||||
'description' => [
|
||||
'fields' => [
|
||||
'description' => $faker->uuid,
|
||||
],
|
||||
],
|
||||
'nr_of_repetitions' => [
|
||||
'fields' => [
|
||||
'nr_of_repetitions' => $faker->numberBetween(1, 2),
|
||||
],
|
||||
'remove_fields' => ['repeat_until'],
|
||||
],
|
||||
'apply_rules' => [
|
||||
'fields' => [
|
||||
'apply_rules' => $faker->boolean,
|
||||
],
|
||||
],
|
||||
'active' => [
|
||||
'fields' => [
|
||||
'active' => $faker->boolean,
|
||||
],
|
||||
],
|
||||
'notes' => [
|
||||
'fields' => [
|
||||
'notes' => $faker->uuid,
|
||||
],
|
||||
],
|
||||
'repetitions_skip' => [
|
||||
'fields' => [
|
||||
'repetitions' => [
|
||||
// first entry, set field:
|
||||
[
|
||||
'skip' => $faker->numberBetween(1, 3),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'repetitions_weekend' => [
|
||||
'fields' => [
|
||||
'repetitions' => [
|
||||
// first entry, set field:
|
||||
[
|
||||
'weekend' => $faker->numberBetween(1, 4),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->addField(Field::createBasic('active', 'boolean'));
|
||||
$configuration->addOptionalFieldSet('active', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->addField(Field::createBasic('repetitions/0/skip', 'random-skip'));
|
||||
$configuration->addOptionalFieldSet('skip', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->addField(Field::createBasic('transactions/0/foreign_amount', 'random-amount'));
|
||||
$fieldSet->addField(Field::createBasic('transactions/0/foreign_currency_id', 'random-currency-id'));
|
||||
$configuration->addOptionalFieldSet('foreign1', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->addField(Field::createBasic('transactions/0/budget_id', 'random-budget-id'));
|
||||
$configuration->addOptionalFieldSet('budget', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->addField(Field::createBasic('transactions/0/category_id', 'random-category-id'));
|
||||
$configuration->addOptionalFieldSet('category', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->addField(Field::createBasic('transactions/0/tags', 'random-tags'));
|
||||
$configuration->addOptionalFieldSet('tags', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->addField(Field::createBasic('transactions/0/piggy_bank_id', 'random-piggy-id'));
|
||||
$configuration->addOptionalFieldSet('piggy', $fieldSet);
|
||||
|
||||
return $configuration->generateAll();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,15 +175,21 @@ class StoreControllerTest extends TestCase
|
||||
*
|
||||
* emptyDataProvider / storeDataProvider
|
||||
*
|
||||
* @dataProvider storeDataProvider
|
||||
* @dataProvider emptyDataProvider
|
||||
*/
|
||||
public function testStore(array $submission): void
|
||||
{
|
||||
if ([] === $submission) {
|
||||
$this->markTestSkipped('Empty data provider');
|
||||
$this->markTestSkipped('Empty provider.');
|
||||
}
|
||||
$route = 'api.v1.recurrences.store';
|
||||
$this->storeAndCompare($route, $submission);
|
||||
Log::debug('testStoreUpdated()');
|
||||
Log::debug('submission :', $submission['submission']);
|
||||
Log::debug('expected :', $submission['expected']);
|
||||
Log::debug('ignore :', $submission['ignore']);
|
||||
// run account store with a minimal data set:
|
||||
$address = route('api.v1.recurrences.store');
|
||||
$this->assertPOST($address, $submission);
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -25,9 +25,11 @@ namespace Tests\Api\Models\Recurrence;
|
||||
use Faker\Factory;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\Objects\Field;
|
||||
use Tests\Objects\FieldSet;
|
||||
use Tests\Objects\TestConfiguration;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\CollectsValues;
|
||||
|
||||
use Tests\Traits\TestHelpers;
|
||||
|
||||
/**
|
||||
@@ -53,13 +55,18 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate(array $submission): void
|
||||
{
|
||||
$ignore = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
$route = route('api.v1.recurrences.update', [$submission['id']]);
|
||||
if ([] === $submission) {
|
||||
$this->markTestSkipped('Empty provider.');
|
||||
}
|
||||
Log::debug('testStoreUpdated()');
|
||||
Log::debug('submission :', $submission['submission']);
|
||||
Log::debug('expected :', $submission['expected']);
|
||||
Log::debug('ignore :', $submission['ignore']);
|
||||
Log::debug('parameters :', $submission['parameters']);
|
||||
|
||||
$route = route('api.v1.recurrences.update', $submission['parameters']);
|
||||
$this->assertPUT($route, $submission);
|
||||
|
||||
$this->updateAndCompare($route, $submission, $ignore);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,13 +75,117 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function updateDataProvider(): array
|
||||
{
|
||||
$submissions = [];
|
||||
$all = $this->updateDataSet();
|
||||
foreach ($all as $name => $data) {
|
||||
$submissions[] = [$data];
|
||||
}
|
||||
$configuration = new TestConfiguration;
|
||||
// optional fields
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('title', 'uuid');
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('title', $fieldSet);
|
||||
|
||||
return $submissions;
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('description', 'uuid');
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('description', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('first_date', 'random-past-date');
|
||||
$field->ignorableFields = ['repetitions'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('first_date', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('apply_rules', 'boolean');
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('apply_rules', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('active', 'boolean');
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('active', $fieldSet);
|
||||
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('repetitions/0/type', 'static-ndom');
|
||||
$field->ignorableFields = ['repetitions/0/description', 'repetitions/0/occurrences'];
|
||||
$fieldSet->addField($field);
|
||||
$fieldSet->addField(Field::createBasic('repetitions/0/moment', 'moment-ndom'));
|
||||
$configuration->addOptionalFieldSet('ndom', $fieldSet);
|
||||
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('repetitions/0/type', 'static-monthly');
|
||||
$field->ignorableFields = ['repetitions/0/description', 'repetitions/0/occurrences'];
|
||||
$fieldSet->addField($field);
|
||||
$fieldSet->addField(Field::createBasic('repetitions/0/moment', 'moment-monthly'));
|
||||
$configuration->addOptionalFieldSet('monthly', $fieldSet);
|
||||
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('repetitions/0/type', 'static-yearly');
|
||||
$field->ignorableFields = ['repetitions/0/description', 'repetitions/0/occurrences'];
|
||||
$fieldSet->addField($field);
|
||||
$fieldSet->addField(Field::createBasic('repetitions/0/moment', 'random-past-date'));
|
||||
$configuration->addOptionalFieldSet('yearly', $fieldSet);
|
||||
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('repetitions/0/skip', 'random-skip');
|
||||
$field->ignorableFields = ['repetitions/0/description', 'repetitions/0/occurrences'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('skip', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('repetitions/0/weekend', 'weekend');
|
||||
$field->ignorableFields = ['repetitions/0/description', 'repetitions/0/occurrences'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('weekend', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('transactions/0/foreign_amount', 'random-amount'));
|
||||
$field = Field::createBasic('transactions/0/foreign_currency_id', 'random-currency-id');
|
||||
$field->ignorableFields = ['transactions/0/foreign_currency_code', 'transactions/0/foreign_currency_symbol'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('foreign1', $fieldSet);
|
||||
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('transactions/0/budget_id', 'random-budget-id');
|
||||
$field->ignorableFields = ['transactions/0/budget_name'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('budget', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('transactions/0/category_id', 'random-category-id');
|
||||
$field->ignorableFields = ['transactions/0/category_name'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('category', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('transactions/0/tags', 'random-tags'));
|
||||
$configuration->addOptionalFieldSet('tags', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('transactions/0/piggy_bank_id', 'random-piggy-id');
|
||||
$field->ignorableFields = ['transactions/0/piggy_bank_name'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('piggy', $fieldSet);
|
||||
|
||||
return $configuration->generateAll();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user