Expand all test models.

This commit is contained in:
James Cole
2021-03-14 10:41:17 +01:00
parent 40a463d62a
commit 288052905e
24 changed files with 1703 additions and 65 deletions

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Models\RuleGroup; namespace FireflyIII\Api\V1\Requests\Models\RuleGroup;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Rules\IsBoolean; use FireflyIII\Rules\IsBoolean;
use FireflyIII\Support\Request\ChecksLogin; use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes; use FireflyIII\Support\Request\ConvertsDataTypes;
@@ -46,15 +45,19 @@ class StoreRequest extends FormRequest
public function getAll(): array public function getAll(): array
{ {
$active = true; $active = true;
$order = 31337;
if (null !== $this->get('active')) { if (null !== $this->get('active')) {
$active = $this->boolean('active'); $active = $this->boolean('active');
} }
if (null !== $this->get('order')) {
$order = $this->integer('order');
}
return [ return [
'title' => $this->string('title'), 'title' => $this->string('title'),
'description' => $this->string('description'), 'description' => $this->string('description'),
'active' => $active, 'active' => $active,
'order' => $order,
]; ];
} }

View File

@@ -28,7 +28,6 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface; use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
use FireflyIII\Support\Request\ChecksLogin; use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes; use FireflyIII\Support\Request\ConvertsDataTypes;
use FireflyIII\User;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Validator; use Illuminate\Validation\Validator;
@@ -94,7 +93,7 @@ class UpdateRequest extends FormRequest
{ {
/** @var TransactionJournalLink $existing */ /** @var TransactionJournalLink $existing */
$existing = $this->route()->parameter('journalLink'); $existing = $this->route()->parameter('journalLink');
$data = $validator->getData(); $data = $validator->getData();
/** @var LinkTypeRepositoryInterface $repository */ /** @var LinkTypeRepositoryInterface $repository */
$repository = app(LinkTypeRepositoryInterface::class); $repository = app(LinkTypeRepositoryInterface::class);
$repository->setUser(auth()->user()); $repository->setUser(auth()->user());
@@ -107,7 +106,13 @@ class UpdateRequest extends FormRequest
$outwardId = $data['outward_id'] ?? $existing->destination_id; $outwardId = $data['outward_id'] ?? $existing->destination_id;
$inward = $journalRepos->findNull((int)$inwardId); $inward = $journalRepos->findNull((int)$inwardId);
$outward = $journalRepos->findNull((int)$outwardId); $outward = $journalRepos->findNull((int)$outwardId);
if($inward->id === $outward->id) { if (null === $inward) {
$inward = $existing->source;
}
if (null === $outward) {
$outward = $existing->destination;
}
if ($inward->id === $outward->id) {
$validator->errors()->add('inward_id', 'Inward ID must be different from outward ID.'); $validator->errors()->add('inward_id', 'Inward ID must be different from outward ID.');
$validator->errors()->add('outward_id', 'Inward ID must be different from outward ID.'); $validator->errors()->add('outward_id', 'Inward ID must be different from outward ID.');
} }
@@ -115,14 +120,14 @@ class UpdateRequest extends FormRequest
if (null === $inward) { if (null === $inward) {
$validator->errors()->add('inward_id', 'This is not a valid inward journal.'); $validator->errors()->add('inward_id', 'This is not a valid inward journal.');
} }
if(null === $outward) { if (null === $outward) {
$validator->errors()->add('inward_id', 'This is not a valid outward journal.'); $validator->errors()->add('inward_id', 'This is not a valid outward journal.');
} }
$inDB =$repository->findSpecificLink($existing->linkType, $inward, $outward); $inDB = $repository->findSpecificLink($existing->linkType, $inward, $outward);
if(null === $inDB) { if (null === $inDB) {
return; return;
} }
if($inDB->id !== $existing->id) { if ($inDB->id !== $existing->id) {
$validator->errors()->add('outward_id', 'Already have a link between inward and outward.'); $validator->errors()->add('outward_id', 'Already have a link between inward and outward.');
$validator->errors()->add('inward_id', 'Already have a link between inward and outward.'); $validator->errors()->add('inward_id', 'Already have a link between inward and outward.');
} }

View File

@@ -107,6 +107,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
*/ */
public function findLink(TransactionJournal $one, TransactionJournal $two): bool public function findLink(TransactionJournal $one, TransactionJournal $two): bool
{ {
Log::debug(sprintf('Now in findLink(%d, %d)', $one->id, $two->id));
$count = TransactionJournalLink::whereDestinationId($one->id)->whereSourceId($two->id)->count(); $count = TransactionJournalLink::whereDestinationId($one->id)->whereSourceId($two->id)->count();
$opposingCount = TransactionJournalLink::whereDestinationId($two->id)->whereSourceId($one->id)->count(); $opposingCount = TransactionJournalLink::whereDestinationId($two->id)->whereSourceId($one->id)->count();

View File

@@ -274,7 +274,7 @@ class RuleRepository implements RuleRepositoryInterface
++$rule->order; ++$rule->order;
$rule->save(); $rule->save();
$this->resetRulesInGroupOrder($rule->ruleGroup); $this->resetRuleOrder($rule->ruleGroup);
return true; return true;
} }
@@ -311,7 +311,7 @@ class RuleRepository implements RuleRepositoryInterface
--$rule->order; --$rule->order;
$rule->save(); $rule->save();
$this->resetRulesInGroupOrder($rule->ruleGroup); $this->resetRuleOrder($rule->ruleGroup);
return true; return true;
} }
@@ -365,7 +365,7 @@ class RuleRepository implements RuleRepositoryInterface
* *
* @return bool * @return bool
*/ */
public function resetRulesInGroupOrder(RuleGroup $ruleGroup): bool public function resetRuleOrder(RuleGroup $ruleGroup): bool
{ {
$ruleGroup->rules()->withTrashed()->whereNotNull('deleted_at')->update(['order' => 0]); $ruleGroup->rules()->withTrashed()->whereNotNull('deleted_at')->update(['order' => 0]);

View File

@@ -167,7 +167,7 @@ interface RuleRepositoryInterface
* *
* @return bool * @return bool
*/ */
public function resetRulesInGroupOrder(RuleGroup $ruleGroup): bool; public function resetRuleOrder(RuleGroup $ruleGroup): bool;
/** /**
* @param string $query * @param string $query

View File

@@ -89,9 +89,9 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
$ruleGroup->delete(); $ruleGroup->delete();
$this->resetRuleGroupOrder(); $this->resetOrder();
if (null !== $moveTo) { if (null !== $moveTo) {
$this->resetRulesInGroupOrder($moveTo); $this->resetRuleOrder($moveTo);
} }
return true; return true;
@@ -324,21 +324,25 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
/** /**
* @return bool * @return bool
*/ */
public function resetRuleGroupOrder(): bool public function resetOrder(): bool
{ {
$this->user->ruleGroups()->whereNotNull('deleted_at')->update(['order' => 0]); $this->user->ruleGroups()->whereNotNull('deleted_at');
$set = $this->user $set = $this->user
->ruleGroups() ->ruleGroups()
->orderBy('order', 'ASC')->get(); ->orderBy('order', 'ASC')
->orderBy('title', 'DESC')
->get();
$count = 1; $count = 1;
/** @var RuleGroup $entry */ /** @var RuleGroup $entry */
foreach ($set as $entry) { foreach ($set as $entry) {
$entry->order = $count; if ($entry->order !== $count) {
$entry->save(); $entry->order = $count;
$entry->save();
}
// also update rules in group. // also update rules in group.
$this->resetRulesInGroupOrder($entry); $this->resetRuleOrder($entry);
++$count; ++$count;
} }
@@ -351,19 +355,21 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
* *
* @return bool * @return bool
*/ */
public function resetRulesInGroupOrder(RuleGroup $ruleGroup): bool public function resetRuleOrder(RuleGroup $ruleGroup): bool
{ {
$ruleGroup->rules()->whereNotNull('deleted_at')->update(['order' => 0]);
$set = $ruleGroup->rules() $set = $ruleGroup->rules()
->orderBy('order', 'ASC') ->orderBy('order', 'ASC')
->orderBy('title', 'DESC')
->orderBy('updated_at', 'DESC') ->orderBy('updated_at', 'DESC')
->get(); ->get(['rules.*']);
$count = 1; $count = 1;
/** @var Rule $entry */ /** @var Rule $entry */
foreach ($set as $entry) { foreach ($set as $entry) {
$entry->order = $count; if ($entry->order !== $count) {
$entry->save(); $entry->order = $count;
$entry->save();
}
++$count; ++$count;
} }
@@ -400,19 +406,18 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
*/ */
public function store(array $data): RuleGroup public function store(array $data): RuleGroup
{ {
$order = $this->getHighestOrderRuleGroup();
$newRuleGroup = new RuleGroup( $newRuleGroup = new RuleGroup(
[ [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'title' => $data['title'], 'title' => $data['title'],
'description' => $data['description'], 'description' => $data['description'],
'order' => $order + 1, 'order' => 31337,
'active' => $data['active'], 'active' => $data['active'],
] ]
); );
$newRuleGroup->save(); $newRuleGroup->save();
$this->resetRuleGroupOrder(); $this->resetOrder();
$this->setOrder($newRuleGroup, $data['order']);
return $newRuleGroup; return $newRuleGroup;
} }
@@ -437,11 +442,8 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
} }
// order // order
if (array_key_exists('order', $data) && $ruleGroup->order !== $data['order']) { if (array_key_exists('order', $data) && $ruleGroup->order !== $data['order']) {
$this->correctRuleGroupOrder(); $this->resetOrder();
$max = $this->maxOrder(); $this->setOrder($ruleGroup, (int)$data['order']);
// TODO also for bills and accounts:
$data['order'] = $data['order'] > $max ? $max : $data['order'];
$ruleGroup = $this->updateOrder($ruleGroup, $ruleGroup->order, $data['order']);
} }
$ruleGroup->save(); $ruleGroup->save();
@@ -449,26 +451,30 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
return $ruleGroup; return $ruleGroup;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function updateOrder(RuleGroup $ruleGroup, int $oldOrder, int $newOrder): RuleGroup public function setOrder(RuleGroup $ruleGroup, int $newOrder): void
{ {
$oldOrder = (int)$ruleGroup->order;
if ($newOrder > $oldOrder) { if ($newOrder > $oldOrder) {
$this->user->ruleGroups()->where('order', '<=', $newOrder)->where('order', '>', $oldOrder) $this->user->ruleGroups()->where('rule_groups.order', '<=', $newOrder)->where('rule_groups.order', '>', $oldOrder)
->where('rule_groups.id', '!=', $ruleGroup->id) ->where('rule_groups.id', '!=', $ruleGroup->id)
->decrement('rule_groups.order', 1); ->decrement('order', 1);
$ruleGroup->order = $newOrder;
$ruleGroup->save();
}
if ($newOrder < $oldOrder) {
$this->user->ruleGroups()->where('order', '>=', $newOrder)->where('order', '<', $oldOrder)
->where('rule_groups.id', '!=', $ruleGroup->id)
->increment('rule_groups.order', 1);
$ruleGroup->order = $newOrder; $ruleGroup->order = $newOrder;
Log::debug(sprintf('Order of group #%d ("%s") is now %d', $ruleGroup->id, $ruleGroup->title, $newOrder));
$ruleGroup->save(); $ruleGroup->save();
return;
} }
return $ruleGroup; $this->user->ruleGroups()->where('rule_groups.order', '>=', $newOrder)->where('rule_groups.order', '<', $oldOrder)
->where('rule_groups.id', '!=', $ruleGroup->id)
->increment('order', 1);
$ruleGroup->order = $newOrder;
Log::debug(sprintf('Order of group #%d ("%s") is now %d', $ruleGroup->id, $ruleGroup->title, $newOrder));
$ruleGroup->save();
} }
} }

View File

@@ -145,14 +145,20 @@ interface RuleGroupRepositoryInterface
/** /**
* @return bool * @return bool
*/ */
public function resetRuleGroupOrder(): bool; public function resetOrder(): bool;
/** /**
* @param RuleGroup $ruleGroup * @param RuleGroup $ruleGroup
* *
* @return bool * @return bool
*/ */
public function resetRulesInGroupOrder(RuleGroup $ruleGroup): bool; public function resetRuleOrder(RuleGroup $ruleGroup): bool;
/**
* @param RuleGroup $ruleGroup
* @param int $newOrder
*/
public function setOrder(RuleGroup $ruleGroup, int $newOrder): void;
/** /**
* @param string $query * @param string $query
@@ -181,14 +187,4 @@ interface RuleGroupRepositoryInterface
* @return RuleGroup * @return RuleGroup
*/ */
public function update(RuleGroup $ruleGroup, array $data): RuleGroup; public function update(RuleGroup $ruleGroup, array $data): RuleGroup;
/**
*
* @param RuleGroup $ruleGroup
* @param int $oldOrder
* @param int $newOrder
*
* @return RuleGroup
*/
public function updateOrder(RuleGroup $ruleGroup, int $oldOrder, int $newOrder): RuleGroup;
} }

