mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-19 08:00:19 +00:00
Tests also validate existing data.
This commit is contained in:
@@ -22,12 +22,13 @@
|
||||
namespace Tests\Api\Models\PiggyBank;
|
||||
|
||||
|
||||
use Faker\Factory;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\Objects\Field;
|
||||
use Tests\Objects\FieldSet;
|
||||
use Tests\Objects\TestConfiguration;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\CollectsValues;
|
||||
|
||||
use Tests\Traits\TestHelpers;
|
||||
|
||||
/**
|
||||
@@ -53,13 +54,17 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate(array $submission): void
|
||||
{
|
||||
$ignore = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
$route = route('api.v1.piggy_banks.update', [$submission['id']]);
|
||||
if ([] === $submission) {
|
||||
$this->markTestSkipped('Empty provider.');
|
||||
}
|
||||
Log::debug('testStoreUpdated()');
|
||||
Log::debug('submission :', $submission['submission']);
|
||||
Log::debug('expected :', $submission['expected']);
|
||||
Log::debug('ignore :', $submission['ignore']);
|
||||
Log::debug('parameters :', $submission['parameters']);
|
||||
|
||||
$this->updateAndCompare($route, $submission, $ignore);
|
||||
$route = route('api.v1.piggy_banks.update', $submission['parameters']);
|
||||
$this->assertPUT($route, $submission);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,99 +73,76 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function updateDataProvider(): array
|
||||
{
|
||||
$submissions = [];
|
||||
$all = $this->updateDataSet();
|
||||
foreach ($all as $name => $data) {
|
||||
$submissions[] = [$data];
|
||||
}
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
return $submissions;
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('name', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('name', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('account_id', 'random-piggy-account');
|
||||
$field->ignorableFields = ['account_name'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('account_id', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('target_amount', 'random-amount-max');
|
||||
$field->ignorableFields = ['percentage', 'current_amount', 'left_to_save', 'save_per_month'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('target_amount', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('current_amount', 'random-amount-min');
|
||||
$field->ignorableFields = ['percentage', 'left_to_save','save_per_month'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('current_amount', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('start_date', 'random-past-date'));
|
||||
$configuration->addOptionalFieldSet('start_date', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = Field::createBasic('target_date', 'random-future-date');
|
||||
$field->ignorableFields = ['save_per_month'];
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('target_date', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('order', 'order'));
|
||||
$configuration->addOptionalFieldSet('order', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'object_group_id';
|
||||
$field->fieldType = 'random-og-id';
|
||||
$field->ignorableFields = ['object_group_title', 'object_group_order'];
|
||||
$field->title = 'object_group_id';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('object_group_id', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'object_group_title';
|
||||
$field->fieldType = 'uuid';
|
||||
$field->ignorableFields = ['object_group_id', 'object_group_order'];
|
||||
$field->title = 'object_group_id';
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('object_group_title', $fieldSet);
|
||||
|
||||
return $configuration->generateAll();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function updateDataSet(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$objectGroupId = $faker->numberBetween(1, 2);
|
||||
$objectGroupName = sprintf('Object group %d', $objectGroupId);
|
||||
$set = [
|
||||
'name' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'name' => ['test_value' => $faker->uuid],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'account_id' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'account_id' => ['test_value' => (string)$faker->numberBetween(1, 3)],
|
||||
],
|
||||
'extra_ignore' => ['account_name', 'currency_id', 'currency_code'],
|
||||
],
|
||||
'target_amount' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'target_amount' => ['test_value' => number_format($faker->randomFloat(2, 50, 100), 2)],
|
||||
],
|
||||
'extra_ignore' => ['percentage', 'current_amount', 'left_to_save'],
|
||||
],
|
||||
'current_amount' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'current_amount' => ['test_value' => number_format($faker->randomFloat(2, 5, 10), 2)],
|
||||
],
|
||||
'extra_ignore' => ['percentage', 'left_to_save'],
|
||||
],
|
||||
'start_date' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'start_date' => ['test_value' => $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d')],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'target_date' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'target_date' => ['test_value' => $faker->dateTimeBetween('+1 year', '+2 year')->format('Y-m-d')],
|
||||
],
|
||||
'extra_ignore' => ['save_per_month'],
|
||||
],
|
||||
'order' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'order' => ['test_value' => $faker->numberBetween(1, 5)],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'notes' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'notes' => ['test_value' => join(' ', $faker->words(5))],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'object_group_id' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'object_group_id' => ['test_value' => (string)$objectGroupId],
|
||||
],
|
||||
'extra_ignore' => ['object_group_order', 'object_group_title'],
|
||||
],
|
||||
'object_group_title' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'object_group_title' => ['test_value' => $objectGroupName],
|
||||
],
|
||||
'extra_ignore' => ['object_group_order', 'object_group_id'],
|
||||
],
|
||||
];
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user