mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Tests also validate existing data.
This commit is contained in:
parent
e577db4635
commit
4c2f758f69
app/Validation
tests
Api/Models
Account
Attachment
AvailableBudget
Bill
Budget
BudgetLimit
Category
ObjectGroup
PiggyBank
Recurrence
Objects
Traits
@ -102,6 +102,16 @@ trait RecurrenceValidation
|
||||
$transactionType = $transaction['type'] ?? $transactionType;
|
||||
$accountValidator->setTransactionType($transactionType);
|
||||
|
||||
if(
|
||||
!array_key_exists('source_id', $transaction) &&
|
||||
!array_key_exists('destination_id', $transaction) &&
|
||||
!array_key_exists('source_name', $transaction) &&
|
||||
!array_key_exists('destination_name', $transaction)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// validate source account.
|
||||
$sourceId = isset($transaction['source_id']) ? (int)$transaction['source_id'] : null;
|
||||
$sourceName = $transaction['source_name'] ?? null;
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,13 +56,36 @@ class TestConfiguration
|
||||
$ignored = $this->ignores;
|
||||
$expected = $this->expected;
|
||||
|
||||
// update ignored parameters:
|
||||
$newIgnored = [];
|
||||
foreach ($ignored as $index => $currentIgnored) {
|
||||
$updated = [];
|
||||
foreach ($currentIgnored as $key => $value) {
|
||||
$key = (int)$key;
|
||||
$positions = explode('/', $value);
|
||||
$count = count($positions);
|
||||
if (1 === $count) {
|
||||
$updated[$key] = $value;
|
||||
continue;
|
||||
}
|
||||
if (3 === $count) {
|
||||
$root = $positions[0];
|
||||
$count = (int)$positions[1];
|
||||
$final = $positions[2];
|
||||
$updated[$root][$count][] = $final;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$newIgnored[$index] = $updated;
|
||||
}
|
||||
|
||||
// now create a combination for each submission and associated data:
|
||||
$final = [];
|
||||
foreach ($array as $index => $submission) {
|
||||
$final[] = [[
|
||||
'submission' => $submission,
|
||||
'expected' => $expected[$index] ?? $submission,
|
||||
'ignore' => $ignored[$index] ?? [],
|
||||
'ignore' => $newIgnored[$index] ?? [],
|
||||
'parameters' => $parameters[$index] ?? [],
|
||||
]];
|
||||
}
|
||||
@ -247,7 +270,7 @@ class TestConfiguration
|
||||
$final = $positions[2];
|
||||
$current[$root] = array_key_exists($root, $current) ? $current[$root] : [];
|
||||
$current[$root][$count] = array_key_exists($count, $current[$root]) ? $current[$root][$count] : [];
|
||||
$current[$root][$count][$final] = $this->generateFieldValue($final);
|
||||
$current[$root][$count][$final] = $this->generateFieldValue($field->fieldType);
|
||||
|
||||
return $current;
|
||||
}
|
||||
@ -295,6 +318,8 @@ class TestConfiguration
|
||||
return $faker->randomElement(['half-year', 'weekly', 'monthly', 'yearly']);
|
||||
case 'random-past-date':
|
||||
return $faker->dateTimeBetween('-3 years', '-1 years')->format('Y-m-d');
|
||||
case 'random-future-date':
|
||||
return $faker->dateTimeBetween('1 years', '3 years')->format('Y-m-d');
|
||||
case 'random-date-two-year':
|
||||
return $faker->dateTimeBetween('-2 years', '-1 years')->format('Y-m-d');
|
||||
case 'random-date-one-year':
|
||||
@ -332,14 +357,51 @@ class TestConfiguration
|
||||
return number_format($faker->randomFloat(2, 50, 100), 2);
|
||||
case 'random-skip':
|
||||
return $faker->numberBetween(0, 4);
|
||||
case 'random-budget-id':
|
||||
case 'random-category-id':
|
||||
case 'random-piggy-id':
|
||||
case 'random-og-id':
|
||||
return $faker->numberBetween(1, 2);
|
||||
case 'random-tags':
|
||||
return $faker->randomElements(['a', 'b', 'c', 'd', 'ef', 'gh'], 3);
|
||||
case 'random-auto-type':
|
||||
return $faker->randomElement(['rollover', 'reset']);
|
||||
case 'random-auto-period':
|
||||
return $faker->randomElement(['weekly', 'monthly', 'yearly']);
|
||||
case 'static-auto-none':
|
||||
return 'none';
|
||||
case 'random-piggy-account':
|
||||
return $faker->numberBetween(1, 3);
|
||||
case 'static-withdrawal':
|
||||
return 'withdrawal';
|
||||
case 'static-ndom':
|
||||
return 'ndom';
|
||||
case 'moment-ndom':
|
||||
return sprintf('%d,%d', $faker->numberBetween(1, 4), $faker->numberBetween(1, 7));
|
||||
case 'static-monthly':
|
||||
return 'monthly';
|
||||
case 'moment-monthly':
|
||||
return $faker->numberBetween(1, 28);
|
||||
case 'static-yearly':
|
||||
return 'yearly';
|
||||
case 'static-deposit':
|
||||
return 'deposit';
|
||||
case 'static-transfer':
|
||||
return 'transfer';
|
||||
case 'static-type-weekly':
|
||||
return 'weekly';
|
||||
case 'random-nr-of-reps':
|
||||
return $faker->numberBetween(5, 12);
|
||||
case 'weekend':
|
||||
return $faker->numberBetween(1, 4);
|
||||
case 'random-asset-id':
|
||||
return $faker->randomElement([1, 2, 3]);
|
||||
case 'random-other-asset-id':
|
||||
return $faker->randomElement([4, 5, 6]);
|
||||
case 'random-expense-id':
|
||||
return $faker->randomElement([8, 11, 12]);
|
||||
case 'random-revenue-id':
|
||||
return $faker->randomElement([9, 10]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -439,13 +501,26 @@ class TestConfiguration
|
||||
if (count($customFields) > 0) {
|
||||
/** @var Field $field */
|
||||
foreach ($customFields as $field) {
|
||||
if (null === $field->expectedReturn) {
|
||||
$this->expected[$index][$field->fieldTitle] = $this->submission[$index][$field->fieldTitle];
|
||||
// fieldTitle indicates the position:
|
||||
$positions = explode('/', $field->fieldTitle);
|
||||
$count = count($positions);
|
||||
if (1 === $count) {
|
||||
if (null === $field->expectedReturn) {
|
||||
$this->expected[$index][$field->fieldTitle] = $this->submission[$index][$field->fieldTitle];
|
||||
}
|
||||
if (null !== $field->expectedReturn) {
|
||||
$this->expected[$index][$field->fieldTitle] = ($field->expectedReturn)($this->submission[$index][$field->fieldTitle]);
|
||||
}
|
||||
}
|
||||
if (null !== $field->expectedReturn) {
|
||||
$this->expected[$index][$field->fieldTitle] = ($field->expectedReturn)($this->submission[$index][$field->fieldTitle]);
|
||||
if (3 === $count) {
|
||||
$root = $positions[0];
|
||||
$count = (int)$positions[1];
|
||||
$final = $positions[2];
|
||||
$this->expected[$index][$root] = array_key_exists($root, $this->expected[$index]) ? $this->expected[$index][$root] : [];
|
||||
$this->expected[$index][$root][$count] = array_key_exists($count, $this->expected[$index][$root])
|
||||
? $this->expected[$index][$root][$count] : [];
|
||||
$this->expected[$index][$root][$count][$final] = $this->submission[$index][$root][$count][$final];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,11 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Tests\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Trait TestHelpers
|
||||
*/
|
||||
@ -34,6 +37,7 @@ trait TestHelpers
|
||||
*/
|
||||
protected function assertPOST(string $route, array $content): void
|
||||
{
|
||||
Log::debug('Now in assertPOST()');
|
||||
$submission = $content['submission'];
|
||||
$expected = $content['expected'];
|
||||
$ignore = $content['ignore'];
|
||||
@ -61,9 +65,13 @@ trait TestHelpers
|
||||
*/
|
||||
private function comparePOSTArray(array $submission, array $response, array $expected, array $ignore): void
|
||||
{
|
||||
Log::debug('Now in comparePOSTArray()');
|
||||
foreach ($response as $key => $value) {
|
||||
Log::debug(sprintf('Now working on (sub)response key ["%s"]', $key));
|
||||
if (is_array($value) && array_key_exists($key, $expected) && is_array($expected[$key])) {
|
||||
Log::debug(sprintf('(Sub)response key ["%s"] is an array!', $key));
|
||||
$this->comparePOSTArray($submission, $value, $expected[$key], $ignore[$key] ?? []);
|
||||
continue;
|
||||
}
|
||||
if (isset($expected[$key])) {
|
||||
if (in_array($key, $ignore, true)) {
|
||||
@ -94,9 +102,18 @@ trait TestHelpers
|
||||
*/
|
||||
protected function assertPUT(string $route, array $content): void
|
||||
{
|
||||
$submission = $content['submission'];
|
||||
$ignore = $content['ignore'];
|
||||
$expected = $content['expected'];
|
||||
$submission = $content['submission'];
|
||||
$ignore = $content['ignore'];
|
||||
$expected = $content['expected'];
|
||||
|
||||
// get the original first:
|
||||
$original = $this->get($route, ['Accept' => 'application/json']);
|
||||
$originalBody = $original->content();
|
||||
$originalJson = json_decode($originalBody, true);
|
||||
$originalAttributes = $originalJson['data']['attributes'];
|
||||
$status = $original->getStatusCode();
|
||||
$this->assertEquals($status, 200, sprintf("Response: %s", json_encode($originalBody)));
|
||||
|
||||
$response = $this->put($route, $submission, ['Accept' => 'application/json']);
|
||||
$responseBody = $response->content();
|
||||
$responseJson = json_decode($responseBody, true);
|
||||
@ -106,7 +123,7 @@ trait TestHelpers
|
||||
|
||||
// get return and compare each field
|
||||
$responseAttributes = $responseJson['data']['attributes'];
|
||||
$this->comparePUTArray($route, $submission, $responseAttributes, $expected, $ignore);
|
||||
$this->comparePUTArray($route, $submission, $responseAttributes, $expected, $ignore, $originalAttributes);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,13 +132,15 @@ trait TestHelpers
|
||||
* @param array $response
|
||||
* @param array $expected
|
||||
* @param array $ignore
|
||||
* @param array $original
|
||||
*/
|
||||
private function comparePUTArray(string $url, array $submission, array $response, array $expected, array $ignore): void
|
||||
private function comparePUTArray(string $url, array $submission, array $response, array $expected, array $ignore, array $original): void
|
||||
{
|
||||
|
||||
$extraIgnore = ['created_at', 'updated_at', 'id'];
|
||||
foreach ($response as $key => $value) {
|
||||
if (is_array($value) && array_key_exists($key, $submission) && is_array($submission[$key])) {
|
||||
$this->comparePUTArray($url, $submission[$key], $value, $expected[$key], $ignore[$key] ?? []);
|
||||
$this->comparePUTArray($url, $submission[$key], $value, $expected[$key], $ignore[$key] ?? [], $original[$key] ?? []);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($submission[$key])) {
|
||||
@ -144,6 +163,28 @@ trait TestHelpers
|
||||
$this->assertEquals($value, $expected[$key], $message);
|
||||
}
|
||||
}
|
||||
// if not set, compare to original to see if it's the same:
|
||||
if (
|
||||
!isset($submission[$key])
|
||||
&& isset($response[$key])
|
||||
&& isset($original[$key])
|
||||
&& !in_array($key, $ignore, true)
|
||||
&& !in_array($key, $extraIgnore, true)) {
|
||||
|
||||
$message = sprintf(
|
||||
"Field '%s' was unexpectedly changed from %s to %s.\nSubmitted: %s\nIgnored: %s\nExpected: %s\nReturned: %s\nURL: %s",
|
||||
$key,
|
||||
json_encode($original[$key]),
|
||||
json_encode($response[$key]),
|
||||
json_encode($submission),
|
||||
json_encode($ignore),
|
||||
json_encode($expected),
|
||||
json_encode($response),
|
||||
$url
|
||||
);
|
||||
$this->assertEquals($response[$key], $original[$key], $message);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user