View File

@@ -53,7 +53,7 @@ class TagTransformer extends AbstractTransformer
if (null !== $location) { if (null !== $location) {
$latitude = $location->latitude; $latitude = $location->latitude;
$longitude = $location->longitude; $longitude = $location->longitude;
$zoomLevel = $location->zoom_level; $zoomLevel = (int)$location->zoom_level;
} }
return [ return [
'id' => (int)$tag->id, 'id' => (int)$tag->id,

View File

@@ -121,7 +121,7 @@ class UpdateControllerTest extends TestCase
'fields' => [ 'fields' => [
'start' => ['test_value' => $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d')], 'start' => ['test_value' => $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d')],
], ],
'extra_ignore' => [], 'extra_ignore' => ['spent'],
], ],
'end' => [ 'end' => [
'id' => 1, 'id' => 1,
@@ -129,7 +129,7 @@ class UpdateControllerTest extends TestCase
'fields' => [ 'fields' => [
'end' => ['test_value' => $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d')], 'end' => ['test_value' => $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d')],
], ],
'extra_ignore' => [], 'extra_ignore' => ['spent'],
], ],
'amount' => [ 'amount' => [
'id' => 1, 'id' => 1,

View File

@@ -86,19 +86,20 @@ class UpdateControllerTest extends TestCase
$faker = Factory::create(); $faker = Factory::create();
$set = [ $set = [
'title' => [ 'title' => [
'id' => 1, 'id' => 3,
'fields' => [ 'fields' => [
'title' => ['test_value' => $faker->uuid], 'title' => ['test_value' => $faker->uuid],
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],
'order' => [ 'order' => [
'id' => 1, 'id' => 3,
'fields' => [ 'fields' => [
'order' => ['test_value' => $faker->numberBetween(1, 2)], 'order' => ['test_value' => $faker->numberBetween(1, 2)],
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],
]; ];
return $set; return $set;

View File

@@ -99,7 +99,7 @@ class UpdateControllerTest extends TestCase
'fields' => [ 'fields' => [
'account_id' => ['test_value' => (string)$faker->numberBetween(1, 3)], 'account_id' => ['test_value' => (string)$faker->numberBetween(1, 3)],
], ],
'extra_ignore' => ['account_name'], 'extra_ignore' => ['account_name','currency_id','currency_code'],
], ],
'target_amount' => [ 'target_amount' => [
'id' => 1, 'id' => 1,

View File

@@ -0,0 +1,138 @@
<?php
/*
* StoreControllerTest.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\RuleGroup;
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 StoreControllerTest
*/
class StoreControllerTest 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)));
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.rule_groups.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
* @return array
*/
public function storeDataProvider(): array
{
$minimalSets = $this->minimalSets();
$optionalSets = $this->optionalSets();
$regenConfig = [
'title' => function () {
$faker = Factory::create();
return $faker->uuid;
},
];
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
}
/**
* @return array
*/
private function minimalSets(): array
{
$faker = Factory::create();
return [
'default_group' => [
'parameters' => [],
'fields' => [
'title' => $faker->uuid,
],
],
];
}
/**
* @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,
],
],
];
}
}

View File

@@ -0,0 +1,122 @@
<?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\RuleGroup;
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.rule_groups.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();
$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;
}
}

View File

@@ -0,0 +1,140 @@
<?php
/*
* StoreControllerTest.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\Tag;
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 StoreControllerTest
*/
class StoreControllerTest 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)));
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.tags.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
* @return array
*/
public function storeDataProvider(): array
{
$minimalSets = $this->minimalSets();
$optionalSets = $this->optionalSets();
$regenConfig = [
'tag' => function () {
$faker = Factory::create();
return $faker->uuid;
},
];
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
}
/**
* @return array
*/
private function minimalSets(): array
{
$faker = Factory::create();
return [
'default_tag' => [
'parameters' => [],
'fields' => [
'tag' => $faker->uuid,
],
],
];
}
/**
* @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),
],
],
];
}
}

View File

@@ -0,0 +1,124 @@
<?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\Tag;
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.tags.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();
$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;
}
}

View File

@@ -0,0 +1,149 @@
<?php
/*
* StoreControllerTest.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\TransactionCurrency;
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 StoreControllerTest
*/
class StoreControllerTest 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)));
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.currencies.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
* @return array
*/
public function storeDataProvider(): array
{
$minimalSets = $this->minimalSets();
$optionalSets = $this->optionalSets();
$regenConfig = [
'code' => function () {
$faker = Factory::create();
return substr($faker->uuid, 0, 3);
},
'name' => function () {
$faker = Factory::create();
return $faker->uuid;
},
'symbol' => function () {
$faker = Factory::create();
return $faker->randomAscii.$faker->randomAscii;
},
];
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
}
/**
* @return array
*/
private function minimalSets(): array
{
$faker = Factory::create();
return [
'default_currency' => [
'parameters' => [],
'fields' => [
'code' => substr($faker->uuid, 0, 3),
'name' => $faker->uuid,
'symbol' => $faker->randomAscii.$faker->randomAscii,
],
],
];
}
/**
* @return \array[][]
*/
private function optionalSets(): array
{
$faker = Factory::create();
return [
'enabled' => [
'fields' => [
'enabled' => $faker->boolean,
],
],
'default' => [
'fields' => [
'default' => $faker->boolean,
],
],
'decimal_places' => [
'fields' => [
'decimal_places' => $faker->numberBetween(1, 6),
],
],
];
}
}

