mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 12:12:18 +00:00
Transaction tests work.
This commit is contained in:
@@ -329,6 +329,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
|||||||
::table('tag_transaction_journal')
|
::table('tag_transaction_journal')
|
||||||
->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id')
|
->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id')
|
||||||
->where('tag_transaction_journal.transaction_journal_id', $journalId)
|
->where('tag_transaction_journal.transaction_journal_id', $journalId)
|
||||||
|
->orderBy('tags.tag','ASC')
|
||||||
->get(['tags.tag']);
|
->get(['tags.tag']);
|
||||||
|
|
||||||
return $result->pluck('tag')->toArray();
|
return $result->pluck('tag')->toArray();
|
||||||
|
12
phpunit.xml
12
phpunit.xml
@@ -36,11 +36,23 @@
|
|||||||
</coverage>
|
</coverage>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="Api">
|
<testsuite name="Api">
|
||||||
|
<!--
|
||||||
|
|
||||||
<directory suffix="Test.php">./tests/Api/Models/Account</directory>
|
<directory suffix="Test.php">./tests/Api/Models/Account</directory>
|
||||||
<directory suffix="Test.php">./tests/Api/Models/Attachment</directory>
|
<directory suffix="Test.php">./tests/Api/Models/Attachment</directory>
|
||||||
<directory suffix="Test.php">./tests/Api/Models/AvailableBudget</directory>
|
<directory suffix="Test.php">./tests/Api/Models/AvailableBudget</directory>
|
||||||
<directory suffix="Test.php">./tests/Api/Models/Bill</directory>
|
<directory suffix="Test.php">./tests/Api/Models/Bill</directory>
|
||||||
<directory suffix="Test.php">./tests/Api/Models/Budget</directory>
|
<directory suffix="Test.php">./tests/Api/Models/Budget</directory>
|
||||||
|
<directory suffix="Test.php">./tests/Api/Models/BudgetLimit</directory>
|
||||||
|
<directory suffix="Test.php">./tests/Api/Models/Category</directory>
|
||||||
|
<directory suffix="Test.php">./tests/Api/Models/ObjectGroup</directory>
|
||||||
|
<directory suffix="Test.php">./tests/Api/Models/PiggyBank</directory>
|
||||||
|
<directory suffix="Test.php">./tests/Api/Models/Recurrence</directory>
|
||||||
|
<directory suffix="Test.php">./tests/Api/Models/Rule</directory>
|
||||||
|
<directory suffix="Test.php">./tests/Api/Models/RuleGroup</directory>
|
||||||
|
<directory suffix="Test.php">./tests/Api/Models/Tag</directory>
|
||||||
|
-->
|
||||||
|
<directory suffix="Test.php">./tests/Api/Models/Transaction</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<php>
|
<php>
|
||||||
|
@@ -187,164 +187,4 @@ class UpdateControllerTest extends TestCase
|
|||||||
|
|
||||||
return $configuration->generateAll();
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\Rule;
|
|||||||
use Faker\Factory;
|
use Faker\Factory;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Tests\Objects\Field;
|
||||||
|
use Tests\Objects\FieldSet;
|
||||||
|
use Tests\Objects\TestConfiguration;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CollectsValues;
|
use Tests\Traits\CollectsValues;
|
||||||
|
|
||||||
@@ -61,159 +64,65 @@ class StoreControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function storeDataProvider(): array
|
public function storeDataProvider(): array
|
||||||
{
|
{
|
||||||
$minimalSets = $this->minimalSets();
|
// some test configs:
|
||||||
$optionalSets = $this->optionalSets();
|
$configuration = new TestConfiguration;
|
||||||
$regenConfig = [
|
|
||||||
'title' => function () {
|
|
||||||
$faker = Factory::create();
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
/**
|
// add optional set
|
||||||
* @return array
|
$fieldSet = new FieldSet;
|
||||||
*/
|
$fieldSet->addField(Field::createBasic('order', 'low-order'));
|
||||||
private function minimalSets(): array
|
$configuration->addOptionalFieldSet('order', $fieldSet);
|
||||||
{
|
|
||||||
$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,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
// 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
|
* emptyDataProvider / storeDataProvider
|
||||||
*
|
*
|
||||||
* @dataProvider storeDataProvider
|
* @dataProvider emptyDataProvider
|
||||||
*/
|
*/
|
||||||
public function testStore(array $submission): void
|
public function testStore(array $submission): void
|
||||||
{
|
{
|
||||||
if ([] === $submission) {
|
if ([] === $submission) {
|
||||||
$this->markTestSkipped('Empty data provider');
|
$this->markTestSkipped('Empty provider.');
|
||||||
}
|
}
|
||||||
$route = 'api.v1.rules.store';
|
Log::debug('testStoreUpdated()');
|
||||||
$this->storeAndCompare($route, $submission);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
168
tests/Api/Models/Rule/UpdateControllerTest.php
Normal file
168
tests/Api/Models/Rule/UpdateControllerTest.php
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* UpdateControllerTEst.php
|
||||||
|
* Copyright (c) 2021 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\RuleGroup;
|
|||||||
use Faker\Factory;
|
use Faker\Factory;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Tests\Objects\Field;
|
||||||
|
use Tests\Objects\FieldSet;
|
||||||
|
use Tests\Objects\TestConfiguration;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CollectsValues;
|
use Tests\Traits\CollectsValues;
|
||||||
|
|
||||||
@@ -61,60 +64,33 @@ class StoreControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function storeDataProvider(): array
|
public function storeDataProvider(): array
|
||||||
{
|
{
|
||||||
$minimalSets = $this->minimalSets();
|
// some test configs:
|
||||||
$optionalSets = $this->optionalSets();
|
$configuration = new TestConfiguration;
|
||||||
$regenConfig = [
|
|
||||||
'title' => function () {
|
|
||||||
$faker = Factory::create();
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
/**
|
$fieldSet = new FieldSet;
|
||||||
* @return array
|
$field = Field::createBasic('order', 'low-order');
|
||||||
*/
|
$fieldSet->addField($field);
|
||||||
private function minimalSets(): array
|
$configuration->addOptionalFieldSet('order', $fieldSet);
|
||||||
{
|
|
||||||
$faker = Factory::create();
|
|
||||||
|
|
||||||
return [
|
$fieldSet = new FieldSet;
|
||||||
'default_group' => [
|
$field = Field::createBasic('active', 'boolean');
|
||||||
'parameters' => [],
|
$fieldSet->addField($field);
|
||||||
'fields' => [
|
$configuration->addOptionalFieldSet('active', $fieldSet);
|
||||||
'title' => $faker->uuid,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return $configuration->generateAll();
|
||||||
* @return \array[][]
|
|
||||||
*/
|
|
||||||
private function optionalSets(): array
|
|
||||||
{
|
|
||||||
$faker = Factory::create();
|
|
||||||
|
|
||||||
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
|
public function testStore(array $submission): void
|
||||||
{
|
{
|
||||||
if ([] === $submission) {
|
if ([] === $submission) {
|
||||||
$this->markTestSkipped('Empty data provider');
|
$this->markTestSkipped('Empty provider.');
|
||||||
}
|
}
|
||||||
$route = 'api.v1.rule_groups.store';
|
Log::debug('testStoreUpdated()');
|
||||||
$this->storeAndCompare($route, $submission);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\RuleGroup;
|
|||||||
use Faker\Factory;
|
use Faker\Factory;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Tests\Objects\Field;
|
||||||
|
use Tests\Objects\FieldSet;
|
||||||
|
use Tests\Objects\TestConfiguration;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CollectsValues;
|
use Tests\Traits\CollectsValues;
|
||||||
|
|
||||||
@@ -53,13 +56,17 @@ class UpdateControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdate(array $submission): void
|
public function testUpdate(array $submission): void
|
||||||
{
|
{
|
||||||
$ignore = [
|
if ([] === $submission) {
|
||||||
'created_at',
|
$this->markTestSkipped('Empty provider.');
|
||||||
'updated_at',
|
}
|
||||||
];
|
Log::debug('testStoreUpdated()');
|
||||||
$route = route('api.v1.rule_groups.update', [$submission['id']]);
|
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
|
public function updateDataProvider(): array
|
||||||
{
|
{
|
||||||
$submissions = [];
|
$configuration = new TestConfiguration;
|
||||||
$all = $this->updateDataSet();
|
|
||||||
foreach ($all as $name => $data) {
|
$fieldSet = new FieldSet;
|
||||||
$submissions[] = [$data];
|
$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 $submissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\Tag;
|
|||||||
use Faker\Factory;
|
use Faker\Factory;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Tests\Objects\Field;
|
||||||
|
use Tests\Objects\FieldSet;
|
||||||
|
use Tests\Objects\TestConfiguration;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CollectsValues;
|
use Tests\Traits\CollectsValues;
|
||||||
|
|
||||||
@@ -61,62 +64,33 @@ class StoreControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function storeDataProvider(): array
|
public function storeDataProvider(): array
|
||||||
{
|
{
|
||||||
$minimalSets = $this->minimalSets();
|
// some test configs:
|
||||||
$optionalSets = $this->optionalSets();
|
$configuration = new TestConfiguration;
|
||||||
$regenConfig = [
|
|
||||||
'tag' => function () {
|
|
||||||
$faker = Factory::create();
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
/**
|
$fieldSet = new FieldSet;
|
||||||
* @return array
|
$field = Field::createBasic('description', 'uuid');
|
||||||
*/
|
$fieldSet->addField($field);
|
||||||
private function minimalSets(): array
|
$configuration->addOptionalFieldSet('description', $fieldSet);
|
||||||
{
|
|
||||||
$faker = Factory::create();
|
|
||||||
|
|
||||||
return [
|
$fieldSet = new FieldSet;
|
||||||
'default_tag' => [
|
$fieldSet->addField(Field::createBasic('longitude', 'longitude'));
|
||||||
'parameters' => [],
|
$fieldSet->addField(Field::createBasic('latitude', 'latitude'));
|
||||||
'fields' => [
|
$fieldSet->addField(Field::createBasic('zoom_level', 'random-zoom_level'));
|
||||||
'tag' => $faker->uuid,
|
$configuration->addOptionalFieldSet('location', $fieldSet);
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return $configuration->generateAll();
|
||||||
* @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),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,10 +103,16 @@ class StoreControllerTest extends TestCase
|
|||||||
public function testStore(array $submission): void
|
public function testStore(array $submission): void
|
||||||
{
|
{
|
||||||
if ([] === $submission) {
|
if ([] === $submission) {
|
||||||
$this->markTestSkipped('Empty data provider');
|
$this->markTestSkipped('Empty provider.');
|
||||||
}
|
}
|
||||||
$route = 'api.v1.tags.store';
|
Log::debug('testStoreUpdated()');
|
||||||
$this->storeAndCompare($route, $submission);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\Tag;
|
|||||||
use Faker\Factory;
|
use Faker\Factory;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Tests\Objects\Field;
|
||||||
|
use Tests\Objects\FieldSet;
|
||||||
|
use Tests\Objects\TestConfiguration;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CollectsValues;
|
use Tests\Traits\CollectsValues;
|
||||||
|
|
||||||
@@ -53,13 +56,17 @@ class UpdateControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdate(array $submission): void
|
public function testUpdate(array $submission): void
|
||||||
{
|
{
|
||||||
$ignore = [
|
if ([] === $submission) {
|
||||||
'created_at',
|
$this->markTestSkipped('Empty provider.');
|
||||||
'updated_at',
|
}
|
||||||
];
|
Log::debug('testStoreUpdated()');
|
||||||
$route = route('api.v1.tags.update', [$submission['id']]);
|
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
|
public function updateDataProvider(): array
|
||||||
{
|
{
|
||||||
$submissions = [];
|
$configuration = new TestConfiguration;
|
||||||
$all = $this->updateDataSet();
|
|
||||||
foreach ($all as $name => $data) {
|
$fieldSet = new FieldSet;
|
||||||
$submissions[] = [$data];
|
$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 $submissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@@ -22,13 +22,14 @@
|
|||||||
namespace Tests\Api\Models\Transaction;
|
namespace Tests\Api\Models\Transaction;
|
||||||
|
|
||||||
|
|
||||||
use DateTimeInterface;
|
use Carbon\Carbon;
|
||||||
use Faker\Factory;
|
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Tests\Objects\Field;
|
||||||
|
use Tests\Objects\FieldSet;
|
||||||
|
use Tests\Objects\TestConfiguration;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CollectsValues;
|
use Tests\Traits\CollectsValues;
|
||||||
|
|
||||||
use Tests\Traits\TestHelpers;
|
use Tests\Traits\TestHelpers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,152 +63,82 @@ class StoreControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function storeDataProvider(): array
|
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 $date->toIso8601String();
|
||||||
* @return array
|
};
|
||||||
*/
|
$defaultSet->addField($field);
|
||||||
private function minimalSets(): array
|
|
||||||
{
|
|
||||||
$faker = Factory::create();
|
|
||||||
|
|
||||||
// 3 sets:
|
$field = Field::createBasic('transactions/0/amount', 'random-amount');
|
||||||
$combis = [
|
$field->expectedReturn = function ($value) {
|
||||||
['withdrawal', 1, 8],
|
return number_format((float)$value, 12);
|
||||||
['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],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
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'));
|
||||||
|
|
||||||
/**
|
$configuration->addMandatoryFieldSet($defaultSet);
|
||||||
* @return \array[][]
|
|
||||||
*/
|
// optional fields
|
||||||
private function optionalSets(): array
|
$fieldSet = new FieldSet;
|
||||||
{
|
$fieldSet->addField(Field::createBasic('transactions/0/category_id', 'random-category-id'));
|
||||||
$faker = Factory::create();
|
$configuration->addOptionalFieldSet('category_id', $fieldSet);
|
||||||
$set = [
|
|
||||||
'transactions_currency_id' => [
|
$fieldSet = new FieldSet;
|
||||||
'fields' => [
|
$fieldSet->addField(Field::createBasic('transactions/0/reconciled', 'boolean'));
|
||||||
'transactions' => [
|
$configuration->addOptionalFieldSet('reconciled', $fieldSet);
|
||||||
// first entry, set field:
|
|
||||||
[
|
$fieldSet = new FieldSet;
|
||||||
'currency_id' => $faker->numberBetween(1, 1),
|
$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',
|
||||||
'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',
|
|
||||||
'sepa_db', 'sepa_country', 'sepa_ep', 'sepa_ci', 'sepa_batch_id'];
|
'sepa_db', 'sepa_country', 'sepa_ep', 'sepa_ci', 'sepa_batch_id'];
|
||||||
foreach ($extra as $key) {
|
|
||||||
$set[$key] = [
|
foreach ($array as $value) {
|
||||||
'fields' => [
|
$fieldSet = new FieldSet;
|
||||||
'transactions' => [
|
$fieldSet->addField(Field::createBasic('transactions/0/' . $value, 'uuid'));
|
||||||
// first entry, set field:
|
$configuration->addOptionalFieldSet($value, $fieldSet);
|
||||||
[
|
|
||||||
$key => $faker->uuid,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $set;
|
return $configuration->generateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $submission
|
* @param array $submission
|
||||||
*
|
*
|
||||||
* emptyDataProvider / storeDataProvider
|
* emptyDataProvider / storeDataProvider
|
||||||
*
|
*
|
||||||
* @dataProvider storeDataProvider
|
* @dataProvider emptyDataProvider
|
||||||
*/
|
*/
|
||||||
public function testStore(array $submission): void
|
public function testStore(array $submission): void
|
||||||
{
|
{
|
||||||
if ([] === $submission) {
|
if ([] === $submission) {
|
||||||
$this->markTestSkipped('Empty data provider');
|
$this->markTestSkipped('Empty provider.');
|
||||||
}
|
}
|
||||||
$route = 'api.v1.transactions.store';
|
Log::debug('testStoreUpdated()');
|
||||||
$this->storeAndCompare($route, $submission);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
184
tests/Api/Models/Transaction/UpdateControllerTest.php
Normal file
184
tests/Api/Models/Transaction/UpdateControllerTest.php
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* UpdateControllerTest.php
|
||||||
|
* Copyright (c) 2021 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -51,21 +51,23 @@ class TestConfiguration
|
|||||||
$this->debugMsg('Now in generateAll()');
|
$this->debugMsg('Now in generateAll()');
|
||||||
// generate submissions
|
// generate submissions
|
||||||
$array = $this->generateSubmissions();
|
$array = $this->generateSubmissions();
|
||||||
//$expected = $this->generateExpected($array);
|
|
||||||
$parameters = $this->parameters;
|
$parameters = $this->parameters;
|
||||||
$ignored = $this->ignores;
|
$ignored = $this->ignores;
|
||||||
$expected = $this->expected;
|
$expected = $this->expected;
|
||||||
|
|
||||||
|
$this->debugMsg(sprintf('Now validating %d ignored() values.', count($ignored)));
|
||||||
|
|
||||||
// update ignored parameters:
|
// update ignored parameters:
|
||||||
$newIgnored = [];
|
$newIgnored = [];
|
||||||
foreach ($ignored as $index => $currentIgnored) {
|
foreach ($ignored as $index => $currentIgnored) {
|
||||||
|
$this->debugMsg(sprintf(' Value #%d is %s', $index, json_encode($currentIgnored)));
|
||||||
$updated = [];
|
$updated = [];
|
||||||
foreach ($currentIgnored as $key => $value) {
|
foreach ($currentIgnored as $key => $value) {
|
||||||
$key = (int)$key;
|
if (!is_array($value)) {
|
||||||
$positions = explode('/', $value);
|
$positions = explode('/', $value);
|
||||||
$count = count($positions);
|
$count = count($positions);
|
||||||
if (1 === $count) {
|
if (1 === $count) {
|
||||||
$updated[$key] = $value;
|
$updated[$key] = $updated[$key] ? $updated[$key] : $value;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (3 === $count) {
|
if (3 === $count) {
|
||||||
@@ -76,7 +78,12 @@ class TestConfiguration
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (is_array($value)) {
|
||||||
|
$updated[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
$newIgnored[$index] = $updated;
|
$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:
|
// 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.
|
// loop each field in this custom set and add them, nothing more.
|
||||||
/** @var Field $field */
|
/** @var Field $field */
|
||||||
foreach ($customSet->fields as $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);
|
$custom = $this->parseField($custom, $field);
|
||||||
$expected = $this->parseExpected($expected, $field, $custom);
|
$expected = $this->parseExpected($expected, $field, $custom);
|
||||||
// for each field, add the ignores to the current index (+1!) of
|
// for each field, add the ignores to the current index (+1!) of
|
||||||
// ignores.
|
// ignores.
|
||||||
$count = count($this->submission);
|
$count = count($this->submission);
|
||||||
if (null !== $field->ignorableFields && count($field->ignorableFields) > 0) {
|
if (null !== $field->ignorableFields && count($field->ignorableFields) > 0) {
|
||||||
|
$this->debugMsg(sprintf(' This field also has ignore things! %s', json_encode($field->ignorableFields)));
|
||||||
$currentIgnoreSet = $this->ignores[$count] ?? [];
|
$currentIgnoreSet = $this->ignores[$count] ?? [];
|
||||||
$this->ignores[$count] = array_values(array_unique(array_values(array_merge($currentIgnoreSet, $field->ignorableFields))));
|
$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;
|
$this->expected[$count] = $expected;
|
||||||
}
|
}
|
||||||
@@ -205,7 +235,7 @@ class TestConfiguration
|
|||||||
}
|
}
|
||||||
$count = count($this->submission);
|
$count = count($this->submission);
|
||||||
$this->submission[] = $custom;
|
$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 submit: %s', json_encode($custom)));
|
||||||
$this->debugMsg(sprintf(' Will ignore: %s', json_encode($this->ignores[$count] ?? [])));
|
$this->debugMsg(sprintf(' Will ignore: %s', json_encode($this->ignores[$count] ?? [])));
|
||||||
$this->debugMsg(sprintf(' Will expect: %s', json_encode($this->expected[$count] ?? [])));
|
$this->debugMsg(sprintf(' Will expect: %s', json_encode($this->expected[$count] ?? [])));
|
||||||
@@ -218,6 +248,69 @@ class TestConfiguration
|
|||||||
return $this->submission;
|
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
|
* @param FieldSet $set
|
||||||
*
|
*
|
||||||
@@ -359,11 +452,13 @@ class TestConfiguration
|
|||||||
return $faker->numberBetween(0, 4);
|
return $faker->numberBetween(0, 4);
|
||||||
case 'random-budget-id':
|
case 'random-budget-id':
|
||||||
case 'random-category-id':
|
case 'random-category-id':
|
||||||
|
case 'random-rule-group-id':
|
||||||
case 'random-piggy-id':
|
case 'random-piggy-id':
|
||||||
|
case 'low-order':
|
||||||
case 'random-og-id':
|
case 'random-og-id':
|
||||||
return $faker->numberBetween(1, 2);
|
return $faker->numberBetween(1, 2);
|
||||||
case 'random-tags':
|
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':
|
case 'random-auto-type':
|
||||||
return $faker->randomElement(['rollover', 'reset']);
|
return $faker->randomElement(['rollover', 'reset']);
|
||||||
case 'random-auto-period':
|
case 'random-auto-period':
|
||||||
@@ -402,6 +497,14 @@ class TestConfiguration
|
|||||||
return $faker->randomElement([8, 11, 12]);
|
return $faker->randomElement([8, 11, 12]);
|
||||||
case 'random-revenue-id':
|
case 'random-revenue-id':
|
||||||
return $faker->randomElement([9, 10]);
|
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
|
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:
|
// fieldTitle indicates the position:
|
||||||
$positions = explode('/', $field->fieldTitle);
|
$positions = explode('/', $field->fieldTitle);
|
||||||
$count = count($positions);
|
$count = count($positions);
|
||||||
@@ -438,12 +542,19 @@ class TestConfiguration
|
|||||||
$expected[$root] = array_key_exists($root, $expected) ? $expected[$root] : [];
|
$expected[$root] = array_key_exists($root, $expected) ? $expected[$root] : [];
|
||||||
$expected[$root][$count] = array_key_exists($count, $expected[$root]) ? $expected[$root][$count] : [];
|
$expected[$root][$count] = array_key_exists($count, $expected[$root]) ? $expected[$root][$count] : [];
|
||||||
$expected[$root][$count][$final] = null;
|
$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) {
|
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) {
|
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;
|
return $expected;
|
||||||
@@ -496,8 +607,9 @@ class TestConfiguration
|
|||||||
* @param int $index
|
* @param int $index
|
||||||
* @param array $customFields
|
* @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) {
|
if (count($customFields) > 0) {
|
||||||
/** @var Field $field */
|
/** @var Field $field */
|
||||||
foreach ($customFields as $field) {
|
foreach ($customFields as $field) {
|
||||||
|
@@ -31,6 +31,8 @@ use Illuminate\Support\Facades\Log;
|
|||||||
*/
|
*/
|
||||||
trait TestHelpers
|
trait TestHelpers
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $route
|
* @param string $route
|
||||||
* @param array $content
|
* @param array $content
|
||||||
@@ -66,6 +68,10 @@ trait TestHelpers
|
|||||||
private function comparePOSTArray(array $submission, array $response, array $expected, array $ignore): void
|
private function comparePOSTArray(array $submission, array $response, array $expected, array $ignore): void
|
||||||
{
|
{
|
||||||
Log::debug('Now in comparePOSTArray()');
|
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) {
|
foreach ($response as $key => $value) {
|
||||||
Log::debug(sprintf('Now working on (sub)response key ["%s"]', $key));
|
Log::debug(sprintf('Now working on (sub)response key ["%s"]', $key));
|
||||||
if (is_array($value) && array_key_exists($key, $expected) && is_array($expected[$key])) {
|
if (is_array($value) && array_key_exists($key, $expected) && is_array($expected[$key])) {
|
||||||
@@ -105,6 +111,7 @@ trait TestHelpers
|
|||||||
$submission = $content['submission'];
|
$submission = $content['submission'];
|
||||||
$ignore = $content['ignore'];
|
$ignore = $content['ignore'];
|
||||||
$expected = $content['expected'];
|
$expected = $content['expected'];
|
||||||
|
Log::debug('Now in assertPUT()');
|
||||||
|
|
||||||
// get the original first:
|
// get the original first:
|
||||||
$original = $this->get($route, ['Accept' => 'application/json']);
|
$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
|
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'];
|
$extraIgnore = ['created_at', 'updated_at', 'id'];
|
||||||
foreach ($response as $key => $value) {
|
foreach ($response as $key => $value) {
|
||||||
if (is_array($value) && array_key_exists($key, $submission) && is_array($submission[$key])) {
|
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] ?? []);
|
$this->comparePUTArray($url, $submission[$key], $value, $expected[$key], $ignore[$key] ?? [], $original[$key] ?? []);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user