diff --git a/app/Repositories/TransactionGroup/TransactionGroupRepository.php b/app/Repositories/TransactionGroup/TransactionGroupRepository.php
index 1abeb637a4..724cef96b3 100644
--- a/app/Repositories/TransactionGroup/TransactionGroupRepository.php
+++ b/app/Repositories/TransactionGroup/TransactionGroupRepository.php
@@ -329,6 +329,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
::table('tag_transaction_journal')
->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id')
->where('tag_transaction_journal.transaction_journal_id', $journalId)
+ ->orderBy('tags.tag','ASC')
->get(['tags.tag']);
return $result->pluck('tag')->toArray();
diff --git a/phpunit.xml b/phpunit.xml
index e31893cf4f..73f6dfa065 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -36,11 +36,23 @@
+
+ ./tests/Api/Models/Transaction
diff --git a/tests/Api/Models/Recurrence/UpdateControllerTest.php b/tests/Api/Models/Recurrence/UpdateControllerTest.php
index 08e13010ec..40732cdc65 100644
--- a/tests/Api/Models/Recurrence/UpdateControllerTest.php
+++ b/tests/Api/Models/Recurrence/UpdateControllerTest.php
@@ -187,164 +187,4 @@ class UpdateControllerTest extends TestCase
return $configuration->generateAll();
}
-
-
- /**
- * @return array
- */
- public function updateDataSet(): array
- {
- $faker = Factory::create();
- $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 = [
- 'title' => [
- 'id' => 1,
- 'fields' => [
- 'title' => ['test_value' => $faker->uuid],
- ],
- 'extra_ignore' => [],
- ],
- 'description' => [
- 'id' => 1,
- 'fields' => [
- 'description' => ['test_value' => $faker->uuid],
- ],
- 'extra_ignore' => [],
- ],
- 'first_date' => [
- 'id' => 1,
- 'fields' => [
- 'first_date' => ['test_value' => $faker->date()],
- ],
- 'extra_ignore' => [],
- ],
- 'repeat_until' => [
- 'id' => 1,
- 'fields' => [
- 'repeat_until' => ['test_value' => $faker->dateTimeBetween('1 year', '2 year')->format('Y-m-d')],
- ],
- 'extra_ignore' => [],
- ],
- 'nr_of_repetitions' => [
- 'id' => 1,
- 'fields' => [
- 'nr_of_repetitions' => ['test_value' => $faker->numberBetween(1, 5)],
- ],
- 'extra_ignore' => ['repeat_until'],
- ],
- 'apply_rules' => [
- 'id' => 1,
- 'fields' => [
- 'apply_rules' => ['test_value' => $faker->boolean],
- ],
- 'extra_ignore' => [],
- ],
- 'active' => [
- 'id' => 1,
- 'fields' => [
- 'active' => ['test_value' => $faker->boolean],
- ],
- 'extra_ignore' => [],
- ],
- 'notes' => [
- 'id' => 1,
- 'fields' => [
- 'notes' => ['test_value' => $faker->uuid],
- ],
- 'extra_ignore' => [],
- ],
- ];
- // repetitions. Will submit 0,1 2 3 repetitions:
- for ($i = 0; $i < 4; $i++) {
- if (0 === $i) {
- $set[] = [
- 'id' => 1,
- 'fields' => [
- 'repetitions' => [
- 'test_value' => [],
- ],
- ],
- 'extra_ignore' => [],
- ];
- continue;
- }
- $extraRepetitions = [];
- // do $i repetitions
- for ($ii = 0; $ii < $i; $ii++) {
- // now loop fields, enough to create sets I guess?
- $thisType = $types[$faker->numberBetween(0, 4)];
- // TODO maybe do some permutation stuff here?
- $extraRepetition = [
- 'type' => $thisType[0],
- 'moment' => $thisType[1],
- 'skip' => $faker->numberBetween(1, 3),
- 'weekend' => $faker->numberBetween(1, 4),
- ];
-
- $extraRepetitions[] = $extraRepetition;
- }
- $set[] = [
- 'id' => 1,
- 'fields' => [
- 'repetitions' => [
- 'test_value' => $extraRepetitions,
- ],
- ],
- 'extra_ignore' => [],
- ];
- }
-
- // transactions. Will submit 0,1 2 3 transactions:
- for ($i = 0; $i < 4; $i++) {
- if (0 === $i) {
- $set[] = [
- 'id' => 1,
- 'fields' => [
- 'transactions' => [
- 'test_value' => [],
- ],
- ],
- 'extra_ignore' => [],
- ];
- continue;
- }
- $extraTransactions = [];
- // do $i repetitions
- for ($ii = 0; $ii < $i; $ii++) {
- // now loop fields, enough to create sets I guess?
- // TODO maybe do some permutation stuff here?
- $extraTransaction = [
- 'currency_id' => (string)$faker->numberBetween(1, 4),
- 'foreign_currency_id' => (string)$faker->numberBetween(4, 6),
- 'source_id' => $faker->numberBetween(1, 3),
- 'destination_id' => $faker->numberBetween(8, 8),
- 'amount' => number_format($faker->randomFloat(2, 10, 100), 2),
- 'foreign_amount' => number_format($faker->randomFloat(2, 10, 100), 2),
- 'description' => $faker->uuid,
- ];
-
- $extraTransactions[] = $extraTransaction;
- }
- $set[] = [
- 'id' => 1,
- 'fields' => [
- 'transactions' => [
- 'test_value' => $extraTransactions,
- ],
- ],
- 'extra_ignore' => [],
- ];
- }
-
- return $set;
- }
-
-
}
\ No newline at end of file
diff --git a/tests/Api/Models/Rule/StoreControllerTest.php b/tests/Api/Models/Rule/StoreControllerTest.php
index 1bf76edd88..88d9f58c59 100644
--- a/tests/Api/Models/Rule/StoreControllerTest.php
+++ b/tests/Api/Models/Rule/StoreControllerTest.php
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\Rule;
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,159 +64,65 @@ 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_rule_id';
+ $defaultSet->addField(Field::createBasic('title', 'uuid'));
+ $defaultSet->addField(Field::createBasic('rule_group_id', 'random-rule-group-id'));
+ $defaultSet->addField(Field::createBasic('trigger', 'random-trigger'));
+ $defaultSet->addField(Field::createBasic('triggers/0/type', 'random-trigger-type'));
+ $defaultSet->addField(Field::createBasic('triggers/0/value', 'uuid'));
+ $defaultSet->addField(Field::createBasic('actions/0/type', 'random-action-type'));
+ $defaultSet->addField(Field::createBasic('actions/0/value', 'uuid'));
+ $configuration->addMandatoryFieldSet($defaultSet);
- return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
- }
+ $defaultSet = new FieldSet();
+ $defaultSet->title = 'default_rule_name';
+ $defaultSet->addField(Field::createBasic('title', 'uuid'));
+ $defaultSet->addField(Field::createBasic('rule_group_title', 'random-rule-group-title'));
+ $defaultSet->addField(Field::createBasic('trigger', 'random-trigger'));
+ $defaultSet->addField(Field::createBasic('triggers/0/type', 'random-trigger-type'));
+ $defaultSet->addField(Field::createBasic('triggers/0/value', 'uuid'));
+ $defaultSet->addField(Field::createBasic('actions/0/type', 'random-action-type'));
+ $defaultSet->addField(Field::createBasic('actions/0/value', 'uuid'));
+ $configuration->addMandatoryFieldSet($defaultSet);
- /**
- * @return array
- */
- private function minimalSets(): array
- {
- $faker = Factory::create();
- // - title
- // - rule_group_id
- // - trigger
- // - triggers
- // - actions
- $set = [
- 'default_by_id' => [
- 'parameters' => [],
- 'fields' => [
- 'title' => $faker->uuid,
- 'rule_group_id' => (string)$faker->randomElement([1, 2]),
- 'trigger' => $faker->randomElement(['store-journal', 'update-journal']),
- 'triggers' => [
- [
- 'type' => $faker->randomElement(['from_account_starts', 'from_account_is', 'description_ends', 'description_is']),
- 'value' => $faker->uuid,
- ],
- ],
- 'actions' => [
- [
- 'type' => $faker->randomElement(['set_category', 'add_tag', 'set_description']),
- 'value' => $faker->uuid,
- ],
- ],
- ],
- ],
- 'default_by_title' => [
- 'parameters' => [],
- 'fields' => [
- 'title' => $faker->uuid,
- 'rule_group_title' => sprintf('Rule group %d', $faker->randomElement([1, 2])),
- 'trigger' => $faker->randomElement(['store-journal', 'update-journal']),
- 'triggers' => [
- [
- 'type' => $faker->randomElement(['from_account_starts', 'from_account_is', 'description_ends', 'description_is']),
- 'value' => $faker->uuid,
- ],
- ],
- 'actions' => [
- [
- 'type' => $faker->randomElement(['set_category', 'add_tag', 'set_description']),
- 'value' => $faker->uuid,
- ],
- ],
- ],
- ],
- ];
+ // add optional set
+ $fieldSet = new FieldSet;
+ $fieldSet->addField(Field::createBasic('order', 'low-order'));
+ $configuration->addOptionalFieldSet('order', $fieldSet);
- // leave it like this for now.
+ $fieldSet = new FieldSet;
+ $fieldSet->addField(Field::createBasic('active', 'boolean'));
+ $configuration->addOptionalFieldSet('active', $fieldSet);
- return $set;
+ $fieldSet = new FieldSet;
+ $fieldSet->addField(Field::createBasic('strict', 'boolean'));
+ $configuration->addOptionalFieldSet('strict', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->addField(Field::createBasic('stop_processing', 'boolean'));
+ $configuration->addOptionalFieldSet('stop_processing', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->addField(Field::createBasic('triggers/0/stop_processing', 'boolean'));
+ $configuration->addOptionalFieldSet('stop_processingX', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->addField(Field::createBasic('triggers/0/active', 'boolean'));
+ $configuration->addOptionalFieldSet('activeX', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->addField(Field::createBasic('actions/0/active', 'boolean'));
+ $configuration->addOptionalFieldSet('activeXX', $fieldSet);
- }
+ return $configuration->generateAll();
- /**
- * @return \array[][]
- */
- private function optionalSets(): array
- {
- $faker = Factory::create();
- return [
- 'order' => [
- 'fields' => [
- 'order' => $faker->numberBetween(1, 2),
- ],
- ],
- 'active' => [
- 'fields' => [
- 'active' => $faker->boolean,
- ],
- ],
- 'strict' => [
- 'fields' => [
- 'strict' => $faker->boolean,
- ],
- ],
- 'stop_processing' => [
- 'fields' => [
- 'stop_processing' => $faker->boolean,
- ],
- ],
- 'triggers_order' => [
- 'fields' => [
- 'triggers' => [
- // first entry, set field:
- [
- 'order' => 1,
- ],
- ],
- ],
- ],
- 'triggers_active' => [
- 'fields' => [
- 'triggers' => [
- // first entry, set field:
- [
- 'active' => false,
- ],
- ],
- ],
- ],
- 'triggers_not_active' => [
- 'fields' => [
- 'triggers' => [
- // first entry, set field:
- [
- 'active' => true,
- ],
- ],
- ],
- ],
- 'triggers_processing' => [
- 'fields' => [
- 'triggers' => [
- // first entry, set field:
- [
- 'stop_processing' => true,
- ],
- ],
- ],
- ],
- 'triggers_not_processing' => [
- 'fields' => [
- 'triggers' => [
- // first entry, set field:
- [
- 'stop_processing' => false,
- ],
- ],
- ],
- ],
- ];
}
/**
@@ -221,15 +130,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.rules.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.rules.store');
+ $this->assertPOST($address, $submission);
}
}
\ No newline at end of file
diff --git a/tests/Api/Models/Rule/UpdateControllerTest.php b/tests/Api/Models/Rule/UpdateControllerTest.php
new file mode 100644
index 0000000000..df8a76a885
--- /dev/null
+++ b/tests/Api/Models/Rule/UpdateControllerTest.php
@@ -0,0 +1,168 @@
+.
+ */
+
+namespace Tests\Api\Models\Rule;
+
+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;
+
+/**
+ * Class UpdateControllerTest
+ */
+class UpdateControllerTest extends TestCase
+{
+ use TestHelpers, CollectsValues;
+
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Passport::actingAs($this->user());
+ Log::info(sprintf('Now in %s.', get_class($this)));
+ }
+
+
+ /**
+ * @dataProvider updateDataProvider
+ */
+ public function testUpdate(array $submission): void
+ {
+ 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);
+
+ }
+
+
+ /**
+ * @return array
+ */
+ public function updateDataProvider(): array
+ {
+ $configuration = new TestConfiguration;
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('title', 'uuid');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('title', $fieldSet);
+
+ $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('order', 'low-order');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('order', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('trigger', 'random-trigger'));
+ $configuration->addOptionalFieldSet('trigger', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('active', 'boolean'));
+ $configuration->addOptionalFieldSet('active', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('strict', 'boolean'));
+ $configuration->addOptionalFieldSet('strict', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('stop_processing', 'boolean'));
+ $configuration->addOptionalFieldSet('stop_processing', $fieldSet);
+
+ // sub trigger fields
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('triggers/0/type', 'random-trigger-type');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('trigger_type', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('triggers/0/value', 'uuid');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('trigger_value', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('triggers/0/active', 'boolean');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('trigger_active', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('triggers/0/stop_processing', 'boolean');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('stop_processing', $fieldSet);
+
+ // optional action fields
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('actions/0/type', 'random-action-type');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('action_type', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('actions/0/value', 'uuid');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('action_value', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('actions/0/active', 'boolean');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('action_active', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('actions/0/stop_processing', 'boolean');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('action_stop_processing', $fieldSet);
+
+ return $configuration->generateAll();
+ }
+}
\ No newline at end of file
diff --git a/tests/Api/Models/RuleGroup/StoreControllerTest.php b/tests/Api/Models/RuleGroup/StoreControllerTest.php
index 2f54e628f3..0175a865f8 100644
--- a/tests/Api/Models/RuleGroup/StoreControllerTest.php
+++ b/tests/Api/Models/RuleGroup/StoreControllerTest.php
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\RuleGroup;
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,60 +64,33 @@ 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_object';
+ $defaultSet->addField(Field::createBasic('title', 'uuid'));
+ $configuration->addMandatoryFieldSet($defaultSet);
- return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
- }
+ // optionals
+ $fieldSet = new FieldSet;
+ $field = Field::createBasic('description', 'uuid');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('description', $fieldSet);
- /**
- * @return array
- */
- private function minimalSets(): array
- {
- $faker = Factory::create();
+ $fieldSet = new FieldSet;
+ $field = Field::createBasic('order', 'low-order');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('order', $fieldSet);
- return [
- 'default_group' => [
- 'parameters' => [],
- 'fields' => [
- 'title' => $faker->uuid,
- ],
- ],
- ];
- }
+ $fieldSet = new FieldSet;
+ $field = Field::createBasic('active', 'boolean');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('active', $fieldSet);
- /**
- * @return \array[][]
- */
- private function optionalSets(): array
- {
- $faker = Factory::create();
+ return $configuration->generateAll();
- return [
- 'description' => [
- 'fields' => [
- 'description' => $faker->uuid,
- ],
- ],
- 'order' => [
- 'fields' => [
- 'order' => $faker->numberBetween(1, 5),
- ],
- ],
- 'active' => [
- 'fields' => [
- 'active' => $faker->boolean,
- ],
- ],
- ];
}
/**
@@ -127,10 +103,15 @@ class StoreControllerTest extends TestCase
public function testStore(array $submission): void
{
if ([] === $submission) {
- $this->markTestSkipped('Empty data provider');
+ $this->markTestSkipped('Empty provider.');
}
- $route = 'api.v1.rule_groups.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.rule_groups.store');
+ $this->assertPOST($address, $submission);
}
}
\ No newline at end of file
diff --git a/tests/Api/Models/RuleGroup/UpdateControllerTest.php b/tests/Api/Models/RuleGroup/UpdateControllerTest.php
index 71acbb783e..f8df066add 100644
--- a/tests/Api/Models/RuleGroup/UpdateControllerTest.php
+++ b/tests/Api/Models/RuleGroup/UpdateControllerTest.php
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\RuleGroup;
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.rule_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.rule_groups.update', $submission['parameters']);
+ $this->assertPUT($route, $submission);
}
@@ -68,55 +75,32 @@ 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];
+ $field = Field::createBasic('title', 'uuid');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('title', $fieldSet);
+
+ $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('order', 'low-order');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('order', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('active', 'boolean');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('active', $fieldSet);
+
+ return $configuration->generateAll();
}
-
-
- /**
- * @return array
- */
- public function updateDataSet(): array
- {
- $faker = Factory::create();
- $set = [
- 'title' => [
- 'id' => 1,
- 'fields' => [
- 'title' => ['test_value' => $faker->uuid],
- ],
- 'extra_ignore' => [],
- ],
- 'description' => [
- 'id' => 1,
- 'fields' => [
- 'description' => ['test_value' => join(' ', $faker->words(5))],
- ],
- 'extra_ignore' => [],
- ],
- 'order' => [
- 'id' => 1,
- 'fields' => [
- 'order' => ['test_value' => $faker->numberBetween(1, 5)],
- ],
- 'extra_ignore' => [],
- ],
- 'active' => [
- 'id' => 1,
- 'fields' => [
- 'active' => ['test_value' => $faker->boolean],
- ],
- 'extra_ignore' => [],
- ],
- ];
-
- return $set;
- }
-
-
}
\ No newline at end of file
diff --git a/tests/Api/Models/Tag/StoreControllerTest.php b/tests/Api/Models/Tag/StoreControllerTest.php
index a7777bf2c3..e8da126767 100644
--- a/tests/Api/Models/Tag/StoreControllerTest.php
+++ b/tests/Api/Models/Tag/StoreControllerTest.php
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\Tag;
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,62 +64,33 @@ class StoreControllerTest extends TestCase
*/
public function storeDataProvider(): array
{
- $minimalSets = $this->minimalSets();
- $optionalSets = $this->optionalSets();
- $regenConfig = [
- 'tag' => 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('tag', 'uuid'));
+ $configuration->addMandatoryFieldSet($defaultSet);
- return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
- }
+ // optionals
+ $fieldSet = new FieldSet;
+ $field = Field::createBasic('date', 'random-past-date');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('date', $fieldSet);
- /**
- * @return array
- */
- private function minimalSets(): array
- {
- $faker = Factory::create();
+ $fieldSet = new FieldSet;
+ $field = Field::createBasic('description', 'uuid');
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('description', $fieldSet);
- return [
- 'default_tag' => [
- 'parameters' => [],
- 'fields' => [
- 'tag' => $faker->uuid,
- ],
- ],
- ];
- }
+ $fieldSet = new FieldSet;
+ $fieldSet->addField(Field::createBasic('longitude', 'longitude'));
+ $fieldSet->addField(Field::createBasic('latitude', 'latitude'));
+ $fieldSet->addField(Field::createBasic('zoom_level', 'random-zoom_level'));
+ $configuration->addOptionalFieldSet('location', $fieldSet);
- /**
- * @return \array[][]
- */
- private function optionalSets(): array
- {
- $faker = Factory::create();
-
- return [
- 'date' => [
- 'fields' => [
- 'date' => $faker->date('Y-m-d'),
- ],
- ],
- 'description' => [
- 'fields' => [
- 'description' => join(' ', $faker->words(4)),
- ],
- ],
- 'location' => [
- 'fields' => [
- 'longitude' => $faker->longitude,
- 'latitude' => $faker->latitude,
- 'zoom_level' => $faker->numberBetween(1, 6),
- ],
- ],
- ];
+ return $configuration->generateAll();
}
/**
@@ -129,10 +103,16 @@ class StoreControllerTest extends TestCase
public function testStore(array $submission): void
{
if ([] === $submission) {
- $this->markTestSkipped('Empty data provider');
+ $this->markTestSkipped('Empty provider.');
}
- $route = 'api.v1.tags.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.tags.store');
+ $this->assertPOST($address, $submission);
+
}
}
\ No newline at end of file
diff --git a/tests/Api/Models/Tag/UpdateControllerTest.php b/tests/Api/Models/Tag/UpdateControllerTest.php
index 67b3d19325..7f215c70ab 100644
--- a/tests/Api/Models/Tag/UpdateControllerTest.php
+++ b/tests/Api/Models/Tag/UpdateControllerTest.php
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\Tag;
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.tags.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.tags.update', $submission['parameters']);
+ $this->assertPUT($route, $submission);
}
@@ -68,57 +75,30 @@ 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('tag', 'uuid'));
+ $configuration->addOptionalFieldSet('tag', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('date', 'random-past-date'));
+ $configuration->addOptionalFieldSet('date', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('description', 'uuid'));
+ $configuration->addOptionalFieldSet('description', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('longitude', 'longitude'));
+ $fieldSet->addField(Field::createBasic('latitude', 'latitude'));
+ $fieldSet->addField(Field::createBasic('zoom_level', 'random-zoom_level'));
+ $configuration->addOptionalFieldSet('location', $fieldSet);
+
+ return $configuration->generateAll();
}
-
-
- /**
- * @return array
- */
- public function updateDataSet(): array
- {
- $faker = Factory::create();
- $set = [
- 'tag' => [
- 'id' => 1,
- 'fields' => [
- 'tag' => ['test_value' => $faker->uuid],
- ],
- 'extra_ignore' => [],
- ],
- 'date' => [
- 'id' => 1,
- 'fields' => [
- 'date' => ['test_value' => $faker->date()],
- ],
- 'extra_ignore' => [],
- ],
- 'description' => [
- 'id' => 1,
- 'fields' => [
- 'description' => ['test_value' => join(' ', $faker->words(5))],
- ],
- 'extra_ignore' => [],
- ],
- 'location' => [
- 'id' => 1,
- 'fields' => [
- 'longitude' => ['test_value' => $faker->longitude],
- 'latitude' => ['test_value' => $faker->latitude],
- 'zoom_level' => ['test_value' => $faker->numberBetween(1, 6)],
- ],
- 'extra_ignore' => [],
- ],
- ];
-
- return $set;
- }
-
-
}
\ No newline at end of file
diff --git a/tests/Api/Models/Transaction/StoreControllerTest.php b/tests/Api/Models/Transaction/StoreControllerTest.php
index 20696056d6..c6b6755727 100644
--- a/tests/Api/Models/Transaction/StoreControllerTest.php
+++ b/tests/Api/Models/Transaction/StoreControllerTest.php
@@ -22,13 +22,14 @@
namespace Tests\Api\Models\Transaction;
-use DateTimeInterface;
-use Faker\Factory;
+use Carbon\Carbon;
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;
/**
@@ -62,152 +63,82 @@ class StoreControllerTest extends TestCase
*/
public function storeDataProvider(): array
{
- $minimalSets = $this->minimalSets();
- $optionalSets = $this->optionalSets();
- $regenConfig = [
- 'transactions' => [
- [
- 'description' => function () {
- $faker = Factory::create();
- return $faker->uuid;
- },
- ],
- ],
- ];
+ // some test configs:
+ $configuration = new TestConfiguration;
- return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
- }
+ // default test set:
+ $defaultSet = new FieldSet();
+ $defaultSet->title = 'default_object_withdrawal';
+ $defaultSet->addField(Field::createBasic('error_if_duplicate_hash', 'boolean'));
+ $defaultSet->addField(Field::createBasic('transactions/0/type', 'static-withdrawal'));
+ $field = Field::createBasic('transactions/0/date', 'random-past-date');
+ $field->expectedReturn = function ($value) {
+ $date = new Carbon($value, 'Europe/Amsterdam');
- /**
- * @return array
- */
- private function minimalSets(): array
- {
- $faker = Factory::create();
+ return $date->toIso8601String();
+ };
+ $defaultSet->addField($field);
- // 3 sets:
- $combis = [
- ['withdrawal', 1, 8],
- ['deposit', 9, 1],
- ['transfer', 1, 2],
- ];
- $set = [];
- foreach ($combis as $combi) {
- $set[] = [
- 'parameters' => [],
- 'fields' => [
- 'error_if_duplicate_hash' => $faker->boolean,
- 'transactions' => [
- [
- 'type' => $combi[0],
- 'date' => $faker->dateTime(null, 'Europe/Amsterdam')->format(DateTimeInterface::RFC3339),
- 'amount' => number_format($faker->randomFloat(2, 10, 100), 12),
- 'description' => $faker->uuid,
- 'source_id' => $combi[1],
- 'destination_id' => $combi[2],
- ],
- ],
- ],
- ];
- }
+ $field = Field::createBasic('transactions/0/amount', 'random-amount');
+ $field->expectedReturn = function ($value) {
+ return number_format((float)$value, 12);
+ };
- return $set;
- }
+ $defaultSet->addField($field);
+ $defaultSet->addField(Field::createBasic('transactions/0/description', 'uuid'));
+ $defaultSet->addField(Field::createBasic('transactions/0/source_id', 'random-asset-id'));
+ $defaultSet->addField(Field::createBasic('transactions/0/destination_id', 'random-expense-id'));
- /**
- * @return \array[][]
- */
- private function optionalSets(): array
- {
- $faker = Factory::create();
- $set = [
- 'transactions_currency_id' => [
- 'fields' => [
- 'transactions' => [
- // first entry, set field:
- [
- 'currency_id' => $faker->numberBetween(1, 1),
- ],
- ],
- ],
- ],
- 'transactions_currency_code' => [
- 'fields' => [
- 'transactions' => [
- // first entry, set field:
- [
- 'currency_code' => $faker->randomElement(['EUR']),
- ],
- ],
- ],
- ],
- // category id
- 'category_id' => [
- 'fields' => [
- 'transactions' => [
- // first entry, set field:
- [
- 'category_id' => '1',
- ],
- ],
- ],
- ],
- // reconciled
- 'reconciled' => [
- 'fields' => [
- 'transactions' => [
- // first entry, set field:
- [
- 'reconciled' => $faker->boolean,
- ],
- ],
- ],
- ],
- // tags
- 'tags' => [
- 'fields' => [
- 'transactions' => [
- // first entry, set field:
- [
- 'tags' => ['a', 'b', 'c'],
- ],
- ],
- ],
- ],
- ];
- $extra = ['notes', 'internal_reference', 'bunq_payment_id', 'sepa_cc', 'sepa_ct_op', 'sepa_ct_id',
+ $configuration->addMandatoryFieldSet($defaultSet);
+
+ // optional fields
+ $fieldSet = new FieldSet;
+ $fieldSet->addField(Field::createBasic('transactions/0/category_id', 'random-category-id'));
+ $configuration->addOptionalFieldSet('category_id', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->addField(Field::createBasic('transactions/0/reconciled', 'boolean'));
+ $configuration->addOptionalFieldSet('reconciled', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->addField(Field::createBasic('transactions/0/tags', 'random-tags'));
+ $configuration->addOptionalFieldSet('tags', $fieldSet);
+
+
+ $array = ['notes', 'internal_reference', 'bunq_payment_id', 'sepa_cc', 'sepa_ct_op', 'sepa_ct_id',
'sepa_db', 'sepa_country', 'sepa_ep', 'sepa_ci', 'sepa_batch_id'];
- foreach ($extra as $key) {
- $set[$key] = [
- 'fields' => [
- 'transactions' => [
- // first entry, set field:
- [
- $key => $faker->uuid,
- ],
- ],
- ],
- ];
+
+ foreach ($array as $value) {
+ $fieldSet = new FieldSet;
+ $fieldSet->addField(Field::createBasic('transactions/0/' . $value, 'uuid'));
+ $configuration->addOptionalFieldSet($value, $fieldSet);
}
- return $set;
+ return $configuration->generateAll();
}
+
/**
* @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.transactions.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.transactions.store');
+ $this->assertPOST($address, $submission);
+
}
}
\ No newline at end of file
diff --git a/tests/Api/Models/Transaction/UpdateControllerTest.php b/tests/Api/Models/Transaction/UpdateControllerTest.php
new file mode 100644
index 0000000000..58269ee762
--- /dev/null
+++ b/tests/Api/Models/Transaction/UpdateControllerTest.php
@@ -0,0 +1,184 @@
+.
+ */
+
+namespace Tests\Api\Models\Transaction;
+
+
+use Carbon\Carbon;
+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;
+
+/**
+ * Class UpdateControllerTest
+ */
+class UpdateControllerTest extends TestCase
+{
+ use TestHelpers, CollectsValues;
+
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Passport::actingAs($this->user());
+ Log::info(sprintf('Now in %s.', get_class($this)));
+ }
+
+
+ /**
+ * @dataProvider updateDataProvider
+ *
+ * @param array $submission
+ */
+ public function testUpdate(array $submission): void
+ {
+ 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.transactions.update', $submission['parameters']);
+ $this->assertPUT($route, $submission);
+ }
+
+
+ /**
+ * @return array
+ */
+ public function updateDataProvider(): array
+ {
+ $configuration = new TestConfiguration;
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('apply_rules', 'boolean'));
+ $configuration->addOptionalFieldSet('apply_rules', $fieldSet);
+
+ // add date
+ $fieldSet = new FieldSet();
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('transactions/0/date', 'random-past-date');
+ $field->expectedReturn = function ($value) {
+ $date = new Carbon($value, 'Europe/Amsterdam');
+
+ return $date->toIso8601String();
+ };
+ $fieldSet->addField($field);
+
+ $configuration->addOptionalFieldSet('date', $fieldSet);
+
+ // category
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('transactions/0/category_id', 'random-category-id'));
+ $configuration->addOptionalFieldSet('category_id', $fieldSet);
+
+ // amount
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('transactions/0/amount', 'random-amount');
+ $field->expectedReturn = function ($value) {
+ return number_format((float)$value, 12);
+ };
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('amount', $fieldSet);
+
+ // descr
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('transactions/0/description', 'uuid'));
+ $configuration->addOptionalFieldSet('descr', $fieldSet);
+
+ // source
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('transactions/0/source_id', 'random-asset-id');
+ $field->ignorableFields = ['transactions/0/source_name', 'transactions/0/source_iban'];
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('src', $fieldSet);
+
+ // dest
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('transactions/0/destination_id', 'random-expense-id');
+ $field->ignorableFields = ['transactions/0/destination_name', 'transactions/0/destination_iban'];
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('dest', $fieldSet);
+
+
+ // optional fields
+ $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_id', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('transactions/0/reconciled', 'boolean'));
+ $configuration->addOptionalFieldSet('reconciled', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $field = Field::createBasic('transactions/0/tags', 'random-tags');
+ $field->expectedReturn = function ($value) {
+ if (is_array($value)) {
+ asort($value);
+
+ return array_values($value);
+ }
+
+ return $value;
+ };
+ $fieldSet->addField($field);
+ $configuration->addOptionalFieldSet('tags', $fieldSet);
+
+
+ $array = ['notes', 'internal_reference', 'bunq_payment_id', 'sepa_cc', 'sepa_ct_op', 'sepa_ct_id',
+ 'sepa_db', 'sepa_country', 'sepa_ep', 'sepa_ci', 'sepa_batch_id'];
+
+ foreach ($array as $value) {
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('transactions/0/' . $value, 'uuid'));
+ $configuration->addOptionalFieldSet($value, $fieldSet);
+ }
+
+
+ $result = $configuration->generateAll();
+
+ return $result;
+ }
+
+
+}
\ No newline at end of file
diff --git a/tests/Objects/TestConfiguration.php b/tests/Objects/TestConfiguration.php
index 66e6997dad..f488f420ac 100644
--- a/tests/Objects/TestConfiguration.php
+++ b/tests/Objects/TestConfiguration.php
@@ -50,33 +50,40 @@ class TestConfiguration
{
$this->debugMsg('Now in generateAll()');
// generate submissions
- $array = $this->generateSubmissions();
- //$expected = $this->generateExpected($array);
+ $array = $this->generateSubmissions();
$parameters = $this->parameters;
$ignored = $this->ignores;
$expected = $this->expected;
+ $this->debugMsg(sprintf('Now validating %d ignored() values.', count($ignored)));
+
// update ignored parameters:
$newIgnored = [];
foreach ($ignored as $index => $currentIgnored) {
+ $this->debugMsg(sprintf(' Value #%d is %s', $index, json_encode($currentIgnored)));
$updated = [];
foreach ($currentIgnored as $key => $value) {
- $key = (int)$key;
- $positions = explode('/', $value);
- $count = count($positions);
- if (1 === $count) {
- $updated[$key] = $value;
- continue;
+ if (!is_array($value)) {
+ $positions = explode('/', $value);
+ $count = count($positions);
+ if (1 === $count) {
+ $updated[$key] = $updated[$key] ? $updated[$key] : $value;
+ continue;
+ }
+ if (3 === $count) {
+ $root = $positions[0];
+ $count = (int)$positions[1];
+ $final = $positions[2];
+ $updated[$root][$count][] = $final;
+ continue;
+ }
}
- if (3 === $count) {
- $root = $positions[0];
- $count = (int)$positions[1];
- $final = $positions[2];
- $updated[$root][$count][] = $final;
- continue;
+ if (is_array($value)) {
+ $updated[$key] = $value;
}
}
$newIgnored[$index] = $updated;
+ $this->debugMsg(sprintf(' Updated value #%d is %s', $index, json_encode($updated)));
}
// now create a combination for each submission and associated data:
@@ -188,15 +195,38 @@ class TestConfiguration
// loop each field in this custom set and add them, nothing more.
/** @var Field $field */
foreach ($customSet->fields as $field) {
- $this->debugMsg(sprintf(' added field %s from custom set %s', $field->fieldTitle, $combination));
+ $this->debugMsg(sprintf(' added field "%s" from custom set "%s"', $field->fieldTitle, $combination));
$custom = $this->parseField($custom, $field);
$expected = $this->parseExpected($expected, $field, $custom);
// for each field, add the ignores to the current index (+1!) of
// ignores.
$count = count($this->submission);
if (null !== $field->ignorableFields && count($field->ignorableFields) > 0) {
- $currentIgnoreSet = $this->ignores[$count] ?? [];
- $this->ignores[$count] = array_values(array_unique(array_values(array_merge($currentIgnoreSet, $field->ignorableFields))));
+ $this->debugMsg(sprintf(' This field also has ignore things! %s', json_encode($field->ignorableFields)));
+ $currentIgnoreSet = $this->ignores[$count] ?? [];
+ $newIgnoreSet = [];
+ foreach ($field->ignorableFields as $ignorableField) {
+ $positions = explode('/', $ignorableField);
+ $posCount = count($positions);
+
+ if (1 === $posCount) {
+ $newIgnoreSet[] = $ignorableField;
+ }
+ if (3 === $posCount) {
+ $root = $positions[0];
+ $index = (int)$positions[1];
+ $final = $positions[2];
+ $newIgnoreSet[$root] = array_key_exists($root, $newIgnoreSet) ? $newIgnoreSet[$root] : [];
+ $newIgnoreSet[$root][$index] = array_key_exists($index, $newIgnoreSet[$root]) ? $newIgnoreSet[$root][$index] : [];
+ $newIgnoreSet[$root][$index][] = $final;
+ }
+ }
+ $this->debugMsg(sprintf(' %s + %s', json_encode($currentIgnoreSet), json_encode($newIgnoreSet)));
+ $mergedArray = $this->mergeIgnoreArray($currentIgnoreSet, $newIgnoreSet);
+ //$this->ignores[$count] = $currentIgnoreSet + $newIgnoreSet;
+ $this->ignores[$count] = $mergedArray;//array_merge_recursive($currentIgnoreSet, $newIgnoreSet);
+
+ $this->debugMsg(sprintf(' New set of ignore things (%d) is: %s', $count, json_encode($this->ignores[$count])));
}
$this->expected[$count] = $expected;
}
@@ -205,7 +235,7 @@ class TestConfiguration
}
$count = count($this->submission);
$this->submission[] = $custom;
- $this->debugMsg(sprintf(' Created set #%d', $totalCount));
+ $this->debugMsg(sprintf(' Created set #%d on index %d', $totalCount, $count));
$this->debugMsg(sprintf(' Will submit: %s', json_encode($custom)));
$this->debugMsg(sprintf(' Will ignore: %s', json_encode($this->ignores[$count] ?? [])));
$this->debugMsg(sprintf(' Will expect: %s', json_encode($this->expected[$count] ?? [])));
@@ -218,6 +248,69 @@ class TestConfiguration
return $this->submission;
}
+ /**
+ * @param $left
+ * @param $right
+ *
+ * @return array
+ */
+ private function mergeIgnoreArray($left, $right): array
+ {
+ // if both empty just return empty:
+ if (0 === count($left) && 0 === count($right)) {
+ $this->debugMsg('Return empty array');
+
+ return [];
+ }
+ // if left is empty return right
+ if (0 === count($left)) {
+ $this->debugMsg('Return right');
+
+ return $right;
+ }
+ // if right is empty return left
+ if (0 === count($right)) {
+ $this->debugMsg('Return left');
+
+ return $left;
+ }
+ $this->debugMsg('Loop right');
+ $result = [];
+ foreach ($right as $key => $value) {
+ $this->debugMsg(sprintf('Now at right key %s with value %s', json_encode($key), json_encode($value)));
+ if (is_array($value) && array_key_exists($key, $left)) {
+ $this->debugMsg(sprintf('Key %s exists in both, go one level deeper.', $key));
+ $result[$key] = $this->mergeIgnoreArray($right[$key], $left[$key]);
+ continue;
+ }
+ if (is_array($value) && !array_key_exists($key, $left)) {
+ $this->debugMsg(sprintf('Key %s exists in right only, keep it as it is.', $key));
+ $result[$key] = $right[$key];
+ }
+ // value is not an array, can be appended to result (ignore the key):
+ $this->debugMsg(sprintf('Key %s is a string (%s), just append it and return it later.', $key, $value));
+ $result[] = $value;
+ }
+ // loop left:
+ $this->debugMsg('Loop left');
+ foreach ($left as $key => $value) {
+ $this->debugMsg(sprintf('Now at left key %s with value %s', json_encode($key), json_encode($value)));
+ if (is_array($value) && array_key_exists($key, $right)) {
+ $this->debugMsg(sprintf('Key %s exists in both, go one level deeper.', $key));
+ $result[$key] = $this->mergeIgnoreArray($left[$key], $right[$key]);
+ continue;
+ }
+ if (is_array($value) && !array_key_exists($key, $right)) {
+ $result[$key] = $left[$key];
+ }
+ // value is not an array, can be appended to result (ignore the key):
+ $result[] = $value;
+ }
+
+ //
+ return $result;
+ }
+
/**
* @param FieldSet $set
*
@@ -359,11 +452,13 @@ class TestConfiguration
return $faker->numberBetween(0, 4);
case 'random-budget-id':
case 'random-category-id':
+ case 'random-rule-group-id':
case 'random-piggy-id':
+ case 'low-order':
case 'random-og-id':
return $faker->numberBetween(1, 2);
case 'random-tags':
- return $faker->randomElements(['a', 'b', 'c', 'd', 'ef', 'gh'], 3);
+ return $faker->randomElements(['a', 'b', 'c', 'd', 'ef', 'gh', 'sasas', '38sksl'], 5);
case 'random-auto-type':
return $faker->randomElement(['rollover', 'reset']);
case 'random-auto-period':
@@ -402,6 +497,14 @@ class TestConfiguration
return $faker->randomElement([8, 11, 12]);
case 'random-revenue-id':
return $faker->randomElement([9, 10]);
+ case 'random-trigger':
+ return $faker->randomElement(['store-journal', 'update-journal']);
+ case 'random-trigger-type':
+ return $faker->randomElement(['from_account_starts', 'from_account_is', 'description_ends', 'description_is']);
+ case 'random-action-type':
+ return $faker->randomElement(['set_category', 'add_tag', 'set_description']);
+ case 'random-rule-group-title':
+ return $faker->randomElement(['Rule group 1', 'Rule group 2']);
}
}
@@ -414,6 +517,7 @@ class TestConfiguration
*/
private function parseExpected(array $expected, Field $field, array $result): array
{
+ $this->debugMsg(sprintf(' Now parsing expected return values for field %s', $field->fieldTitle));
// fieldTitle indicates the position:
$positions = explode('/', $field->fieldTitle);
$count = count($positions);
@@ -438,12 +542,19 @@ class TestConfiguration
$expected[$root] = array_key_exists($root, $expected) ? $expected[$root] : [];
$expected[$root][$count] = array_key_exists($count, $expected[$root]) ? $expected[$root][$count] : [];
$expected[$root][$count][$final] = null;
+ $this->debugMsg(sprintf(' Field name is split, so will store the expected return in $expected[%s][%d][%s] = (here)', $root, $count, $final));
if (null === $field->expectedReturn) {
- $expected[$root][$count][$final] = $result[$root][$count][$final] ?? false;
+ $this->debugMsg(sprintf(' Expected return is NULL, so will use the result for this point: %s', json_encode($result)));
+ $expected[$root][$count][$final] = $result[$root][$count][$final];
}
if (null !== $field->expectedReturn) {
- $expected[$root][$count][$final] = ($field->expectedReturn)($result[$root][$count][$final] ?? false);
+ $this->debugMsg(sprintf(' Expected return is not NULL, so will use a callback for this point: %s', json_encode($result)));
+ $this->debugMsg(sprintf(' Root : %s', json_encode($result[$root])));
+ $this->debugMsg(sprintf(' Count : %s', json_encode($result[$root][$count])));
+ $this->debugMsg(sprintf(' Final : %s', json_encode($result[$root][$count][$final])));
+ $lastValue = $result[$root][$count][$final];
+ $expected[$root][$count][$final] = ($field->expectedReturn)($lastValue);
}
return $expected;
@@ -496,8 +607,9 @@ class TestConfiguration
* @param int $index
* @param array $customFields
*/
- function updateExpected(int $index, array $customFields): void
+ private function updateExpected(int $index, array $customFields): void
{
+ $this->debugMsg('Now parsing expected return values for this set.');
if (count($customFields) > 0) {
/** @var Field $field */
foreach ($customFields as $field) {
diff --git a/tests/Traits/TestHelpers.php b/tests/Traits/TestHelpers.php
index 61fb538749..a9bf64952e 100644
--- a/tests/Traits/TestHelpers.php
+++ b/tests/Traits/TestHelpers.php
@@ -31,6 +31,8 @@ use Illuminate\Support\Facades\Log;
*/
trait TestHelpers
{
+
+
/**
* @param string $route
* @param array $content
@@ -66,6 +68,10 @@ trait TestHelpers
private function comparePOSTArray(array $submission, array $response, array $expected, array $ignore): void
{
Log::debug('Now in comparePOSTArray()');
+ Log::debug(sprintf('Submission : %s', json_encode($submission)));
+ Log::debug(sprintf('Response : %s', json_encode($response)));
+ Log::debug(sprintf('Expected : %s', json_encode($expected)));
+ Log::debug(sprintf('Ignore : %s', json_encode($ignore)));
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])) {
@@ -105,6 +111,7 @@ trait TestHelpers
$submission = $content['submission'];
$ignore = $content['ignore'];
$expected = $content['expected'];
+ Log::debug('Now in assertPUT()');
// get the original first:
$original = $this->get($route, ['Accept' => 'application/json']);
@@ -136,9 +143,18 @@ trait TestHelpers
*/
private function comparePUTArray(string $url, array $submission, array $response, array $expected, array $ignore, array $original): void
{
+ Log::debug('Now in comparePUTArray()');
+ Log::debug(sprintf('Submission : %s', json_encode($submission)));
+ Log::debug(sprintf('Response : %s', json_encode($response)));
+ Log::debug(sprintf('Expected : %s', json_encode($expected)));
+ Log::debug(sprintf('Ignore : %s', json_encode($ignore)));
+ Log::debug(sprintf('Original : %s', json_encode($original)));
$extraIgnore = ['created_at', 'updated_at', 'id'];
foreach ($response as $key => $value) {
if (is_array($value) && array_key_exists($key, $submission) && is_array($submission[$key])) {
+ if (in_array($key, $ignore, true)) {
+ continue;
+ }
$this->comparePUTArray($url, $submission[$key], $value, $expected[$key], $ignore[$key] ?? [], $original[$key] ?? []);
continue;
}