View File

@@ -0,0 +1,136 @@
<?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\TransactionCurrency;
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.currencies.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();
$set = [
'name' => [
'id' => 'INR',
'fields' => [
'name' => ['test_value' => $faker->uuid],
],
'extra_ignore' => [],
],
'code' => [
'id' => 'INR',
'fields' => [
'code' => ['test_value' => substr($faker->uuid, 0, 3)],
],
'extra_ignore' => [],
],
'symbol' => [
'id' => 'RUB',
'fields' => [
'description' => ['test_value' => $faker->randomAscii.$faker->randomAscii],
],
'extra_ignore' => [],
],
'decimal_places' => [
'id' => 'ETH',
'fields' => [
'decimal_places' => ['test_value' => $faker->numberBetween(1, 6)],
],
'extra_ignore' => [],
],
'enabled' => [
'id' => 'ETH',
'fields' => [
'enabled' => ['test_value' => $faker->boolean],
],
'extra_ignore' => [],
],
'default' => [
'id' => 'XBT',
'fields' => [
'default' => ['test_value' => $faker->boolean],
],
'extra_ignore' => [],
],
];
return $set;
}
}

View File

@@ -0,0 +1,143 @@
<?php
/*
* StoreControllerTest.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\TransactionLink;
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 StoreControllerTest
*/
class StoreControllerTest 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)));
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.transaction_links.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
* @return array
*/
public function storeDataProvider(): array
{
$minimalSets = $this->minimalSets();
$optionalSets = $this->optionalSets();
$regenConfig = [
'inward_id' => function () {
$faker = Factory::create();
return (string)$faker->numberBetween(1, 10);
},
'outward_id' => function () {
$faker = Factory::create();
return (string)$faker->numberBetween(11, 20);
},
];
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
}
/**
* @return array
*/
private function minimalSets(): array
{
$faker = Factory::create();
return [
'default_link_id' => [
'parameters' => [],
'fields' => [
'link_type_id' => (string)$faker->numberBetween(1, 4),
'inward_id' => (string)$faker->numberBetween(1, 10),
'outward_id' => (string)$faker->numberBetween(11, 20),
],
],
'default_link_name' => [
'parameters' => [],
'fields' => [
'link_type_name' => 'Related',
'inward_id' => (string)$faker->numberBetween(1, 10),
'outward_id' => (string)$faker->numberBetween(11, 20),
],
],
];
}
/**
* @return \array[][]
*/
private function optionalSets(): array
{
$faker = Factory::create();
return [
'notes' => [
'fields' => [
'notes' => join(' ', $faker->words(5)),
],
],
];
}
}

