mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-03 11:08:28 +00:00
Restore and fix API tests
This commit is contained in:
@@ -36,6 +36,7 @@ use Illuminate\Foundation\Auth\RegistersUsers;
|
|||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\Redirector;
|
use Illuminate\Routing\Redirector;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
@@ -94,7 +95,7 @@ class RegisterController extends Controller
|
|||||||
|
|
||||||
$this->validator($request->all())->validate();
|
$this->validator($request->all())->validate();
|
||||||
$user = $this->createUser($request->all());
|
$user = $this->createUser($request->all());
|
||||||
app('log')->info(sprintf('Registered new user %s', $user->email));
|
Log::info(sprintf('Registered new user %s', $user->email));
|
||||||
$owner = new OwnerNotifiable();
|
$owner = new OwnerNotifiable();
|
||||||
event(new RegisteredUser($owner, $user));
|
event(new RegisteredUser($owner, $user));
|
||||||
|
|
||||||
|
@@ -464,7 +464,7 @@ class Navigation
|
|||||||
$displayFormat = (string) trans('config.month_and_day_js', [], $locale);
|
$displayFormat = (string) trans('config.month_and_day_js', [], $locale);
|
||||||
$diff = $start->diffInMonths($end, true);
|
$diff = $start->diffInMonths($end, true);
|
||||||
// increment by month (for year)
|
// increment by month (for year)
|
||||||
if ($diff >= 1.0001) {
|
if ($diff >= 1.0001 && $diff < 12.001) {
|
||||||
$increment = 'addMonth';
|
$increment = 'addMonth';
|
||||||
$displayFormat = (string) trans('config.month_js');
|
$displayFormat = (string) trans('config.month_js');
|
||||||
}
|
}
|
||||||
@@ -495,7 +495,7 @@ class Navigation
|
|||||||
$format = 'Y-m-d';
|
$format = 'Y-m-d';
|
||||||
$diff = $start->diffInMonths($end, true);
|
$diff = $start->diffInMonths($end, true);
|
||||||
// Log::debug(sprintf('preferredCarbonFormat(%s, %s) = %f', $start->format('Y-m-d'), $end->format('Y-m-d'), $diff));
|
// Log::debug(sprintf('preferredCarbonFormat(%s, %s) = %f', $start->format('Y-m-d'), $end->format('Y-m-d'), $diff));
|
||||||
if ($diff >= 1.001) {
|
if ($diff >= 1.001 && $diff < 12.001) {
|
||||||
// Log::debug(sprintf('Return Y-m because %s', $diff));
|
// Log::debug(sprintf('Return Y-m because %s', $diff));
|
||||||
$format = 'Y-m';
|
$format = 'Y-m';
|
||||||
}
|
}
|
||||||
@@ -566,7 +566,7 @@ class Navigation
|
|||||||
{
|
{
|
||||||
$locale = app('steam')->getLocale();
|
$locale = app('steam')->getLocale();
|
||||||
$diff = $start->diffInMonths($end, true);
|
$diff = $start->diffInMonths($end, true);
|
||||||
if ($diff >= 1.001) {
|
if ($diff >= 1.001 && $diff < 12.001) {
|
||||||
return (string) trans('config.month_js', [], $locale);
|
return (string) trans('config.month_js', [], $locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -584,7 +584,7 @@ class Navigation
|
|||||||
public function preferredEndOfPeriod(Carbon $start, Carbon $end): string
|
public function preferredEndOfPeriod(Carbon $start, Carbon $end): string
|
||||||
{
|
{
|
||||||
$diff = $start->diffInMonths($end, true);
|
$diff = $start->diffInMonths($end, true);
|
||||||
if ($diff >= 1.001) {
|
if ($diff >= 1.001 && $diff < 12.001) {
|
||||||
return 'endOfMonth';
|
return 'endOfMonth';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -602,7 +602,7 @@ class Navigation
|
|||||||
public function preferredRangeFormat(Carbon $start, Carbon $end): string
|
public function preferredRangeFormat(Carbon $start, Carbon $end): string
|
||||||
{
|
{
|
||||||
$diff = $start->diffInMonths($end, true);
|
$diff = $start->diffInMonths($end, true);
|
||||||
if ($diff >= 1.001) {
|
if ($diff >= 1.001 && $diff < 12.001) {
|
||||||
return '1M';
|
return '1M';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -620,7 +620,7 @@ class Navigation
|
|||||||
public function preferredSqlFormat(Carbon $start, Carbon $end): string
|
public function preferredSqlFormat(Carbon $start, Carbon $end): string
|
||||||
{
|
{
|
||||||
$diff = $start->diffInMonths($end, true);
|
$diff = $start->diffInMonths($end, true);
|
||||||
if ($diff >= 1.001) {
|
if ($diff >= 1.001 && $diff < 12.001) {
|
||||||
return '%Y-%m';
|
return '%Y-%m';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -66,7 +66,7 @@ trait UserGroupTrait
|
|||||||
if ($user instanceof User) {
|
if ($user instanceof User) {
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
if (null === $user->userGroup) {
|
if (null === $user->userGroup) {
|
||||||
throw new FireflyException(sprintf('User #%d has no user group.', $user->id));
|
throw new FireflyException(sprintf('User #%d ("%s") has no user group.', $user->id, $user->email));
|
||||||
}
|
}
|
||||||
$this->userGroup = $user->userGroup;
|
$this->userGroup = $user->userGroup;
|
||||||
|
|
||||||
|
@@ -74,7 +74,7 @@ class User extends Authenticatable
|
|||||||
use HasApiTokens;
|
use HasApiTokens;
|
||||||
use Notifiable;
|
use Notifiable;
|
||||||
use ReturnsIntegerIdTrait;
|
use ReturnsIntegerIdTrait;
|
||||||
protected $fillable = ['email', 'password', 'blocked', 'blocked_code'];
|
protected $fillable = ['email', 'password', 'blocked', 'blocked_code','user_group_id'];
|
||||||
protected $hidden = ['password', 'remember_token'];
|
protected $hidden = ['password', 'remember_token'];
|
||||||
protected $table = 'users';
|
protected $table = 'users';
|
||||||
|
|
||||||
|
@@ -31,12 +31,15 @@
|
|||||||
failOnRisky="true"
|
failOnRisky="true"
|
||||||
failOnWarning="true"
|
failOnWarning="true"
|
||||||
processIsolation="false"
|
processIsolation="false"
|
||||||
|
stopOnError="true"
|
||||||
stopOnFailure="true">
|
stopOnFailure="true">
|
||||||
<php>
|
<php>
|
||||||
<env name="APP_ENV" value="testing"/>
|
<env name="APP_ENV" value="testing"/>
|
||||||
|
<env name="DB_CONNECTION" value="sqlite"/>
|
||||||
<env name="APP_LOG_ENV" value="notice"/>
|
<env name="APP_LOG_ENV" value="notice"/>
|
||||||
|
<env name="DB_DATABASE" value=""/>
|
||||||
|
|
||||||
<env name="QUERY_PARSER_IMPLEMENTATION" value="new"/>
|
<env name="QUERY_PARSER_IMPLEMENTATION" value="new"/>
|
||||||
<ini name="xdebug.mode" value="coverage"/>
|
|
||||||
</php>
|
</php>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="unit">
|
<testsuite name="unit">
|
||||||
|
@@ -45,20 +45,6 @@ final class BillControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
|
|
||||||
#[Override]
|
|
||||||
protected function createAuthenticatedUser(): User
|
|
||||||
{
|
|
||||||
$userGroup = UserGroup::create(['title' => 'Test Group']);
|
|
||||||
|
|
||||||
$user = User::create([
|
|
||||||
'email' => 'test@email.com',
|
|
||||||
'password' => 'password',
|
|
||||||
]);
|
|
||||||
$user->user_group_id = $userGroup->id;
|
|
||||||
$user->save();
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createTestBills(int $count, User $user): void
|
private function createTestBills(int $count, User $user): void
|
||||||
{
|
{
|
||||||
@@ -96,7 +82,6 @@ final class BillControllerTest extends TestCase
|
|||||||
$response = $this->get(route('api.v1.autocomplete.bills'), ['Accept' => 'application/json']);
|
$response = $this->get(route('api.v1.autocomplete.bills'), ['Accept' => 'application/json']);
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
$response->assertHeader('Content-Type', 'application/json');
|
$response->assertHeader('Content-Type', 'application/json');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGivenAuthenticatedRequestWhenCallingTheBillsEndpointThenReturnsBills(): void
|
public function testGivenAuthenticatedRequestWhenCallingTheBillsEndpointThenReturnsBills(): void
|
||||||
|
@@ -45,21 +45,6 @@ final class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
|
|
||||||
#[Override]
|
|
||||||
protected function createAuthenticatedUser(): User
|
|
||||||
{
|
|
||||||
$userGroup = UserGroup::create(['title' => 'Test Group']);
|
|
||||||
|
|
||||||
$user = User::create([
|
|
||||||
'email' => 'test@email.com',
|
|
||||||
'password' => 'password',
|
|
||||||
]);
|
|
||||||
$user->user_group_id = $userGroup->id;
|
|
||||||
$user->save();
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createTestBudgets(int $count, User $user): void
|
private function createTestBudgets(int $count, User $user): void
|
||||||
{
|
{
|
||||||
for ($i = 1; $i <= $count; ++$i) {
|
for ($i = 1; $i <= $count; ++$i) {
|
||||||
|
@@ -25,7 +25,9 @@ declare(strict_types=1);
|
|||||||
namespace Tests\integration\Api\Autocomplete;
|
namespace Tests\integration\Api\Autocomplete;
|
||||||
|
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
|
use FireflyIII\Models\UserRole;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Tests\integration\TestCase;
|
use Tests\integration\TestCase;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use FireflyIII\Models\UserGroup;
|
use FireflyIII\Models\UserGroup;
|
||||||
@@ -45,20 +47,7 @@ final class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
|
|
||||||
#[Override]
|
|
||||||
protected function createAuthenticatedUser(): User
|
|
||||||
{
|
|
||||||
$userGroup = UserGroup::create(['title' => 'Test Group']);
|
|
||||||
|
|
||||||
$user = User::create([
|
|
||||||
'email' => 'test@email.com',
|
|
||||||
'password' => 'password',
|
|
||||||
]);
|
|
||||||
$user->user_group_id = $userGroup->id;
|
|
||||||
$user->save();
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createTestCategories(int $count, User $user): void
|
private function createTestCategories(int $count, User $user): void
|
||||||
{
|
{
|
||||||
|
@@ -45,21 +45,6 @@ final class CurrencyControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
|
|
||||||
#[Override]
|
|
||||||
protected function createAuthenticatedUser(): User
|
|
||||||
{
|
|
||||||
$userGroup = UserGroup::create(['title' => 'Test Group']);
|
|
||||||
|
|
||||||
|
|
||||||
$user = User::create([
|
|
||||||
'email' => 'test@email.com',
|
|
||||||
'password' => 'password',
|
|
||||||
]);
|
|
||||||
$user->user_group_id = $userGroup->id;
|
|
||||||
$user->save();
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createTestCurrencies(int $count, bool $enabled): void
|
private function createTestCurrencies(int $count, bool $enabled): void
|
||||||
{
|
{
|
||||||
|
@@ -45,22 +45,6 @@ final class ObjectGroupControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
|
|
||||||
#[Override]
|
|
||||||
protected function createAuthenticatedUser(): User
|
|
||||||
{
|
|
||||||
$userGroup = UserGroup::create(['title' => 'Test Group']);
|
|
||||||
|
|
||||||
|
|
||||||
$user = User::create([
|
|
||||||
'email' => 'test@email.com',
|
|
||||||
'password' => 'password',
|
|
||||||
]);
|
|
||||||
$user->user_group_id = $userGroup->id;
|
|
||||||
$user->save();
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createTestObjectGroups(int $count, User $user): void
|
private function createTestObjectGroups(int $count, User $user): void
|
||||||
{
|
{
|
||||||
for ($i = 1; $i <= $count; ++$i) {
|
for ($i = 1; $i <= $count; ++$i) {
|
||||||
|
@@ -23,10 +23,13 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Tests\integration;
|
namespace Tests\integration;
|
||||||
|
|
||||||
|
use FireflyIII\Models\GroupMembership;
|
||||||
use FireflyIII\Models\UserGroup;
|
use FireflyIII\Models\UserGroup;
|
||||||
|
use FireflyIII\Models\UserRole;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Tests\integration\Traits\CollectsValues;
|
use Tests\integration\Traits\CollectsValues;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,11 +60,26 @@ abstract class TestCase extends BaseTestCase
|
|||||||
protected function createAuthenticatedUser(): User
|
protected function createAuthenticatedUser(): User
|
||||||
{
|
{
|
||||||
$group = UserGroup::create(['title' => 'test@email.com']);
|
$group = UserGroup::create(['title' => 'test@email.com']);
|
||||||
|
$role = UserRole::where('title', 'owner')->first();
|
||||||
return User::create([
|
$user = User::create([
|
||||||
'email' => 'test@email.com',
|
'email' => 'test@email.com',
|
||||||
'password' => 'password',
|
'password' => 'password',
|
||||||
'user_group_id' => $group->id,
|
'user_group_id' => $group->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
GroupMembership::create(
|
||||||
|
[
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'user_group_id' => $group->id,
|
||||||
|
'user_role_id' => $role->id,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user