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

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

View File

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

View File

@@ -99,7 +99,7 @@ class UpdateControllerTest extends TestCase
'fields' => [
'account_id' => ['test_value' => (string)$faker->numberBetween(1, 3)],
],
'extra_ignore' => ['account_name'],
'extra_ignore' => ['account_name','currency_id','currency_code'],
],
'target_amount' => [
'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:
$response = $this->get($route, ['Accept' => 'application/json']);
$status = $response->getStatusCode();
$this->assertEquals($status, 200, sprintf(sprintf('%s failed with 404.', $route)));
$response->assertStatus(200);
$originalString = $response->content();
$originalArray = json_decode($originalString, true, 512, JSON_THROW_ON_ERROR);