- Refactoring

- Download restriction
This commit is contained in:
Čarodej
2022-01-05 18:29:07 +01:00
parent ec29764c3f
commit 29a954e21b
15 changed files with 400 additions and 176 deletions

View File

@@ -1,112 +0,0 @@
<?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());
}
/**
* @test
*/
public function it_can_create_new_folder()
{
$user = User::factory()
->create();
// Create basic folder
$this
->actingAs($user)
->postJson('/api/create-folder', [
'name' => 'New Folder',
])
->assertStatus(201);
// Create team folder
$this
->actingAs($user)
->postJson('/api/teams/folders', [
'name' => 'New Team Folder',
'invitations' => [
[
'email' => 'john@doe.com',
'permission' => 'can-edit',
'type' => 'invitation',
],
],
])
->assertStatus(201);
$this->assertDatabaseCount('folders', 2);
}
/**
* @test
*/
public function it_cant_create_new_folder_because_user_has_3_failed_payments()
{
$user = User::factory()
->hasFailedpayments(3)
->create();
// Create basic folder
$this
->actingAs($user)
->postJson('/api/create-folder', [
'name' => 'New Folder',
])
->assertStatus(401);
// Create team folder
$this
->actingAs($user)
->postJson('/api/teams/folders', [
'name' => 'New Folder',
'invitations' => [
[
'email' => 'john@doe.com',
'permission' => 'can-edit',
'type' => 'invitation',
],
],
])
->assertStatus(401);
$this->assertDatabaseCount('folders', 0);
}
}

View File

@@ -1,13 +1,14 @@
<?php
namespace Tests\App\Limitations;
namespace Tests\App\Restrictions;
use Tests\TestCase;
use App\Users\Models\User;
use Domain\Files\Models\File;
use Domain\Sharing\Models\Share;
use Domain\Settings\Models\Setting;
use Domain\Teams\Models\TeamFolderMember;
class DefaultLimitationTest extends TestCase
class DefaultRestrictionsTest extends TestCase
{
/**
* @test
@@ -130,10 +131,10 @@ class DefaultLimitationTest extends TestCase
->create()
->each(
fn ($member) => TeamFolderMember::factory()
->create([
'parent_id' => $user->folders[0]->id,
'user_id' => $member->id,
])
->create([
'parent_id' => $user->folders[0]->id,
'user_id' => $member->id,
])
);
// Try invite new members, it has to fail
@@ -184,4 +185,54 @@ class DefaultLimitationTest extends TestCase
])
->assertCreated();
}
/**
* @test
*/
public function it_can_get_private_file()
{
$user = User::factory()
->create();
$file = File::factory()
->create([
'user_id' => $user->id,
'basename' => 'fake-file.pdf',
'name' => 'fake-file.pdf',
]);
// 404 but, ok, because there is not stored temporary file in test
$this
->actingAs($user)
->get("file/$file->name")
->assertStatus(404);
}
/**
* @test
*/
public function it_can_get_shared_file()
{
$user = User::factory()
->create();
$file = File::factory()
->create([
'basename' => 'fake-file.pdf',
'name' => 'fake-file.pdf',
]);
$share = Share::factory()
->create([
'item_id' => $file->id,
'user_id' => $user->id,
'type' => 'file',
'is_protected' => false,
]);
// 404 but, ok, because there is not stored temporary file in test
$this
->get("file/$file->name/$share->token")
->assertStatus(404);
}
}

View File

@@ -1,13 +1,14 @@
<?php
namespace Tests\App\Limitations;
namespace Tests\App\Restrictions;
use Tests\TestCase;
use App\Users\Models\User;
use Domain\Files\Models\File;
use Domain\Sharing\Models\Share;
use Domain\Settings\Models\Setting;
use Domain\Teams\Models\TeamFolderMember;
class FixedBillingLimitationTest extends TestCase
class FixedBillingRestrictionsTest extends TestCase
{
public function setUp(): void
{
@@ -91,10 +92,10 @@ class FixedBillingLimitationTest extends TestCase
->create()
->each(
fn ($member) => TeamFolderMember::factory()
->create([
'parent_id' => $user->folders[0]->id,
'user_id' => $member->id,
])
->create([
'parent_id' => $user->folders[0]->id,
'user_id' => $member->id,
])
);
// Try invite new members, it has to fail
@@ -145,4 +146,54 @@ class FixedBillingLimitationTest extends TestCase
])
->assertCreated();
}
/**
* @test
*/
public function it_can_get_private_file()
{
$user = User::factory()
->create();
$file = File::factory()
->create([
'user_id' => $user->id,
'basename' => 'fake-file.pdf',
'name' => 'fake-file.pdf',
]);
// 404 but, ok, because there is not stored temporary file in test
$this
->actingAs($user)
->get("file/$file->name")
->assertStatus(404);
}
/**
* @test
*/
public function it_can_get_shared_file()
{
$user = User::factory()
->create();
$file = File::factory()
->create([
'basename' => 'fake-file.pdf',
'name' => 'fake-file.pdf',
]);
$share = Share::factory()
->create([
'item_id' => $file->id,
'user_id' => $user->id,
'type' => 'file',
'is_protected' => false,
]);
// 404 but, ok, because there is not stored temporary file in test
$this
->get("file/$file->name/$share->token")
->assertStatus(404);
}
}

