mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-29 11:15:58 +00:00
test refactoring
This commit is contained in:
+1
-1
@@ -9,13 +9,13 @@ use Domain\Admin\Controllers\Users\DeleteUserController;
|
|||||||
use Domain\Settings\Controllers\GetSettingsValueController;
|
use Domain\Settings\Controllers\GetSettingsValueController;
|
||||||
use Domain\Admin\Controllers\Dashboard\GetNewbiesController;
|
use Domain\Admin\Controllers\Dashboard\GetNewbiesController;
|
||||||
use Domain\Admin\Controllers\Users\ChangeUserRoleController;
|
use Domain\Admin\Controllers\Users\ChangeUserRoleController;
|
||||||
use Domain\Settings\Controllers\StoreSocialServiceCredentialsController;
|
|
||||||
use Domain\Settings\Controllers\UpdateSettingValueController;
|
use Domain\Settings\Controllers\UpdateSettingValueController;
|
||||||
use Domain\Admin\Controllers\Users\ResetUserPasswordController;
|
use Domain\Admin\Controllers\Users\ResetUserPasswordController;
|
||||||
use Domain\Admin\Controllers\Dashboard\GetDashboardDataController;
|
use Domain\Admin\Controllers\Dashboard\GetDashboardDataController;
|
||||||
use Domain\Localization\Controllers\UpdateLanguageStringController;
|
use Domain\Localization\Controllers\UpdateLanguageStringController;
|
||||||
use Domain\Admin\Controllers\Users\ShowUserStorageCapacityController;
|
use Domain\Admin\Controllers\Users\ShowUserStorageCapacityController;
|
||||||
use Domain\Admin\Controllers\Users\ChangeUserStorageCapacityController;
|
use Domain\Admin\Controllers\Users\ChangeUserStorageCapacityController;
|
||||||
|
use Domain\Settings\Controllers\StoreSocialServiceCredentialsController;
|
||||||
use Domain\Settings\Controllers\StorePaymentServiceCredentialsController;
|
use Domain\Settings\Controllers\StorePaymentServiceCredentialsController;
|
||||||
|
|
||||||
// Dashboard
|
// Dashboard
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ class GenerateDemoSubscriptionContentCommand extends Command
|
|||||||
|
|
||||||
// Create plans and subscriptions for fixed billing
|
// Create plans and subscriptions for fixed billing
|
||||||
if ($this->argument('type') === 'fixed') {
|
if ($this->argument('type') === 'fixed') {
|
||||||
|
|
||||||
|
// TODO: check for credentials
|
||||||
|
|
||||||
$this->info('Setting up new fixed plans demo data...');
|
$this->info('Setting up new fixed plans demo data...');
|
||||||
$this->generateFixedPlans();
|
$this->generateFixedPlans();
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class AutoSubscribeForMeteredBillingAction
|
|||||||
} else {
|
} else {
|
||||||
// Create balance with 0 amount
|
// Create balance with 0 amount
|
||||||
$user->balance()->create([
|
$user->balance()->create([
|
||||||
'amount' => 0,
|
'amount' => 0,
|
||||||
'currency' => $plan->currency,
|
'currency' => $plan->currency,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Users\Actions;
|
namespace App\Users\Actions;
|
||||||
|
|
||||||
use App\Users\DTO\CreateUserData;
|
|
||||||
use App\Users\Models\User;
|
use App\Users\Models\User;
|
||||||
|
use App\Users\DTO\CreateUserData;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Auth\Events\Registered;
|
use Illuminate\Auth\Events\Registered;
|
||||||
use Illuminate\Contracts\Auth\StatefulGuard;
|
use Illuminate\Contracts\Auth\StatefulGuard;
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ class RegisterUserController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public CreateNewUserAction $createNewUser,
|
public CreateNewUserAction $createNewUser,
|
||||||
) {}
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
public function __invoke(RegisterUserRequest $request)
|
public function __invoke(RegisterUserRequest $request)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Users\Resources;
|
namespace App\Users\Resources;
|
||||||
|
|
||||||
use ByteUnits\Metric;
|
use ByteUnits\Metric;
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
@@ -22,18 +20,18 @@ class UserStorageResource extends JsonResource
|
|||||||
|
|
||||||
$totalCapacity = match (get_settings('subscription_type')) {
|
$totalCapacity = match (get_settings('subscription_type')) {
|
||||||
'metered' => $this->usedCapacity / 1000000000,
|
'metered' => $this->usedCapacity / 1000000000,
|
||||||
'fixed' => $this->limitations->max_storage_amount,
|
'fixed' => $this->limitations->max_storage_amount,
|
||||||
default => $this->limitations->max_storage_amount,
|
default => $this->limitations->max_storage_amount,
|
||||||
};
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'data' => [
|
'data' => [
|
||||||
'id' => (string)$this->id,
|
'id' => (string) $this->id,
|
||||||
'type' => 'storage',
|
'type' => 'storage',
|
||||||
'attributes' => [
|
'attributes' => [
|
||||||
'used' => Metric::bytes($this->usedCapacity)->format(),
|
'used' => Metric::bytes($this->usedCapacity)->format(),
|
||||||
'capacity' => format_gigabytes($totalCapacity),
|
'capacity' => format_gigabytes($totalCapacity),
|
||||||
'percentage' => (float)get_storage_percentage($this->usedCapacity, $totalCapacity),
|
'percentage' => (float) get_storage_percentage($this->usedCapacity, $totalCapacity),
|
||||||
],
|
],
|
||||||
'meta' => [
|
'meta' => [
|
||||||
'traffic' => [
|
'traffic' => [
|
||||||
@@ -46,23 +44,23 @@ class UserStorageResource extends JsonResource
|
|||||||
],
|
],
|
||||||
'images' => [
|
'images' => [
|
||||||
'used' => Metric::bytes($images)->format(),
|
'used' => Metric::bytes($images)->format(),
|
||||||
'percentage' => (float)get_storage_percentage($images, $totalCapacity),
|
'percentage' => (float) get_storage_percentage($images, $totalCapacity),
|
||||||
],
|
],
|
||||||
'audios' => [
|
'audios' => [
|
||||||
'used' => Metric::bytes($audios)->format(),
|
'used' => Metric::bytes($audios)->format(),
|
||||||
'percentage' => (float)get_storage_percentage($audios, $totalCapacity),
|
'percentage' => (float) get_storage_percentage($audios, $totalCapacity),
|
||||||
],
|
],
|
||||||
'videos' => [
|
'videos' => [
|
||||||
'used' => Metric::bytes($videos)->format(),
|
'used' => Metric::bytes($videos)->format(),
|
||||||
'percentage' => (float)get_storage_percentage($videos, $totalCapacity),
|
'percentage' => (float) get_storage_percentage($videos, $totalCapacity),
|
||||||
],
|
],
|
||||||
'documents' => [
|
'documents' => [
|
||||||
'used' => Metric::bytes($documents)->format(),
|
'used' => Metric::bytes($documents)->format(),
|
||||||
'percentage' => (float)get_storage_percentage($documents, $totalCapacity),
|
'percentage' => (float) get_storage_percentage($documents, $totalCapacity),
|
||||||
],
|
],
|
||||||
'others' => [
|
'others' => [
|
||||||
'used' => Metric::bytes($others)->format(),
|
'used' => Metric::bytes($others)->format(),
|
||||||
'percentage' => (float)get_storage_percentage($others, $totalCapacity),
|
'percentage' => (float) get_storage_percentage($others, $totalCapacity),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
@@ -134,12 +132,12 @@ class UserStorageResource extends JsonResource
|
|||||||
->orderBy('created_at')
|
->orderBy('created_at')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$upload = $trafficRecords->map(fn($record) => [
|
$upload = $trafficRecords->map(fn ($record) => [
|
||||||
'created_at' => format_date($record->created_at),
|
'created_at' => format_date($record->created_at),
|
||||||
'amount' => $uploadMax !== 0 ? round(($record->upload / $uploadMax) * 100, 2) : 0,
|
'amount' => $uploadMax !== 0 ? round(($record->upload / $uploadMax) * 100, 2) : 0,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$download = $trafficRecords->map(fn($record) => [
|
$download = $trafficRecords->map(fn ($record) => [
|
||||||
'created_at' => format_date($record->created_at),
|
'created_at' => format_date($record->created_at),
|
||||||
'amount' => $downloadMax !== 0 ? round(($record->download / $downloadMax) * 100, 2) : 0,
|
'amount' => $downloadMax !== 0 ? round(($record->download / $downloadMax) * 100, 2) : 0,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Domain\Admin\Controllers\Dashboard;
|
namespace Domain\Admin\Controllers\Dashboard;
|
||||||
|
|
||||||
use ByteUnits\Metric;
|
use ByteUnits\Metric;
|
||||||
use App\Users\Models\User;
|
use App\Users\Models\User;
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
|
||||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
|
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||||
use VueFileManager\Subscription\Domain\Subscriptions\Models\Subscription;
|
use VueFileManager\Subscription\Domain\Subscriptions\Models\Subscription;
|
||||||
|
|
||||||
class GetDashboardDataController extends Controller
|
class GetDashboardDataController extends Controller
|
||||||
@@ -61,16 +60,17 @@ class GetDashboardDataController extends Controller
|
|||||||
->select(
|
->select(
|
||||||
DB::raw('DATE(created_at) as created_at'),
|
DB::raw('DATE(created_at) as created_at'),
|
||||||
DB::raw('sum(download) as download'),
|
DB::raw('sum(download) as download'),
|
||||||
DB::raw('sum(upload) as upload'))
|
DB::raw('sum(upload) as upload')
|
||||||
|
)
|
||||||
->groupBy('created_at')
|
->groupBy('created_at')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$upload = $trafficRecords->map(fn($record) => [
|
$upload = $trafficRecords->map(fn ($record) => [
|
||||||
'created_at' => format_date($record->created_at, '%d. %B. %Y'),
|
'created_at' => format_date($record->created_at, '%d. %B. %Y'),
|
||||||
'amount' => intval($trafficRecords->max('upload')) !== 0 ? round(($record->upload / $trafficRecords->max('upload')) * 100, 2) : 0,
|
'amount' => intval($trafficRecords->max('upload')) !== 0 ? round(($record->upload / $trafficRecords->max('upload')) * 100, 2) : 0,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$download = $trafficRecords->map(fn($record) => [
|
$download = $trafficRecords->map(fn ($record) => [
|
||||||
'created_at' => format_date($record->created_at, '%d. %B. %Y'),
|
'created_at' => format_date($record->created_at, '%d. %B. %Y'),
|
||||||
'amount' => intval($trafficRecords->max('download')) !== 0 ? round(($record->download / $trafficRecords->max('download')) * 100, 2) : 0,
|
'amount' => intval($trafficRecords->max('download')) !== 0 ? round(($record->download / $trafficRecords->max('download')) * 100, 2) : 0,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ class StoreSocialServiceCredentialsController
|
|||||||
if (! app()->runningUnitTests()) {
|
if (! app()->runningUnitTests()) {
|
||||||
$credentials = [
|
$credentials = [
|
||||||
'facebook' => [
|
'facebook' => [
|
||||||
'FACEBOOK_CLIENT_ID' => $request->input('client_id'),
|
'FACEBOOK_CLIENT_ID' => $request->input('client_id'),
|
||||||
'FACEBOOK_CLIENT_SECRET' => $request->input('client_secret'),
|
'FACEBOOK_CLIENT_SECRET' => $request->input('client_secret'),
|
||||||
],
|
],
|
||||||
'google' => [
|
'google' => [
|
||||||
'GOOGLE_CLIENT_ID' => $request->input('client_id'),
|
'GOOGLE_CLIENT_ID' => $request->input('client_id'),
|
||||||
'GOOGLE_CLIENT_SECRET' => $request->input('client_secret'),
|
'GOOGLE_CLIENT_SECRET' => $request->input('client_secret'),
|
||||||
],
|
],
|
||||||
'github' => [
|
'github' => [
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Domain\Settings\Requests;
|
namespace Domain\Settings\Requests;
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|||||||
@@ -139,9 +139,14 @@ class UserAccountTest extends TestCase
|
|||||||
'id' => (string) $user->id,
|
'id' => (string) $user->id,
|
||||||
'type' => 'user',
|
'type' => 'user',
|
||||||
'attributes' => [
|
'attributes' => [
|
||||||
'avatar' => null,
|
'avatar' => [
|
||||||
|
'md' => 'http://localhost/assets/images/default-avatar.png',
|
||||||
|
'sm' => 'http://localhost/assets/images/default-avatar.png',
|
||||||
|
'xs' => 'http://localhost/assets/images/default-avatar.png',
|
||||||
|
],
|
||||||
'email' => $user->email,
|
'email' => $user->email,
|
||||||
'role' => $user->role,
|
'role' => $user->role,
|
||||||
|
'socialite_account' => false,
|
||||||
'two_factor_authentication' => false,
|
'two_factor_authentication' => false,
|
||||||
'folders' => [],
|
'folders' => [],
|
||||||
'storage' => [
|
'storage' => [
|
||||||
@@ -151,9 +156,21 @@ class UserAccountTest extends TestCase
|
|||||||
'capacity_formatted' => '1GB',
|
'capacity_formatted' => '1GB',
|
||||||
],
|
],
|
||||||
'created_at' => format_date($user->created_at, '%d. %b. %Y'),
|
'created_at' => format_date($user->created_at, '%d. %b. %Y'),
|
||||||
'updated_at' => format_date($user->updated_at, '%d. %b. %Y'),
|
'updated_at' => format_date($user->updated_at, '%d. %B. %Y'),
|
||||||
|
],
|
||||||
|
'meta' => [
|
||||||
|
'restrictions' => [
|
||||||
|
'canCreateFolder' => true,
|
||||||
|
'canCreateTeamFolder' => true,
|
||||||
|
'canDownload' => true,
|
||||||
|
'canInviteTeamMembers' => true,
|
||||||
|
'canUpload' => true,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'relationships' => [
|
'relationships' => [
|
||||||
|
'creditCards' => [
|
||||||
|
'data' => [],
|
||||||
|
],
|
||||||
'settings' => [
|
'settings' => [
|
||||||
'data' => [
|
'data' => [
|
||||||
'id' => (string) $user->id,
|
'id' => (string) $user->id,
|
||||||
@@ -174,13 +191,6 @@ class UserAccountTest extends TestCase
|
|||||||
'favourites' => [
|
'favourites' => [
|
||||||
'data' => [],
|
'data' => [],
|
||||||
],
|
],
|
||||||
'limitations' => [
|
|
||||||
'id' => $user->id,
|
|
||||||
'type' => 'limitations',
|
|
||||||
'data' => [
|
|
||||||
'attributes' => $user->limitations,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -131,6 +131,14 @@ class AdminTest extends TestCase
|
|||||||
'used' => '1.00MB',
|
'used' => '1.00MB',
|
||||||
'percentage' => 0.1,
|
'percentage' => 0.1,
|
||||||
],
|
],
|
||||||
|
'traffic' => [
|
||||||
|
'chart' => [
|
||||||
|
'download' => [],
|
||||||
|
'upload' => [],
|
||||||
|
],
|
||||||
|
'download' => '0B',
|
||||||
|
'upload' => '0B',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ namespace Tests\Domain\Admin;
|
|||||||
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use App\Users\Models\User;
|
use App\Users\Models\User;
|
||||||
use Laravel\Sanctum\Sanctum;
|
|
||||||
use Domain\Files\Models\File;
|
use Domain\Files\Models\File;
|
||||||
|
|
||||||
class DashboardTest extends TestCase
|
class DashboardTest extends TestCase
|
||||||
@@ -25,11 +24,26 @@ class DashboardTest extends TestCase
|
|||||||
->getJson('/api/admin/dashboard')
|
->getJson('/api/admin/dashboard')
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertExactJson([
|
->assertExactJson([
|
||||||
'license' => 'extended',
|
'app' => [
|
||||||
'total_premium_users' => 0,
|
'earnings' => '$0.00',
|
||||||
'app_version' => config('vuefilemanager.version'),
|
'license' => 'extended',
|
||||||
'total_users' => 1,
|
'version' => config('vuefilemanager.version'),
|
||||||
'total_used_space' => '2.00MB',
|
],
|
||||||
|
'disk' => [
|
||||||
|
'download' => [
|
||||||
|
'records' => [],
|
||||||
|
'total' => '0B',
|
||||||
|
],
|
||||||
|
'upload' => [
|
||||||
|
'records' => [],
|
||||||
|
'total' => '0B',
|
||||||
|
],
|
||||||
|
'used' => '2.00MB',
|
||||||
|
],
|
||||||
|
'users' => [
|
||||||
|
'total' => 1,
|
||||||
|
'usersPremiumTotal' => 0,
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,20 +53,21 @@ class DashboardTest extends TestCase
|
|||||||
public function it_get_new_users_for_dashboard()
|
public function it_get_new_users_for_dashboard()
|
||||||
{
|
{
|
||||||
$users = User::factory()
|
$users = User::factory()
|
||||||
->count(5)
|
->count(3)
|
||||||
->create(['role' => 'user']);
|
->create(['role' => 'user']);
|
||||||
|
|
||||||
$admin = User::factory()
|
$admin = User::factory()
|
||||||
->create(['role' => 'admin']);
|
->create(['role' => 'admin']);
|
||||||
|
|
||||||
Sanctum::actingAs($admin);
|
$users->each(
|
||||||
|
fn ($user) =>
|
||||||
$users->each(function ($user) {
|
$this
|
||||||
$this->getJson('/api/admin/dashboard/newbies')
|
->actingAs($admin)
|
||||||
|
->getJson('/api/admin/dashboard/newbies')
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertJsonFragment([
|
->assertJsonFragment([
|
||||||
'id' => $user->id,
|
'id' => $user->id,
|
||||||
]);
|
])
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Domain\Settings;
|
namespace Tests\Domain\Settings;
|
||||||
|
|
||||||
use Storage;
|
use Storage;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Support\Scheduler;
|
namespace Tests\Support\Scheduler;
|
||||||
|
|
||||||
use Storage;
|
use Storage;
|
||||||
|
|||||||
Reference in New Issue
Block a user