mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Transaction tests work.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
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 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);
|
||||
}
|
||||
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user