View File

@@ -0,0 +1,216 @@
<?php
namespace Tests\App\Restrictions;
use Tests\TestCase;
use App\Users\Models\User;
use Domain\Files\Models\File;
use Domain\Sharing\Models\Share;
use Illuminate\Support\Facades\DB;
class MeteredBillingRestrictionsTest 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());
}
/**
* @test
*/
public function it_can_create_new_folder()
{
$user = User::factory()
->create();
// Create basic folder
$this
->actingAs($user)
->postJson('/api/create-folder', [
'name' => 'New Folder',
])
->assertStatus(201);
// Create team folder
$this
->actingAs($user)
->postJson('/api/teams/folders', [
'name' => 'New Team Folder',
'invitations' => [
[
'email' => 'john@doe.com',
'permission' => 'can-edit',
'type' => 'invitation',
],
],
])
->assertStatus(201);
$this->assertDatabaseCount('folders', 2);
}
/**
* @test
*/
public function it_cant_create_new_folder_because_user_has_3_failed_payments()
{
$user = User::factory()
->hasFailedpayments(3)
->create();
// Create basic folder
$this
->actingAs($user)
->postJson('/api/create-folder', [
'name' => 'New Folder',
])
->assertStatus(401);
// Create team folder
$this
->actingAs($user)
->postJson('/api/teams/folders', [
'name' => 'New Folder',
'invitations' => [
[
'email' => 'john@doe.com',
'permission' => 'can-edit',
'type' => 'invitation',
],
],
])
->assertStatus(401);
$this->assertDatabaseCount('folders', 0);
}
/**
* @test
*/
public function it_cant_get_private_file_because_user_has_3_failed_payments()
{
$user = User::factory()
->hasFailedpayments(3)
->create();
$file = File::factory()
->create([
'user_id' => $user->id,
'basename' => 'fake-file.pdf',
'name' => 'fake-file.pdf',
]);
$this
->actingAs($user)
->get("file/$file->name")
->assertStatus(401);
}
/**
* @test
*/
public function it_can_get_private_file()
{
$user = User::factory()
->create();
$file = File::factory()
->create([
'user_id' => $user->id,
'basename' => 'fake-file.pdf',
'name' => 'fake-file.pdf',
]);
// 404 but, ok, because there is not stored temporary file in test
$this
->actingAs($user)
->get("file/$file->name")
->assertStatus(404);
}
/**
* @test
*/
public function it_cant_get_shared_file_because_user_has_3_failed_payments()
{
$user = User::factory()
->hasFailedpayments(3)
->create();
$file = File::factory()
->create([
'user_id' => $user->id,
'basename' => 'fake-file.pdf',
'name' => 'fake-file.pdf',
]);
$share = Share::factory()
->create([
'item_id' => $file->id,
'user_id' => $user->id,
'type' => 'file',
'is_protected' => false,
]);
$this
->get("file/$file->name/$share->token")
->assertStatus(401);
}
/**
* @test
*/
public function it_can_get_shared_file()
{
$user = User::factory()
->create();
$file = File::factory()
->create([
'user_id' => $user->id,
'basename' => 'fake-file.pdf',
'name' => 'fake-file.pdf',
]);
$share = Share::factory()
->create([
'item_id' => $file->id,
'user_id' => $user->id,
'type' => 'file',
'is_protected' => false,
]);
// 404 but, ok, because there is not stored temporary file in test
$this
->get("file/$file->name/$share->token")
->assertStatus(404);
}
}

View File

@@ -1,10 +1,10 @@
<?php
namespace Tests\App\Limitations;
namespace Tests\App\Restrictions;
use Tests\TestCase;
use Domain\Settings\Models\Setting;
class LimitationTest extends TestCase
class RestrictionsTest extends TestCase
{
/**
* @test
@@ -17,7 +17,7 @@ class LimitationTest extends TestCase
'value' => 'metered',
]);
$this->assertEquals('metered', get_limitation_driver());
$this->assertEquals('metered', get_restriction_driver());
}
/**
* @test
@@ -30,7 +30,7 @@ class LimitationTest extends TestCase
'value' => 'fixed',
]);
$this->assertEquals('fixed', get_limitation_driver());
$this->assertEquals('fixed', get_restriction_driver());
}
/**
* @test
@@ -42,6 +42,6 @@ class LimitationTest extends TestCase
$subscriptionType?->delete();
$this->assertEquals('default', get_limitation_driver());
$this->assertEquals('default', get_restriction_driver());
}
}