View File

@@ -0,0 +1,129 @@
<?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\TransactionLink;
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.transaction_links.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();
$set = [
'link_type_id' => [
'id' => 1,
'fields' => [
'link_type_id' => ['test_value' => (string)$faker->numberBetween(1,3)],
],
'extra_ignore' => ['link_type_name'],
],
'link_type_name' => [
'id' => 1,
'fields' => [
'link_type_name' => ['test_value' => 'Refund'],
],
'extra_ignore' => ['link_type_id'],
],
'inward_id' => [
'id' => 1,
'fields' => [
'inward_id' => ['test_value' => (string)$faker->numberBetween(11,20)],
],
'extra_ignore' => [],
],
'outward_id' => [
'id' => 1,
'fields' => [
'outward_id' => ['test_value' => (string)$faker->numberBetween(11, 30)],
],
'extra_ignore' => [],
],
'notes' => [
'id' => 1,
'fields' => [
'notes' => ['test_value' => join(' ', $faker->words(5))],
],
'extra_ignore' => [],
],
];
return $set;
}
}

View File

@@ -0,0 +1,135 @@
<?php
/*
* StoreControllerTest.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\TransactionLinkType;
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 StoreControllerTest
*/
class StoreControllerTest 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)));
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.link_types.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
* @return array
*/
public function storeDataProvider(): array
{
$minimalSets = $this->minimalSets();
$optionalSets = $this->optionalSets();
$regenConfig = [
'name' => function () {
$faker = Factory::create();
return $faker->uuid;
},
'inward' => function () {
$faker = Factory::create();
return $faker->uuid;
},
'outward' => function () {
$faker = Factory::create();
return $faker->uuid;
},
];
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
}
/**
* @return array
*/
private function minimalSets(): array
{
$faker = Factory::create();
return [
'default_link_type' => [
'parameters' => [],
'fields' => [
'name' => $faker->uuid,
'inward' => $faker->uuid,
'outward' => $faker->uuid,
],
],
];
}
/**
* @return \array[][]
*/
private function optionalSets(): array
{
return [
];
}
}

