mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 00:27:30 +00:00
Update meta data for new release.
This commit is contained in:
@@ -109,7 +109,7 @@ class StoreControllerTest extends TestCase
|
||||
['weekly', (string)$faker->numberBetween(1, 7)],
|
||||
['ndom', (string)$faker->numberBetween(1, 4) . ',' . $faker->numberBetween(1, 7)],
|
||||
['monthly', (string)$faker->numberBetween(1, 31)],
|
||||
['yearly', $faker->date()],
|
||||
['yearly', $faker->dateTimeBetween('-1 year','now')->format('Y-m-d')],
|
||||
];
|
||||
$set = [];
|
||||
|
||||
|
244
tests/Api/Models/Recurrence/UpdateControllerTest.php
Normal file
244
tests/Api/Models/Recurrence/UpdateControllerTest.php
Normal file
@@ -0,0 +1,244 @@
|
||||
<?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\Recurrence;
|
||||
|
||||
|
||||
use Faker\Factory;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\CollectsValues;
|
||||
use Tests\Traits\RandomValues;
|
||||
use Tests\Traits\TestHelpers;
|
||||
|
||||
/**
|
||||
* Class UpdateControllerTest
|
||||
*/
|
||||
class UpdateControllerTest extends TestCase
|
||||
{
|
||||
use RandomValues, 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
|
||||
{
|
||||
$ignore = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
$route = route('api.v1.recurrences.update', [$submission['id']]);
|
||||
|
||||
$this->updateAndCompare($route, $submission, $ignore);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function updateDataProvider(): array
|
||||
{
|
||||
$submissions = [];
|
||||
$all = $this->updateDataSet();
|
||||
foreach ($all as $name => $data) {
|
||||
$submissions[] = [$data];
|
||||
}
|
||||
|
||||
return $submissions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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++) {
|
||||
//echo 'Now at ' . $i . ':' . $ii . ' <br>' . "\n";
|
||||
// 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++) {
|
||||
//echo 'Now at ' . $i . ':' . $ii . ' <br>' . "\n";
|
||||
// now loop fields, enough to create sets I guess?
|
||||
// TODO maybe do some permutation stuff here?
|
||||
$extraTransaction = [
|
||||
'description' => $faker->uuid,
|
||||
'amount' => number_format($faker->randomFloat(2, 10, 100), 2),
|
||||
'skip' => $faker->numberBetween(1, 3),
|
||||
'weekend' => $faker->numberBetween(1, 4),
|
||||
'budget_id' => $faker->numberBetween(1, 2),
|
||||
'category_id' => $faker->numberBetween(1, 2),
|
||||
'tags' => ['a', 'c', 'd'],
|
||||
'source_id' => 1,
|
||||
'destination_id' => 8,
|
||||
];
|
||||
|
||||
$extraTransactions[] = $extraTransaction;
|
||||
}
|
||||
// TODO later maybe
|
||||
// $set[] = [
|
||||
// 'id' => 1,
|
||||
// 'fields' => [
|
||||
// 'transactions' => [
|
||||
// 'test_value' => $extraTransactions,
|
||||
// ],
|
||||
// ],
|
||||
// 'extra_ignore' => [],
|
||||
// ];
|
||||
}
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -131,13 +131,13 @@ trait TestHelpers
|
||||
{
|
||||
foreach ($opts as $i => $func) {
|
||||
if (array_key_exists($i, $set)) {
|
||||
if(!is_array($set[$i])) {
|
||||
if (!is_array($set[$i])) {
|
||||
$set[$i] = $func();
|
||||
}
|
||||
if(is_array($set[$i])) {
|
||||
foreach($set[$i] as $ii => $lines) {
|
||||
foreach($lines as $iii => $value) {
|
||||
if(isset($opts[$i][$ii][$iii])) {
|
||||
if (is_array($set[$i])) {
|
||||
foreach ($set[$i] as $ii => $lines) {
|
||||
foreach ($lines as $iii => $value) {
|
||||
if (isset($opts[$i][$ii][$iii])) {
|
||||
$set[$i][$ii][$iii] = $opts[$i][$ii][$iii]();
|
||||
}
|
||||
}
|
||||
@@ -194,19 +194,26 @@ trait TestHelpers
|
||||
}
|
||||
// field in response was also in body:
|
||||
if (array_key_exists($rKey, $submissionArray)) {
|
||||
if ($submissionArray[$rKey] !== $rValue) {
|
||||
// comparison must be on array:
|
||||
if (is_array($submissionArray[$rKey]) && is_array($rValue)) {
|
||||
$this->compareArray($originalAttributes, $rKey, $submissionArray[$rKey], $rValue);
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
"Expected field '%s' to be %s but its %s\nOriginal: %s\nSubmission: %s\nResult: %s",
|
||||
$rKey,
|
||||
var_export($submissionArray[$rKey], true),
|
||||
var_export($rValue, true),
|
||||
$originalString,
|
||||
json_encode($submissionArray),
|
||||
$responseString
|
||||
);
|
||||
$this->assertTrue(false, $message);
|
||||
continue;
|
||||
if (!is_array($submissionArray[$rKey]) && !is_array($rValue)) {
|
||||
if ($submissionArray[$rKey] !== $rValue) {
|
||||
|
||||
$message = sprintf(
|
||||
"Expected field '%s' to be %s but its %s\nOriginal: %s\nSubmission: %s\nResult: %s",
|
||||
$rKey,
|
||||
var_export($submissionArray[$rKey], true),
|
||||
var_export($rValue, true),
|
||||
$originalString,
|
||||
json_encode($submissionArray),
|
||||
$responseString
|
||||
);
|
||||
$this->assertTrue(false, $message);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -282,13 +289,18 @@ trait TestHelpers
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $fullOriginal
|
||||
* @param array $fullOriginal
|
||||
* @param string $key
|
||||
* @param array $original
|
||||
* @param array $returned
|
||||
*/
|
||||
protected function compareArray(array $fullOriginal, string $key, array $original, array $returned)
|
||||
{
|
||||
// TODO this should be configurable but OK
|
||||
if(in_array($key, ['transactions','repetitions'], true) && 0 === count($original) && 0 !== count($returned)) {
|
||||
// accept this.
|
||||
return;
|
||||
}
|
||||
$ignore = ['id', 'created_at', 'updated_at'];
|
||||
foreach ($returned as $objectKey => $object) {
|
||||
// each object is a transaction, a rule trigger, a rule action, whatever.
|
||||
|
Reference in New Issue
Block a user