mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 08:12:15 +00:00
Limitation API skelet with can upload tests
This commit is contained in:
88
tests/App/Limitations/DefaultLimitationTest.php
Normal file
88
tests/App/Limitations/DefaultLimitationTest.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace Tests\App\Limitations;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Settings\Models\Setting;
|
||||
|
||||
class DefaultLimitationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_can_upload()
|
||||
{
|
||||
$user = User::factory()
|
||||
->create();
|
||||
|
||||
$this->assertEquals(true, $user->canUpload(9999999));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_cant_upload_because_storage_limit_exceeded()
|
||||
{
|
||||
$user = User::factory()
|
||||
->create();
|
||||
|
||||
File::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'filesize' => 99999999,
|
||||
]);
|
||||
|
||||
$this->assertEquals(false, $user->canUpload(999999999));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_can_upload_because_storage_limitation_is_turned_off_and_user_has_unlimited_limit()
|
||||
{
|
||||
$user = User::factory()
|
||||
->create();
|
||||
|
||||
// Turn off storage limitation
|
||||
Setting::updateOrCreate([
|
||||
'name' => 'storage_limitation',
|
||||
], [
|
||||
'value' => 0,
|
||||
]);
|
||||
|
||||
File::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'filesize' => 99999999,
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $user->limitations->max_storage_amount);
|
||||
$this->assertEquals(true, $user->canUpload(999999999));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_cant_upload_because_storage_limitation_is_turned_on_and_user_exceeded_limit()
|
||||
{
|
||||
$user = User::factory()
|
||||
->create();
|
||||
|
||||
// Turn on storage limitation
|
||||
Setting::updateOrCreate([
|
||||
'name' => 'storage_limitation',
|
||||
], [
|
||||
'value' => 1,
|
||||
]);
|
||||
|
||||
File::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'filesize' => 99999999,
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $user->limitations->max_storage_amount);
|
||||
$this->assertEquals(false, $user->canUpload(999999999));
|
||||
}
|
||||
}
|
||||
49
tests/App/Limitations/FixedBillingLimitationTest.php
Normal file
49
tests/App/Limitations/FixedBillingLimitationTest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Tests\App\Limitations;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Settings\Models\Setting;
|
||||
|
||||
class FixedBillingLimitationTest extends TestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Setting::updateOrCreate([
|
||||
'name' => 'subscription_type',
|
||||
], [
|
||||
'value' => 'fixed',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_can_upload()
|
||||
{
|
||||
$user = User::factory()
|
||||
->create();
|
||||
|
||||
$this->assertEquals(true, $user->canUpload(9999999));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_cant_upload_because_storage_limit_exceeded()
|
||||
{
|
||||
$user = User::factory()
|
||||
->create();
|
||||
|
||||
File::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'filesize' => 99999999,
|
||||
]);
|
||||
|
||||
$this->assertEquals(false, $user->canUpload(999999999));
|
||||
}
|
||||
}
|
||||
47
tests/App/Limitations/LimitationTest.php
Normal file
47
tests/App/Limitations/LimitationTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Tests\App\Limitations;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Domain\Settings\Models\Setting;
|
||||
|
||||
class LimitationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_metered_driver()
|
||||
{
|
||||
Setting::updateOrCreate([
|
||||
'name' => 'subscription_type',
|
||||
], [
|
||||
'value' => 'metered',
|
||||
]);
|
||||
|
||||
$this->assertEquals('metered', get_limitation_driver());
|
||||
}
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_fixed_driver()
|
||||
{
|
||||
Setting::updateOrCreate([
|
||||
'name' => 'subscription_type',
|
||||
], [
|
||||
'value' => 'fixed',
|
||||
]);
|
||||
|
||||
$this->assertEquals('fixed', get_limitation_driver());
|
||||
}
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_default_driver()
|
||||
{
|
||||
$subscriptionType = Setting::where('name', 'subscription_type')
|
||||
->first();
|
||||
|
||||
$subscriptionType?->delete();
|
||||
|
||||
$this->assertEquals('default', get_limitation_driver());
|
||||
}
|
||||
}
|
||||
43
tests/App/Limitations/MeteredBillingLimitationTest.php
Normal file
43
tests/App/Limitations/MeteredBillingLimitationTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace Tests\App\Limitations;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MeteredBillingLimitationTest extends TestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
DB::table('settings')->insert([
|
||||
'name' => 'subscription_type',
|
||||
'value' => 'metered',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_can_upload()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasFailedpayments(2)
|
||||
->create();
|
||||
|
||||
$this->assertEquals(true, $user->canUpload());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_cant_upload_because_user_has_3_failed_payments()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasFailedpayments(3)
|
||||
->create();
|
||||
|
||||
$this->assertEquals(false, $user->canUpload());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user