View File

@@ -0,0 +1,115 @@
<?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\TransactionLinkType;
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.link_types.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();
$set = [
'name' => [
'id' => 5,
'fields' => [
'name' => ['test_value' => $faker->uuid],
],
'extra_ignore' => [],
],
'inward' => [
'id' => 5,
'fields' => [
'inward' => ['test_value' => $faker->uuid],
],
'extra_ignore' => [],
],
'outward' => [
'id' => 5,
'fields' => [
'outward' => ['test_value' => $faker->uuid],
],
'extra_ignore' => [],
],
];
return $set;
}
}

View File

@@ -0,0 +1,157 @@
<?php
/*
* StoreControllerTest.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\Webhook;
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 StoreControllerTest
*/
class StoreControllerTest 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)));
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.webhooks.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
* @return array
*/
public function storeDataProvider(): array
{
$minimalSets = $this->minimalSets();
$optionalSets = $this->optionalSets();
$regenConfig = [
'title' => function () {
$faker = Factory::create();
return $faker->uuid;
},
'url' => function () {
$faker = Factory::create();
return str_replace(['http://'], 'https://', $faker->url);
},
'trigger' => function () {
$faker = Factory::create();
return $faker->randomElement(['TRIGGER_STORE_TRANSACTION', 'TRIGGER_UPDATE_TRANSACTION', 'TRIGGER_DESTROY_TRANSACTION']);
},
'response' => function () {
$faker = Factory::create();
return $faker->randomElement(['RESPONSE_TRANSACTIONS', 'RESPONSE_ACCOUNTS', 'RESPONSE_NONE']);
},
'delivery' => function () {
$faker = Factory::create();
return $faker->randomElement(['DELIVERY_JSON']);
},
];
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
}
/**
* @return array
*/
private function minimalSets(): array
{
$faker = Factory::create();
// - title
// - trigger
// - response
// - delivery
// - url
return [
'default_webhook' => [
'parameters' => [],
'fields' => [
'title' => $faker->uuid,
'trigger' => $faker->randomElement(['TRIGGER_STORE_TRANSACTION', 'TRIGGER_UPDATE_TRANSACTION', 'TRIGGER_DESTROY_TRANSACTION']),
'response' => $faker->randomElement(['RESPONSE_TRANSACTIONS', 'RESPONSE_ACCOUNTS', 'RESPONSE_NONE']),
'delivery' => $faker->randomElement(['DELIVERY_JSON']),
'url' => str_replace(['http://'], 'https://', $faker->url),
],
],
];
}
/**
* @return \array[][]
*/
private function optionalSets(): array
{
$faker = Factory::create();
return [
'active' => [
'fields' => [
'active' => $faker->boolean,
],
],
];
}
}

