diff --git a/tests/Api/Models/Account/StoreControllerTest.php b/tests/Api/Models/Account/StoreControllerTest.php index 63b3ede760..31fd59fcf4 100644 --- a/tests/Api/Models/Account/StoreControllerTest.php +++ b/tests/Api/Models/Account/StoreControllerTest.php @@ -25,6 +25,9 @@ namespace Tests\Api\Models\Account; use Faker\Factory; use Laravel\Passport\Passport; use Log; +use Tests\Objects\TestConfiguration; +use Tests\Objects\TestMandatoryField; +use Tests\Objects\TestMandatoryFieldSet; use Tests\TestCase; use Tests\Traits\CollectsValues; use Tests\Traits\RandomValues; @@ -55,6 +58,8 @@ class StoreControllerTest extends TestCase */ public function testStore(array $submission): void { + $this->someTestData(); + exit; if ([] === $submission) { $this->markTestSkipped('Empty data provider'); } @@ -235,7 +240,67 @@ class StoreControllerTest extends TestCase public function someTestData(): void { - $set = [ + // a basic test config set contains + // mandatory fields and X optional fields + // the optional fields will be rotated automatically. + $config = new TestConfiguration; + + // add a set of mandatory fields: + $mandatoryFieldSet = new TestMandatoryFieldSet(); + $mandatoryFieldSet->title = 'default_asset_account'; + + // name + $mandatoryField = new TestMandatoryField; + $mandatoryField->title = 'name'; + $mandatoryField->fieldTitle = 'name'; + $mandatoryField->fieldPosition = ''; // root + $mandatoryField->fieldType = 'uuid'; // refers to a generator or something? + $mandatoryField->expectedReturnType = 'equal'; // or 'callback' + $mandatoryField->expectedReturn = null; // or the callback + $mandatoryField->ignorableFields = []; + $mandatoryFieldSet->addMandatoryField($mandatoryField); + + // type + $mandatoryField = new TestMandatoryField; + $mandatoryField->title = 'type'; + $mandatoryField->fieldTitle = 'type'; + $mandatoryField->fieldPosition = ''; // root + $mandatoryField->fieldType = 'static-asset'; // refers to a generator or something? + $mandatoryField->expectedReturnType = 'equal'; // or 'callback' + $mandatoryField->expectedReturn = null; // or the callback + $mandatoryField->ignorableFields = []; // something like transactions/0/currency_code + $mandatoryFieldSet->addMandatoryField($mandatoryField); + + // role + $mandatoryField = new TestMandatoryField; + $mandatoryField->title = 'role'; + $mandatoryField->fieldTitle = 'account_role'; + $mandatoryField->fieldPosition = ''; // root + $mandatoryField->fieldType = 'random-asset-accountRole'; // refers to a generator or something? + $mandatoryField->expectedReturnType = 'equal'; // or 'callback' + $mandatoryField->expectedReturn = null; // or the callback + $mandatoryField->ignorableFields = []; // something like transactions/0/currency_code + $mandatoryFieldSet->addMandatoryField($mandatoryField); + +// $mandatoryField = new TestMandatoryField; +// $mandatoryField->title = 'transaction_type'; +// $mandatoryField->fieldTitle = 'type'; +// $mandatoryField->fieldPosition = 'transactions/0'; // not root! +// $mandatoryField->fieldType = 'random-transactionType'; // refers to a generator or something? +// $mandatoryField->expectedReturnType = 'equal'; // or 'callback' +// $mandatoryField->expectedReturn = null; // or the callback +// $mandatoryField->ignorableFields = []; +// $mandatoryFieldSet->addMandatoryField($mandatoryField); + + $config->mandatoryFieldSet = $mandatoryFieldSet; + + // generate submissions + $arr = $config->generateSubmission(); + var_dump($arr); + exit; + // generate expected returns. + + $set = [ // set for withdrawal, copy this for // other transaction types etc. // make a CLASS!! diff --git a/tests/Objects/IgnorableField.php b/tests/Objects/IgnorableField.php new file mode 100644 index 0000000000..0e42a79ed2 --- /dev/null +++ b/tests/Objects/IgnorableField.php @@ -0,0 +1,12 @@ +submission = []; + } + + public function generateSubmission(): array + { + $this->submission = []; + /** @var TestMandatoryField $field */ + foreach ($this->mandatoryFieldSet->mandatoryFields as $field) { + $this->parseField($field); + } + + return $this->submission; + } + + private function parseField(TestMandatoryField $field) + { + if ('' === $field->fieldPosition) { + $this->submission[$field->fieldTitle] = $this->generateFieldValue($field->fieldType); + } + if ('' !== $field->fieldPosition) { + $positions = explode('/', $field->fieldPosition); + // since the "positions" array is almost 2 indexes deep at best, we can do some manual fiddling. + $root = $positions[0]; + $count = (int)$positions[1]; + $this->submission[$root] = array_key_exists($root, $this->submission) ? $this->submission[$root] : []; + $this->submission[$root][$count] = array_key_exists($count, $this->submission[$root]) ? $this->submission[$root][$count] : []; + $this->submission[$root][$count][$field->fieldTitle] = $this->generateFieldValue($field->fieldType); + } + } + + /** + * @param string $type + * + * @return mixed|string + */ + private function generateFieldValue(string $type) + { + $faker = Factory::create(); + switch ($type) { + default: + throw new RuntimeException(sprintf('Cannot handle field "%s"', $type)); + case 'uuid': + return $faker->uuid; + case 'static-asset': + return 'asset'; + case 'random-asset-accountRole': + return $faker->randomElement(['defaultAsset', 'savingsAsset']); + case 'random-transactionType': + return $faker->randomElement(['withdrawal', 'deposit', 'transfer']); + } + } + +} \ No newline at end of file diff --git a/tests/Objects/TestMandatoryField.php b/tests/Objects/TestMandatoryField.php new file mode 100644 index 0000000000..006c5e2b87 --- /dev/null +++ b/tests/Objects/TestMandatoryField.php @@ -0,0 +1,20 @@ +mandatoryFields = []; + } + + /** + * @param TestMandatoryField $field + */ + public function addMandatoryField(TestMandatoryField $field) + { + $this->mandatoryFields[] = $field; + } + +} \ No newline at end of file diff --git a/tests/Objects/TestObject.php b/tests/Objects/TestObject.php new file mode 100644 index 0000000000..3d38479aa2 --- /dev/null +++ b/tests/Objects/TestObject.php @@ -0,0 +1,16 @@ +