View File

@@ -0,0 +1,136 @@
<?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\Webhook;
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.webhooks.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();
$set = [
'active' => [
'id' => 1,
'fields' => [
'active' => ['test_value' => $faker->boolean],
],
'extra_ignore' => [],
],
'title' => [
'id' => 1,
'fields' => [
'title' => ['test_value' => $faker->uuid],
],
'extra_ignore' => [],
],
'trigger' => [
'id' => 1,
'fields' => [
'trigger' => ['test_value' => $faker->randomElement(['TRIGGER_STORE_TRANSACTION', 'TRIGGER_UPDATE_TRANSACTION', 'TRIGGER_DESTROY_TRANSACTION'])],
],
'extra_ignore' => [],
],
'response' => [
'id' => 1,
'fields' => [
'response' => ['test_value' => $faker->randomElement(['RESPONSE_TRANSACTIONS', 'RESPONSE_ACCOUNTS', 'RESPONSE_NONE'])],
],
'extra_ignore' => [],
],
'delivery' => [
'id' => 1,
'fields' => [
'delivery' => ['test_value' => $faker->randomElement(['DELIVERY_JSON'])],
],
'extra_ignore' => [],
],
'url' => [
'id' => 1,
'fields' => [
'url' => ['test_value' => str_replace(['http://'], 'https://', $faker->url)],
],
'extra_ignore' => [],
],
];
return $set;
}
}

View File

@@ -132,6 +132,8 @@ trait TestHelpers
{ {
// get original values: // get original values:
$response = $this->get($route, ['Accept' => 'application/json']); $response = $this->get($route, ['Accept' => 'application/json']);
$status = $response->getStatusCode();
$this->assertEquals($status, 200, sprintf(sprintf('%s failed with 404.', $route)));
$response->assertStatus(200); $response->assertStatus(200);
$originalString = $response->content(); $originalString = $response->content();
$originalArray = json_decode($originalString, true, 512, JSON_THROW_ON_ERROR); $originalArray = json_decode($originalString, true, 512, JSON_THROW_ON_ERROR);