diff --git a/_ide_helper.php b/_ide_helper.php index 4d47e708..206a68c0 100644 --- a/_ide_helper.php +++ b/_ide_helper.php @@ -1769,7 +1769,7 @@ /** * Get the currently authenticated user. * - * @return \App\Models\User|null + * @return \Domain\Settings\Models\User|null * @static */ public static function user() @@ -1804,7 +1804,7 @@ * Log the given user ID into the application without sessions or cookies. * * @param mixed $id - * @return \App\Models\User|false + * @return \Domain\Settings\Models\User|false * @static */ public static function onceUsingId($id) @@ -1882,7 +1882,7 @@ * * @param mixed $id * @param bool $remember - * @return \App\Models\User|false + * @return \Domain\Settings\Models\User|false * @static */ public static function loginUsingId($id, $remember = false) @@ -1958,7 +1958,7 @@ /** * Get the last user we attempted to authenticate. * - * @return \App\Models\User + * @return \Domain\Settings\Models\User * @static */ public static function getLastAttempted() @@ -2060,7 +2060,7 @@ /** * Return the currently cached user. * - * @return \App\Models\User|null + * @return \Domain\Settings\Models\User|null * @static */ public static function getUser() @@ -2106,7 +2106,7 @@ /** * Determine if the current user is authenticated. If not, throw an exception. * - * @return \App\Models\User + * @return \Domain\Settings\Models\User * @throws \Illuminate\Auth\AuthenticationException * @static */ diff --git a/config/auth.php b/config/auth.php index 86cbc082..570109bb 100644 --- a/config/auth.php +++ b/config/auth.php @@ -67,7 +67,7 @@ return [ 'providers' => [ 'users' => [ 'driver' => 'eloquent', - 'model' => App\Models\User::class, + 'model' => Domain\Settings\Models\User::class, ], // 'users' => [ diff --git a/config/cashier.php b/config/cashier.php index f554bda0..4c7858cb 100644 --- a/config/cashier.php +++ b/config/cashier.php @@ -56,7 +56,7 @@ return [ | */ - 'model' => env('CASHIER_MODEL', App\Models\User::class), + 'model' => env('CASHIER_MODEL', Domain\Settings\Models\User::class), /* |-------------------------------------------------------------------------- diff --git a/database/factories/FileFactory.php b/database/factories/FileFactory.php index 503d8652..5d0e5739 100644 --- a/database/factories/FileFactory.php +++ b/database/factories/FileFactory.php @@ -2,7 +2,7 @@ namespace Database\Factories; -use App\Models\File; +use Domain\Settings\Models\File; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; diff --git a/database/factories/FolderFactory.php b/database/factories/FolderFactory.php index e39be4d7..0d05a767 100644 --- a/database/factories/FolderFactory.php +++ b/database/factories/FolderFactory.php @@ -2,7 +2,7 @@ namespace Database\Factories; -use App\Models\Folder; +use Domain\Settings\Models\Folder; use Illuminate\Database\Eloquent\Factories\Factory; class FolderFactory extends Factory diff --git a/database/factories/ShareFactory.php b/database/factories/ShareFactory.php index 5c0d9078..7135bce5 100644 --- a/database/factories/ShareFactory.php +++ b/database/factories/ShareFactory.php @@ -2,7 +2,7 @@ namespace Database\Factories; -use App\Models\Share; +use Domain\Settings\Models\Share; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 174da426..0ba0c558 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -2,7 +2,7 @@ namespace Database\Factories; -use App\Models\User; +use Domain\Settings\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; diff --git a/database/factories/ZipFactory.php b/database/factories/ZipFactory.php index 03551230..b973b959 100644 --- a/database/factories/ZipFactory.php +++ b/database/factories/ZipFactory.php @@ -2,7 +2,7 @@ namespace Database\Factories; -use App\Models\Zip; +use Domain\Settings\Models\Zip; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; diff --git a/src/App/Console/Commands/SetupDevEnvironment.php b/src/App/Console/Commands/SetupDevEnvironment.php index 31ec0157..01d58fb1 100644 --- a/src/App/Console/Commands/SetupDevEnvironment.php +++ b/src/App/Console/Commands/SetupDevEnvironment.php @@ -1,13 +1,13 @@ create(); - Sanctum::actingAs($user); - - $this->postJson('/logout') + $this + ->actingAs($user) + ->postJson('/logout') ->assertStatus(204); } diff --git a/tests/App/Users/UserAccountTest.php b/tests/App/Users/UserAccountTest.php index 15282f5a..3a471b1c 100644 --- a/tests/App/Users/UserAccountTest.php +++ b/tests/App/Users/UserAccountTest.php @@ -4,9 +4,9 @@ namespace Tests\Feature\Accounts; use Storage; use Notification; use Tests\TestCase; -use App\Models\User; +use Domain\Settings\Models\User; use Laravel\Sanctum\Sanctum; -use App\Services\SetupService; +use Domain\SetupWizard\Services\SetupService; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\URL; use Illuminate\Auth\Notifications\VerifyEmail; @@ -48,9 +48,9 @@ class UserAccountTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->postJson('/api/user/password', [ + $this + ->actingAs($user) + ->postJson('/api/user/password', [ 'current_password' => 'secret', 'password' => 'VerySecretPassword', 'password_confirmation' => 'VerySecretPassword', @@ -67,9 +67,9 @@ class UserAccountTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->patchJson('/api/user/relationships/settings', [ + $this + ->actingAs($user) + ->patchJson('/api/user/relationships/settings', [ 'name' => 'address', 'value' => 'Jantar', ])->assertStatus(204); @@ -84,17 +84,15 @@ class UserAccountTest extends TestCase */ public function it_update_user_avatar() { - $this->setup->create_directories(); - $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - $avatar = UploadedFile::fake() ->image('fake-image.jpg'); - $this->patchJson('/api/user/relationships/settings', [ + $this + ->actingAs($user) + ->patchJson('/api/user/relationships/settings', [ 'avatar' => $avatar, ])->assertStatus(204); diff --git a/tests/Domain/Admin/AdminTest.php b/tests/Domain/Admin/AdminTest.php index cb4bb2e8..da3a206d 100644 --- a/tests/Domain/Admin/AdminTest.php +++ b/tests/Domain/Admin/AdminTest.php @@ -1,15 +1,15 @@ 'active', ]); - Sanctum::actingAs($user); - - $this->getJson('/api/admin/dashboard') + $this + ->actingAs($user) + ->getJson('/api/admin/dashboard') ->assertStatus(200) ->assertExactJson([ "license" => 'Regular', @@ -120,10 +120,10 @@ class AdminTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - // TODO: pridat exactjson po refaktorovani userresource - $this->getJson("/api/admin/users/$user->id/detail") + $this + ->actingAs($admin) + ->getJson("/api/admin/users/$user->id/detail") ->assertStatus(200) ->assertJsonFragment([ 'id' => $user->id, @@ -141,9 +141,9 @@ class AdminTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - - $this->getJson("/api/admin/users/$user->id/subscription") + $this + ->actingAs($admin) + ->getJson("/api/admin/users/$user->id/subscription") ->assertStatus(404); } @@ -169,9 +169,9 @@ class AdminTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - - $this->getJson("/api/admin/users/$user->id/storage") + $this + ->actingAs($admin) + ->getJson("/api/admin/users/$user->id/storage") ->assertStatus(200) ->assertExactJson([ "data" => [ @@ -219,9 +219,9 @@ class AdminTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - - $this->postJson("/api/admin/users/$user->id/reset-password") + $this + ->actingAs($admin) + ->postJson("/api/admin/users/$user->id/reset-password") ->assertStatus(204); Notification::assertTimesSent(1, ResetPassword::class); @@ -238,9 +238,9 @@ class AdminTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - - $this->patchJson("/api/admin/users/$user->id/capacity", [ + $this + ->actingAs($admin) + ->patchJson("/api/admin/users/$user->id/capacity", [ 'attributes' => [ 'storage_capacity' => 10 ] @@ -263,9 +263,9 @@ class AdminTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - - $this->patchJson("/api/admin/users/$user->id/role", [ + $this + ->actingAs($admin) + ->patchJson("/api/admin/users/$user->id/role", [ 'attributes' => [ 'role' => 'admin' ] @@ -282,12 +282,12 @@ class AdminTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - $avatar = UploadedFile::fake() ->image('fake-image.jpg'); - $this->postJson("/api/admin/users/create", [ + $this + ->actingAs($admin) + ->postJson("/api/admin/users/create", [ 'name' => 'John Doe', 'role' => 'user', 'email' => 'john@doe.com', @@ -319,8 +319,6 @@ class AdminTest extends TestCase */ public function it_delete_user_with_all_data() { - $this->setup->create_directories(); - // Create and login user $user = User::factory(User::class) ->create(['role' => 'user']); @@ -462,9 +460,9 @@ class AdminTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - - $this->getJson('/api/admin/pages/terms-of-service') + $this + ->actingAs($admin) + ->getJson('/api/admin/pages/terms-of-service') ->assertStatus(200) ->assertJsonFragment([ 'slug' => 'terms-of-service' @@ -481,9 +479,9 @@ class AdminTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - - $this->patchJson('/api/admin/pages/terms-of-service', [ + $this + ->actingAs($admin) + ->patchJson('/api/admin/pages/terms-of-service', [ 'name' => 'title', 'value' => 'New Title' ])->assertStatus(204); @@ -492,147 +490,4 @@ class AdminTest extends TestCase 'title' => 'New Title' ]); } - - /** - * @test - */ - public function it_get_settings() - { - $this->setup->seed_default_settings('Extended'); - - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $this->getJson('/api/admin/settings?column=section_features|section_feature_boxes') - ->assertStatus(200) - ->assertJsonFragment([ - 'section_features' => '1', - 'section_feature_boxes' => '1', - ]); - } - - /** - * @test - */ - public function it_update_settings() - { - $this->setup->seed_default_settings('Extended'); - - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $this->patchJson('/api/admin/settings', [ - 'name' => 'header_title', - 'value' => 'New Header Title' - ])->assertStatus(204); - - $this->assertDatabaseHas('settings', [ - 'value' => 'New Header Title' - ]); - } - - /** - * @test - */ - public function it_update_settings_image() - { - $this->setup->create_directories(); - - Setting::forceCreate([ - 'name' => 'app_logo', - 'value' => null, - ]); - - $logo = UploadedFile::fake() - ->image('fake-image.jpg'); - - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $this->patchJson('/api/admin/settings', [ - 'name' => 'app_logo', - 'app_logo' => $logo - ])->assertStatus(204); - - $this->assertDatabaseMissing('settings', [ - 'app_logo' => null - ]); - - Storage::assertExists( - get_setting('app_logo') - ); - } - - /** - * @test - */ - public function it_flush_cache() - { - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $this->getJson('/api/admin/settings/flush-cache') - ->assertStatus(204); - } - - /** - * @test - */ - public function it_set_stripe() - { - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $this->postJson('/api/admin/settings/stripe', [ - 'currency' => 'EUR', - 'key' => '123456789', - 'secret' => '123456789', - 'webhookSecret' => '123456789', - ])->assertStatus(204); - - $this->assertDatabaseHas('settings', [ - 'name' => 'stripe_currency', - 'value' => 'EUR', - ]); - - $this->assertDatabaseHas('settings', [ - 'name' => 'payments_configured', - 'value' => 1, - ]); - - $this->assertDatabaseHas('settings', [ - 'name' => 'payments_active', - 'value' => 1, - ]); - } - - /** - * @test - */ - public function it_set_email() - { - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $this->postJson('/api/admin/settings/email', [ - 'driver' => 'smtp', - 'host' => 'smtp.email.com', - 'port' => 25, - 'username' => 'john@doe.com', - 'password' => 'secret', - 'encryption' => 'tls', - ])->assertStatus(204); - } } diff --git a/tests/Domain/Browsing/BrowseTest.php b/tests/Domain/Browsing/BrowseTest.php index 27ef0d3b..dffcab48 100644 --- a/tests/Domain/Browsing/BrowseTest.php +++ b/tests/Domain/Browsing/BrowseTest.php @@ -1,11 +1,11 @@ create(); - Sanctum::actingAs($user); - $folder_level_1 = Folder::factory(Folder::class) ->create([ 'name' => 'level 1', @@ -56,7 +54,9 @@ class BrowseTest extends TestCase 'user_id' => $user->id, ]); - $this->getJson("/api/browse/navigation") + $this + ->actingAs($user) + ->getJson("/api/browse/navigation") ->assertStatus(200) ->assertExactJson([ [ @@ -121,8 +121,6 @@ class BrowseTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - $root = Folder::factory(Folder::class) ->create([ 'name' => 'root', @@ -148,7 +146,9 @@ class BrowseTest extends TestCase 'user_id' => $user->id, ]); - $this->getJson("/api/browse/folders/$root->id") + $this + ->actingAs($user) + ->getJson("/api/browse/folders/$root->id") ->assertStatus(200) ->assertExactJson([ [ @@ -210,8 +210,6 @@ class BrowseTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - $root = Folder::factory(Folder::class) ->create([ 'name' => 'root', @@ -244,7 +242,9 @@ class BrowseTest extends TestCase 'created_at' => now(), ]); - $this->getJson("/api/browse/latest") + $this + ->actingAs($user) + ->getJson("/api/browse/latest") ->assertStatus(200) ->assertExactJson([ [ @@ -306,8 +306,6 @@ class BrowseTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - $file = File::factory(File::class) ->create([ "author" => "visitor", @@ -315,7 +313,9 @@ class BrowseTest extends TestCase 'user_id' => $user->id, ]); - $this->getJson("/api/browse/participants") + $this + ->actingAs($user) + ->getJson("/api/browse/participants") ->assertStatus(200) ->assertJsonFragment([ 'id' => $file->id @@ -330,8 +330,6 @@ class BrowseTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - $folder = Folder::factory(Folder::class) ->create([ 'parent_id' => null, @@ -360,7 +358,9 @@ class BrowseTest extends TestCase 'deleted_at' => now(), ]); - $this->getJson("/api/browse/trash") + $this + ->actingAs($user) + ->getJson("/api/browse/trash") ->assertStatus(200) ->assertExactJson([ [ @@ -448,15 +448,15 @@ class BrowseTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - $file = File::factory(File::class) ->create([ 'name' => 'Document', 'user_id' => $user->id, ]); - $this->getJson("/api/browse/search?query=doc") + $this + ->actingAs($user) + ->getJson("/api/browse/search?query=doc") ->assertStatus(200) ->assertJsonFragment([ 'id' => $file->id @@ -471,15 +471,15 @@ class BrowseTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - $folder = Folder::factory(Folder::class) ->create([ 'name' => 'Documents', 'user_id' => $user->id, ]); - $this->getJson("/api/browse/search?query=doc") + $this + ->actingAs($user) + ->getJson("/api/browse/search?query=doc") ->assertStatus(200) ->assertJsonFragment([ 'id' => $folder->id diff --git a/tests/Domain/Files/ContentAccessTest.php b/tests/Domain/Files/ContentAccessTest.php index 02ccb34c..a45f9fa7 100644 --- a/tests/Domain/Files/ContentAccessTest.php +++ b/tests/Domain/Files/ContentAccessTest.php @@ -1,12 +1,12 @@ setup->create_directories(); - $avatar = UploadedFile::fake() ->image('fake-avatar.jpg'); @@ -44,8 +42,6 @@ class ContentAccessTest extends TestCase */ public function it_get_public_system_image() { - $this->setup->create_directories(); - $system = UploadedFile::fake() ->image('fake-logo.jpg'); @@ -62,8 +58,6 @@ class ContentAccessTest extends TestCase */ public function it_get_private_user_file() { - $this->setup->create_directories(); - $user = User::factory(User::class) ->create(); @@ -79,9 +73,9 @@ class ContentAccessTest extends TestCase 'name' => 'fake-file.pdf', ]); - Sanctum::actingAs($user); - - $this->get("file/$file->name") + $this + ->actingAs($user) + ->get("file/$file->name") ->assertOk(); } @@ -90,8 +84,6 @@ class ContentAccessTest extends TestCase */ public function it_get_private_user_image_thumbnail() { - $this->setup->create_directories(); - $user = User::factory(User::class) ->create(); @@ -107,9 +99,9 @@ class ContentAccessTest extends TestCase 'name' => 'fake-thumbnail.jpg', ]); - Sanctum::actingAs($user); - - $this->get("thumbnail/$thumbnail->name") + $this + ->actingAs($user) + ->get("thumbnail/$thumbnail->name") ->assertStatus(200); } @@ -118,13 +110,9 @@ class ContentAccessTest extends TestCase */ public function it_get_private_user_zip() { - $this->setup->create_directories(); - $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - $file = UploadedFile::fake() ->create('archive.zip', 2000, 'application/zip'); @@ -135,7 +123,9 @@ class ContentAccessTest extends TestCase 'user_id' => $user->id, ]); - $this->get("zip/$zip->id") + $this + ->actingAs($user) + ->get("zip/$zip->id") ->assertOk(); } @@ -144,8 +134,6 @@ class ContentAccessTest extends TestCase */ public function logged_user_try_to_get_another_private_user_image_thumbnail() { - $this->setup->create_directories(); - $users = User::factory(User::class) ->count(2) ->create(); @@ -173,8 +161,6 @@ class ContentAccessTest extends TestCase */ public function logged_user_try_to_get_another_private_user_file() { - $this->setup->create_directories(); - $users = User::factory(User::class) ->count(2) ->create(); @@ -202,13 +188,9 @@ class ContentAccessTest extends TestCase */ public function logged_user_try_to_get_another_private_user_zip() { - $this->setup->create_directories(); - $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - $file = UploadedFile::fake() ->create('archive.zip', 2000, 'application/zip'); @@ -218,7 +200,9 @@ class ContentAccessTest extends TestCase 'basename' => 'EHWKcuvKzA4Gv29v-archive.zip', ]); - $this->get("zip/$zip->id") + $this + ->actingAs($user) + ->get("zip/$zip->id") ->assertNotFound(); } diff --git a/tests/Domain/Files/FileTest.php b/tests/Domain/Files/FileTest.php index a68f0f7c..20759c85 100644 --- a/tests/Domain/Files/FileTest.php +++ b/tests/Domain/Files/FileTest.php @@ -1,13 +1,12 @@ setup->create_directories(); - $file = UploadedFile::fake() ->image('fake-image.jpg'); $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->postJson('/api/upload', [ + $this + ->actingAs($user) + ->postJson('/api/upload', [ 'filename' => $file->name, 'file' => $file, 'folder_id' => null, @@ -80,17 +77,15 @@ class FileTest extends TestCase */ public function it_upload_new_file() { - $this->setup->create_directories(); - $file = UploadedFile::fake() ->create('fake-file.pdf', 1200, 'application/pdf'); $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->postJson('/api/upload', [ + $this + ->actingAs($user) + ->postJson('/api/upload', [ 'filename' => $file->name, 'file' => $file, 'folder_id' => null, @@ -117,8 +112,6 @@ class FileTest extends TestCase */ public function it_upload_blacklisted_mimetype_file() { - $this->setup->create_directories(); - Setting::create([ 'name' => 'mimetypes_blacklist', 'value' => 'pdf', @@ -130,9 +123,9 @@ class FileTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->postJson('/api/upload', [ + $this + ->actingAs($user) + ->postJson('/api/upload', [ 'file' => $file, 'folder_id' => null, 'is_last' => true, @@ -153,9 +146,9 @@ class FileTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->patchJson("/api/rename/{$file->id}", [ + $this + ->actingAs($user) + ->patchJson("/api/rename/{$file->id}", [ 'name' => 'Renamed Item', 'type' => 'file', ]) @@ -183,9 +176,9 @@ class FileTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->postJson("/api/move", [ + $this + ->actingAs($user) + ->postJson("/api/move", [ 'to_id' => $folder->id, 'items' => [ [ @@ -213,9 +206,9 @@ class FileTest extends TestCase ->count(2) ->create(); - Sanctum::actingAs($user); - - $this->postJson("/api/remove", [ + $this + ->actingAs($user) + ->postJson("/api/remove", [ 'items' => [ [ 'id' => $files[0]->id, @@ -243,8 +236,6 @@ class FileTest extends TestCase */ public function it_delete_multiple_files_hardly() { - $this->setup->create_directories(); - $user = User::factory(User::class) ->create(); @@ -294,46 +285,4 @@ class FileTest extends TestCase ); }); } - - /** - * @test - */ - public function it_zip_multiple_files_and_download_it() - { - $this->setup->create_directories(); - - $user = User::factory(User::class) - ->create(); - - Sanctum::actingAs($user); - - collect([0, 1]) - ->each(function ($index) { - - $file = UploadedFile::fake() - ->create("fake-file-$index.pdf", 1200, 'application/pdf'); - - $this->postJson('/api/upload', [ - 'filename' => $file->name, - 'file' => $file, - 'folder_id' => null, - 'is_last' => true, - ])->assertStatus(201); - }); - - $file_ids = File::all()->pluck('id'); - - $this->postJson("/api/zip/files", [ - 'items' => $file_ids, - ])->assertStatus(201); - - $this->assertDatabaseHas('zips', [ - 'user_id' => $user->id - ]); - - Storage::disk('local') - ->assertExists( - 'zip/' . Zip::first()->basename - ); - } } diff --git a/tests/Domain/Folders/FolderTest.php b/tests/Domain/Folders/FolderTest.php index ab370da3..91b693b4 100644 --- a/tests/Domain/Folders/FolderTest.php +++ b/tests/Domain/Folders/FolderTest.php @@ -1,12 +1,12 @@ create(); - Sanctum::actingAs($user); - - $this->postJson('/api/create-folder', [ + $this + ->actingAs($user) + ->postJson('/api/create-folder', [ 'name' => 'New Folder', 'parent_id' => null, ]) @@ -70,9 +70,9 @@ class FolderTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->patchJson("/api/rename/{$folder->id}", [ + $this + ->actingAs($user) + ->patchJson("/api/rename/{$folder->id}", [ 'name' => 'Renamed Folder', 'type' => 'folder', ]) @@ -97,15 +97,15 @@ class FolderTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - $emoji_fragment = [ 'category' => 'Smileys & Emotion (face-smiling)', 'char' => '😁', 'name' => 'beaming face with smiling eyes', ]; - $this->patchJson("/api/rename/{$folder->id}", [ + $this + ->actingAs($user) + ->patchJson("/api/rename/{$folder->id}", [ 'name' => 'Renamed Folder', 'type' => 'folder', 'emoji' => $emoji_fragment @@ -133,9 +133,9 @@ class FolderTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->patchJson("/api/rename/{$folder->id}", [ + $this + ->actingAs($user) + ->patchJson("/api/rename/{$folder->id}", [ 'name' => 'Folder Name', 'type' => 'folder', 'color' => '#AD6FFE' @@ -164,9 +164,9 @@ class FolderTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->postJson("/api/folders/favourites", [ + $this + ->actingAs($user) + ->postJson("/api/folders/favourites", [ 'folders' => [ $folder->id ], @@ -189,13 +189,13 @@ class FolderTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - $user ->favouriteFolders() ->attach($folder->id); - $this->deleteJson("/api/folders/favourites/$folder->id") + $this + ->actingAs($user) + ->deleteJson("/api/folders/favourites/$folder->id") ->assertStatus(204); $this->assertDatabaseMissing('favourite_folder', [ @@ -218,9 +218,9 @@ class FolderTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->postJson("/api/move", [ + $this + ->actingAs($user) + ->postJson("/api/move", [ 'to_id' => $root->id, 'items' => [ [ @@ -252,9 +252,9 @@ class FolderTest extends TestCase $user->favouriteFolders()->attach($folder_1->id); $user->favouriteFolders()->attach($folder_2->id); - Sanctum::actingAs($user); - - $this->postJson("/api/remove", [ + $this + ->actingAs($user) + ->postJson("/api/remove", [ 'items' => [ [ 'id' => $folder_1->id, @@ -296,9 +296,9 @@ class FolderTest extends TestCase $folder_2 = Folder::factory(Folder::class) ->create(); - Sanctum::actingAs($user); - - $this->postJson("/api/remove", [ + $this + ->actingAs($user) + ->postJson("/api/remove", [ 'items' => [ [ 'id' => $folder_1->id, @@ -330,8 +330,6 @@ class FolderTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - $folder_root = Folder::factory(Folder::class) ->create([ 'user_id' => $user->id @@ -355,7 +353,9 @@ class FolderTest extends TestCase 'user_id' => $user->id, ]); - $this->postJson("/api/remove", [ + $this + ->actingAs($user) + ->postJson("/api/remove", [ 'items' => [ [ 'id' => $folder_root->id, @@ -385,8 +385,6 @@ class FolderTest extends TestCase */ public function it_delete_folder_with_their_content_within_hardly() { - $this->setup->create_directories(); - $user = User::factory(User::class) ->create(); @@ -452,48 +450,4 @@ class FolderTest extends TestCase ]); }); } - - /** - * @test - */ - public function it_zip_folder_with_content_within_and_download() - { - $this->setup->create_directories(); - - $user = User::factory(User::class) - ->create(); - - Sanctum::actingAs($user); - - $folder = Folder::factory(Folder::class) - ->create([ - 'user_id' => $user->id - ]); - - collect([0, 1]) - ->each(function ($index) use ($folder) { - - $file = UploadedFile::fake() - ->create("fake-file-$index.pdf", 1200, 'application/pdf'); - - $this->postJson('/api/upload', [ - 'filename' => $file->name, - 'file' => $file, - 'folder_id' => $folder->id, - 'is_last' => true, - ])->assertStatus(201); - }); - - $this->getJson("/api/zip/folder/$folder->id") - ->assertStatus(201); - - $this->assertDatabaseHas('zips', [ - 'user_id' => $user->id - ]); - - Storage::disk('local') - ->assertExists( - 'zip/' . Zip::first()->basename - ); - } } diff --git a/tests/Domain/Homepage/HomepageTest.php b/tests/Domain/Homepage/HomepageTest.php index f4ab956c..5c484a1c 100644 --- a/tests/Domain/Homepage/HomepageTest.php +++ b/tests/Domain/Homepage/HomepageTest.php @@ -1,14 +1,14 @@ assertSee('This link is protected by password'); } - /** - * @test - */ - public function it_get_legal_page() - { - $this->setup->seed_default_pages(); - - $this->getJson('/api/page/terms-of-service') - ->assertStatus(200) - ->assertJsonFragment([ - 'title' => 'Terms of Service', - ]); - } - /** * @test */ @@ -178,41 +164,4 @@ class HomepageTest extends TestCase Mail::assertSent(SendContactMessage::class); } - - /** - * @test - */ - public function it_get_settings() - { - Setting::create([ - 'name' => 'get_started_title', - 'value' => 'Hello World!', - ]); - - Setting::create([ - 'name' => 'pricing_description', - 'value' => 'Give me a money!', - ]); - - $this->getJson('/api/content?column=get_started_title|pricing_description') - ->assertStatus(200) - ->assertExactJson([ - "get_started_title" => "Hello World!", - "pricing_description" => "Give me a money!", - ]); - } - - /** - * @test - */ - public function it_try_get_secured_settings_via_public_api() - { - Setting::create([ - 'name' => 'purchase_code', - 'value' => '15a53561-d387-4e0a-8de1-5d1bff34c1ed', - ]); - - $this->getJson('/api/content?column=purchase_code') - ->assertStatus(401); - } } diff --git a/tests/Domain/Invoices/UserInvoicesTest.php b/tests/Domain/Invoices/UserInvoicesTest.php new file mode 100644 index 00000000..2f91660f --- /dev/null +++ b/tests/Domain/Invoices/UserInvoicesTest.php @@ -0,0 +1,37 @@ +create($this->user); + + Sanctum::actingAs($user); + + $this->postJson('/api/user/subscription/upgrade', [ + 'billing' => $this->billing, + 'plan' => $this->plan, + 'payment' => [ + 'type' => 'stripe', + ], + ])->assertStatus(204); + + $this->getJson('/api/user/invoices') + ->assertStatus(200) + ->assertJsonFragment([ + 'customer' => $this->user['stripe_id'] + ]); + } +} \ No newline at end of file diff --git a/tests/Domain/Languages/LanguagesTest.php b/tests/Domain/Languages/AdminLanguageTranslatorTest.php similarity index 58% rename from tests/Domain/Languages/LanguagesTest.php rename to tests/Domain/Languages/AdminLanguageTranslatorTest.php index 5d7bc47f..1eeb0cec 100644 --- a/tests/Domain/Languages/LanguagesTest.php +++ b/tests/Domain/Languages/AdminLanguageTranslatorTest.php @@ -1,23 +1,16 @@ setup = app()->make(SetupService::class); - } /** * @test @@ -32,9 +25,9 @@ class LanguagesTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - - $this->postJson('/api/admin/languages', [ + $this + ->actingAs($admin) + ->postJson('/api/admin/languages', [ 'name' => 'Slovenčina', 'locale' => 'sk', ]) @@ -66,11 +59,11 @@ class LanguagesTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - $language = Language::first(); - $this->patchJson("/api/admin/languages/$language->id", [ + $this + ->actingAs($admin) + ->patchJson("/api/admin/languages/$language->id", [ 'name' => 'name', 'value' => 'Slovenčina', ]) @@ -98,9 +91,9 @@ class LanguagesTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - - $this->deleteJson("/api/admin/languages/$language->id") + $this + ->actingAs($admin) + ->deleteJson("/api/admin/languages/$language->id") ->assertStatus(204); $this->assertDatabaseMissing('languages', [ @@ -125,11 +118,11 @@ class LanguagesTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - $language = Language::first(); - $this->deleteJson("/api/admin/languages/$language->id") + $this + ->actingAs($admin) + ->deleteJson("/api/admin/languages/$language->id") ->assertStatus(401); } @@ -143,9 +136,9 @@ class LanguagesTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - - $this->getJson('/api/admin/languages') + $this + ->actingAs($admin) + ->getJson('/api/admin/languages') ->assertStatus(200) ->assertJsonFragment([ "locale" => "en", @@ -163,11 +156,11 @@ class LanguagesTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - $language = Language::first(); - $this->patchJson("/api/admin/languages/$language->id/strings", [ + $this + ->actingAs($admin) + ->patchJson("/api/admin/languages/$language->id/strings", [ 'name' => 'actions.close', 'value' => 'Close It, now!', ]); @@ -189,86 +182,15 @@ class LanguagesTest extends TestCase $admin = User::factory(User::class) ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - $language = Language::first(); - $this->getJson("/api/admin/languages/$language->id") + $this + ->actingAs($admin) + ->getJson("/api/admin/languages/$language->id") ->assertStatus(200) ->assertJsonFragment([ "actions.close" => "Close", "locale" => "en", ]); } - - /** - * @test - */ - public function it_get_language_translations_for_frontend() - { - $this->setup->seed_default_language(); - - $this->getJson("/translations/en") - ->assertStatus(200) - ->assertJsonFragment([ - "actions.close" => "Close", - ]); - } - - /** - * @test - */ - public function it_get_custom_translations_from_file_config() - { - $this->setup->seed_default_language(); - - $this->assertDatabaseHas('language_translations', [ - 'key' => 'custom', - 'value' => 'translation', - 'lang' => 'en', - ]); - } - - /** - * @test - */ - public function it_get_translated_string_from_t_helper_function() - { - $this->setup->seed_default_language(); - - Language::first() - ->languageTranslations() - ->forceCreate([ - "key" => "test", - "value" => "Hi, my name is :name :surname", - "lang" => "en", - ]); - - $this->assertEquals( - 'Close', - __t('actions.close') - ); - - $this->assertEquals( - '🙋 John share some files with you. Look at it!', - __t('shared_link_email_subject', ['user' => 'John']) - ); - - $this->assertEquals( - 'Hi, my name is John Doe', - __t('test', ['name' => 'John', 'surname' => 'Doe']) - ); - } - - - /** - * @test - */ - public function it_get_translated_string_from_t_helper_without_database_connection() - { - $this->assertEquals( - __t('actions.close'), - 'Close' - ); - } -} +} \ No newline at end of file diff --git a/tests/Domain/Languages/TranslationsAccessTest.php b/tests/Domain/Languages/TranslationsAccessTest.php new file mode 100644 index 00000000..fe469c5b --- /dev/null +++ b/tests/Domain/Languages/TranslationsAccessTest.php @@ -0,0 +1,92 @@ +setup = app()->make(SetupService::class); + } + + /** + * @test + */ + public function it_get_language_translations_for_frontend() + { + $this->setup->seed_default_language(); + + $this->getJson("/translations/en") + ->assertStatus(200) + ->assertJsonFragment([ + "actions.close" => "Close", + ]); + } + + /** + * @test + */ + public function it_get_custom_translations_from_file_config() + { + $this->setup->seed_default_language(); + + $this->assertDatabaseHas('language_translations', [ + 'key' => 'custom', + 'value' => 'translation', + 'lang' => 'en', + ]); + } + + /** + * @test + */ + public function it_get_translated_string_from_t_helper_function() + { + $this->setup->seed_default_language(); + + Language::first() + ->languageTranslations() + ->forceCreate([ + "key" => "test", + "value" => "Hi, my name is :name :surname", + "lang" => "en", + ]); + + $this->assertEquals( + 'Close', + __t('actions.close') + ); + + $this->assertEquals( + '🙋 John share some files with you. Look at it!', + __t('shared_link_email_subject', ['user' => 'John']) + ); + + $this->assertEquals( + 'Hi, my name is John Doe', + __t('test', ['name' => 'John', 'surname' => 'Doe']) + ); + } + + + /** + * @test + */ + public function it_get_translated_string_from_t_helper_without_database_connection() + { + $this->assertEquals( + __t('actions.close'), + 'Close' + ); + } +} diff --git a/tests/Domain/Maintenance/AppUpgradeTest.php b/tests/Domain/Maintenance/AppUpgradeTest.php index 6515d46b..e056fec7 100644 --- a/tests/Domain/Maintenance/AppUpgradeTest.php +++ b/tests/Domain/Maintenance/AppUpgradeTest.php @@ -1,8 +1,8 @@ create(['role' => 'admin']); - Sanctum::actingAs($user); - DB::table('settings') ->insert([ [ @@ -61,7 +54,9 @@ class AppUpgradeTest extends TestCase ]); }); - $this->get('/upgrade/translations') + $this + ->actingAs($user) + ->get('/upgrade/translations') ->assertStatus(201); collect(['en', 'sk']) diff --git a/tests/Domain/Pages/PagesTest.php b/tests/Domain/Pages/PagesTest.php new file mode 100644 index 00000000..770e2a3a --- /dev/null +++ b/tests/Domain/Pages/PagesTest.php @@ -0,0 +1,25 @@ +seed_default_pages(); + + $this->getJson('/api/page/terms-of-service') + ->assertStatus(200) + ->assertJsonFragment([ + 'title' => 'Terms of Service', + ]); + } +} \ No newline at end of file diff --git a/tests/Domain/Plans/AdminPlansTest.php b/tests/Domain/Plans/AdminPlansTest.php new file mode 100644 index 00000000..38ffb314 --- /dev/null +++ b/tests/Domain/Plans/AdminPlansTest.php @@ -0,0 +1,192 @@ +create(['role' => 'admin']); + + $this + ->actingAs($admin) + ->getJson('/api/admin/plans/' . $this->plan['data']['id']) + ->assertStatus(200); + } + + /** + * + */ + public function it_create_single_plan_from_admin() + { + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + $plan_name = 'test-plan-' . Str::random(16); + + $this + ->actingAs($admin) + ->postJson('/api/admin/plans', [ + 'type' => 'plan', + 'attributes' => [ + 'name' => $plan_name, + 'price' => (string)rand(1, 99), + 'description' => 'Some random description', + 'capacity' => rand(1, 999), + ], + ]) + ->assertStatus(201) + ->assertJsonFragment([ + 'name' => $plan_name + ]); + } + + /** + * + */ + public function it_update_single_plan_from_admin() + { + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + Sanctum::actingAs($admin); + + $plan_name = 'test-plan-' . Str::random(16); + + $this->postJson('/api/admin/plans', [ + 'type' => 'plan', + 'attributes' => [ + 'name' => $plan_name, + 'price' => (string)rand(1, 99), + 'description' => 'Some random description', + 'capacity' => rand(1, 999), + ], + ]) + ->assertStatus(201) + ->assertJsonFragment([ + 'name' => $plan_name + ]); + + $this->patchJson("/api/admin/plans/" . strtolower($plan_name), [ + 'name' => 'description', + 'value' => 'updated description' + ])->assertStatus(201); + } + + /** + * + */ + public function it_get_subscribers_from_plan_from_admin() + { + $user = User::factory(User::class) + ->create($this->user); + + $this + ->actingAs($user) + ->postJson('/api/user/subscription/upgrade', [ + 'billing' => $this->billing, + 'plan' => $this->plan, + 'payment' => [ + 'type' => 'stripe', + ], + ])->assertStatus(204); + + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + $this + ->actingAs($admin) + ->getJson('/api/admin/plans/' . $this->plan['data']['id'] . '/subscribers') + ->assertStatus(200) + ->assertJsonFragment([ + 'id' => $user->id + ]); + } + + /** + * + */ + public function it_get_all_invoices_from_admin() + { + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + $this + ->actingAs($admin) + ->getJson("/api/admin/invoices") + ->assertStatus(200); + } + + /** + * + */ + public function it_get_single_user_invoice_page_from_admin() + { + $user = User::factory(User::class) + ->create($this->user); + + $invoices = $this + ->actingAs($user) + ->getJson('/api/user/invoices') + ->assertStatus(200) + ->assertJsonFragment([ + 'customer' => $this->user['stripe_id'] + ]); + + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + $invoice_id = json_decode($invoices->content(), true)['data'][0]['data']['id']; + + $this + ->actingAs($admin) + ->get("/invoice/{$this->user['stripe_id']}/$invoice_id") + ->assertStatus(200) + ->assertSee('Invoice'); + } + + /** + * + */ + public function it_get_user_invoices_from_admin() + { + $user = User::factory(User::class) + ->create($this->user); + + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + $this + ->actingAs($admin) + ->getJson("/api/admin/users/$user->id/invoices") + ->assertStatus(200) + ->assertJsonFragment([ + 'customer' => $this->user['stripe_id'] + ]); + } + + /** + * + */ + public function it_get_all_plans_from_admin() + { + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + $this + ->actingAs($admin) + ->getJson('/api/admin/plans') + ->assertStatus(200); + } +} \ No newline at end of file diff --git a/tests/Domain/Plans/PlansTest.php b/tests/Domain/Plans/PlansTest.php new file mode 100644 index 00000000..f695111f --- /dev/null +++ b/tests/Domain/Plans/PlansTest.php @@ -0,0 +1,52 @@ +getJson('/api/pricing') + ->assertStatus(200); + } + + /** + * + */ + public function it_delete_single_plan() + { + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + Sanctum::actingAs($admin); + + $plan_name = 'test-plan-' . Str::random(16); + + $this->postJson('/api/admin/plans', [ + 'type' => 'plan', + 'attributes' => [ + 'name' => $plan_name, + 'price' => (string)rand(1, 99), + 'description' => 'Some random description', + 'capacity' => rand(1, 999), + ], + ]) + ->assertStatus(201) + ->assertJsonFragment([ + 'name' => $plan_name + ]); + + $this->deleteJson("/api/admin/plans/" . strtolower($plan_name)) + ->assertStatus(204); + } +} \ No newline at end of file diff --git a/tests/Domain/Plans/SetupWizardPlansTest.php b/tests/Domain/Plans/SetupWizardPlansTest.php new file mode 100644 index 00000000..44db8d3c --- /dev/null +++ b/tests/Domain/Plans/SetupWizardPlansTest.php @@ -0,0 +1,40 @@ +postJson('/api/setup/stripe-plans', [ + 'plans' => [ + [ + 'type' => 'plan', + 'attributes' => [ + 'name' => 'test-plan-' . Str::random(), + 'price' => (string)rand(1, 99), + 'description' => 'Some random description', + 'capacity' => rand(1, 999), + ], + ], + [ + 'type' => 'plan', + 'attributes' => [ + 'name' => 'test-plan-' . Str::random(), + 'price' => (string)rand(1, 99), + 'description' => 'Some random description', + 'capacity' => rand(1, 999), + ], + ], + ] + ])->assertStatus(204); + } +} \ No newline at end of file diff --git a/tests/Domain/Settings/SettingsTest.php b/tests/Domain/Settings/SettingsTest.php new file mode 100644 index 00000000..dbd625fa --- /dev/null +++ b/tests/Domain/Settings/SettingsTest.php @@ -0,0 +1,194 @@ + 'get_started_title', + 'value' => 'Hello World!', + ]); + + Setting::create([ + 'name' => 'pricing_description', + 'value' => 'Give me a money!', + ]); + + $this->getJson('/api/content?column=get_started_title|pricing_description') + ->assertStatus(200) + ->assertExactJson([ + "get_started_title" => "Hello World!", + "pricing_description" => "Give me a money!", + ]); + } + + /** + * @test + */ + public function it_get_admin_settings() + { + $this->setup->seed_default_settings('Extended'); + + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + $this + ->actingAs($admin) + ->getJson('/api/admin/settings?column=section_features|section_feature_boxes') + ->assertStatus(200) + ->assertJsonFragment([ + 'section_features' => '1', + 'section_feature_boxes' => '1', + ]); + } + + /** + * @test + */ + public function it_try_get_secured_settings_via_public_api() + { + Setting::create([ + 'name' => 'purchase_code', + 'value' => '15a53561-d387-4e0a-8de1-5d1bff34c1ed', + ]); + + $this->getJson('/api/content?column=purchase_code') + ->assertStatus(401); + } + + /** + * @test + */ + public function it_update_settings() + { + $this->setup->seed_default_settings('Extended'); + + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + $this + ->actingAs($admin) + ->patchJson('/api/admin/settings', [ + 'name' => 'header_title', + 'value' => 'New Header Title' + ])->assertStatus(204); + + $this->assertDatabaseHas('settings', [ + 'value' => 'New Header Title' + ]); + } + + /** + * @test + */ + public function it_update_settings_image() + { + Setting::forceCreate([ + 'name' => 'app_logo', + 'value' => null, + ]); + + $logo = UploadedFile::fake() + ->image('fake-image.jpg'); + + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + Sanctum::actingAs($admin); + + $this + ->actingAs($admin) + ->patchJson('/api/admin/settings', [ + 'name' => 'app_logo', + 'app_logo' => $logo + ])->assertStatus(204); + + $this->assertDatabaseMissing('settings', [ + 'app_logo' => null + ]); + + Storage::assertExists( + get_setting('app_logo') + ); + } + + /** + * @test + */ + public function it_flush_cache() + { + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + $this + ->actingAs($admin) + ->getJson('/api/admin/settings/flush-cache') + ->assertStatus(204); + } + + /** + * @test + */ + public function it_set_stripe() + { + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + $this + ->actingAs($admin) + ->postJson('/api/admin/settings/stripe', [ + 'currency' => 'EUR', + 'key' => '123456789', + 'secret' => '123456789', + 'webhookSecret' => '123456789', + ])->assertStatus(204); + + $this->assertDatabaseHas('settings', [ + 'name' => 'stripe_currency', + 'value' => 'EUR', + ]); + + $this->assertDatabaseHas('settings', [ + 'name' => 'payments_configured', + 'value' => 1, + ]); + + $this->assertDatabaseHas('settings', [ + 'name' => 'payments_active', + 'value' => 1, + ]); + } + + /** + * @test + */ + public function it_set_email() + { + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + $this + ->actingAs($admin) + ->postJson('/api/admin/settings/email', [ + 'driver' => 'smtp', + 'host' => 'smtp.email.com', + 'port' => 25, + 'username' => 'john@doe.com', + 'password' => 'secret', + 'encryption' => 'tls', + ])->assertStatus(204); + } +} \ No newline at end of file diff --git a/tests/Domain/SetupWizard/SetupServiceTest.php b/tests/Domain/SetupWizard/SetupServiceTest.php index 09e5aaa6..5facdbe4 100644 --- a/tests/Domain/SetupWizard/SetupServiceTest.php +++ b/tests/Domain/SetupWizard/SetupServiceTest.php @@ -1,10 +1,10 @@ setup->create_directories(); + // folders are created in TestCase collect(['avatars', 'chunks', 'system', 'files', 'temp', 'zip']) ->each(function ($directory) { diff --git a/tests/Domain/SetupWizard/SetupWizardTest.php b/tests/Domain/SetupWizard/SetupWizardTest.php index 931fe179..b9f3b330 100644 --- a/tests/Domain/SetupWizard/SetupWizardTest.php +++ b/tests/Domain/SetupWizard/SetupWizardTest.php @@ -1,9 +1,9 @@ create(); - Sanctum::actingAs($user); - - $this->postJson("/api/share/$file->id", [ + $this + ->actingAs($user) + ->postJson("/api/share/$file->id", [ 'isPassword' => false, 'permission' => 'editor', 'type' => 'file', @@ -55,9 +55,9 @@ class UserShareTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->postJson("/api/share/$folder->id", [ + $this + ->actingAs($user) + ->postJson("/api/share/$folder->id", [ 'isPassword' => false, 'permission' => 'editor', 'type' => 'folder', @@ -87,9 +87,9 @@ class UserShareTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->postJson("/api/share/$folder->id", [ + $this + ->actingAs($user) + ->postJson("/api/share/$folder->id", [ 'isPassword' => true, 'password' => 'secret', 'permission' => 'editor', @@ -125,9 +125,9 @@ class UserShareTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->postJson("/api/share/$folder->id", [ + $this + ->actingAs($user) + ->postJson("/api/share/$folder->id", [ 'isPassword' => false, 'permission' => 'editor', 'type' => 'folder', @@ -151,9 +151,9 @@ class UserShareTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - - $this->postJson("/api/share/$folder->id", [ + $this + ->actingAs($user) + ->postJson("/api/share/$folder->id", [ 'isPassword' => false, 'permission' => 'editor', 'type' => 'folder', diff --git a/tests/Domain/Sharing/VisitorAccessToItemsTest.php b/tests/Domain/Sharing/VisitorAccessToItemsTest.php index 2144b4d0..552fd023 100644 --- a/tests/Domain/Sharing/VisitorAccessToItemsTest.php +++ b/tests/Domain/Sharing/VisitorAccessToItemsTest.php @@ -1,12 +1,12 @@ setup->create_directories(); - collect([true, false]) ->each(function ($is_protected) { @@ -102,8 +100,6 @@ class VisitorAccessToItemsTest extends TestCase */ public function it_get_shared_image() { - $this->setup->create_directories(); - collect([true, false]) ->each(function ($is_protected) { @@ -159,8 +155,6 @@ class VisitorAccessToItemsTest extends TestCase */ public function it_get_public_thumbnail() { - $this->setup->create_directories(); - collect([true, false]) ->each(function ($is_protected) { @@ -219,8 +213,6 @@ class VisitorAccessToItemsTest extends TestCase */ public function it_download_publicly_zipped_files() { - $this->setup->create_directories(); - collect([true, false]) ->each(function ($is_protected) { diff --git a/tests/Domain/Sharing/VisitorBrowseTest.php b/tests/Domain/Sharing/VisitorBrowseTest.php index c89944bd..ac720059 100644 --- a/tests/Domain/Sharing/VisitorBrowseTest.php +++ b/tests/Domain/Sharing/VisitorBrowseTest.php @@ -1,16 +1,12 @@ assertCookieMissing('share_session'); } - /** - * @test - */ - public function visitor_zip_shared_multiple_files() - { - $this->setup->create_directories(); - - // check private or public share record - collect([true, false]) - ->each(function ($is_protected) { - - $user = User::factory(User::class) - ->create(); - - $folder = Folder::factory(Folder::class) - ->create([ - 'user_id' => $user->id - ]); - - collect([0, 1]) - ->each(function ($index) use ($folder, $user) { - - $file = UploadedFile::fake() - ->create(Str::random() . "-fake-file-$index.pdf", 1000, 'application/pdf'); - - Storage::putFileAs("files/$user->id", $file, $file->name); - - File::factory(File::class) - ->create([ - 'filesize' => $file->getSize(), - 'folder_id' => $folder->id, - 'user_id' => $user->id, - 'basename' => $file->name, - 'name' => "fake-file-$index.pdf", - ]); - }); - - $share = Share::factory(Share::class) - ->create([ - 'item_id' => $folder->id, - 'user_id' => $user->id, - 'type' => 'folder', - 'is_protected' => $is_protected, - ]); - - // Check shared item protected by password - if ($is_protected) { - - $cookie = ['share_session' => json_encode([ - 'token' => $share->token, - 'authenticated' => true, - ])]; - - $this - ->withUnencryptedCookies($cookie) - ->post("/api/zip/files/$share->token", [ - 'items' => File::all()->pluck('id') - ])->assertStatus(201); - } - - // Check public shared item - if (!$is_protected) { - $this->postJson("/api/zip/files/$share->token", [ - 'items' => File::all()->pluck('id') - ])->assertStatus(201); - } - - $this->assertDatabaseHas('zips', [ - 'user_id' => $user->id, - 'shared_token' => $share->token, - ]); - - Storage::assertExists("zip/" . Zip::first()->basename); - }); - } - - /** - * @test - */ - public function visitor_try_zip_not_shared_file_with_already_shared_multiple_files() - { - // check private or public share record - collect([true, false]) - ->each(function ($is_protected) { - - $user = User::factory(User::class) - ->create(); - - $folder = Folder::factory(Folder::class) - ->create([ - 'user_id' => $user->id - ]); - - File::factory(File::class) - ->create([ - 'folder_id' => $folder->id, - 'user_id' => $user->id, - ]); - - File::factory(File::class) - ->create([ - 'user_id' => $user->id, - ]); - - $share = Share::factory(Share::class) - ->create([ - 'item_id' => $folder->id, - 'user_id' => $user->id, - 'type' => 'folder', - 'is_protected' => $is_protected, - ]); - - // Check shared item protected by password - if ($is_protected) { - - $cookie = ['share_session' => json_encode([ - 'token' => $share->token, - 'authenticated' => true, - ])]; - - $this - ->withUnencryptedCookies($cookie) - ->post("/api/zip/files/$share->token", [ - 'items' => File::all()->pluck('id') - ])->assertStatus(403); - } - - // Check public shared item - if (!$is_protected) { - $this->postJson("/api/zip/files/$share->token", [ - 'items' => File::all()->pluck('id') - ])->assertStatus(403); - } - }); - } - - /** - * @test - */ - public function visitor_zip_shared_folder() - { - $this->setup->create_directories(); - - // check private or public share record - collect([true, false]) - ->each(function ($is_protected) { - - $user = User::factory(User::class) - ->create(); - - $root = Folder::factory(Folder::class) - ->create([ - 'user_id' => $user->id - ]); - - $children = Folder::factory(Folder::class) - ->create([ - 'user_id' => $user->id, - 'parent_id' => $root->id - ]); - - collect([0, 1]) - ->each(function ($index) use ($children, $user) { - - $file = UploadedFile::fake() - ->create(Str::random() . "-fake-file-$index.pdf", 1000, 'application/pdf'); - - Storage::putFileAs("files/$user->id", $file, $file->name); - - File::factory(File::class) - ->create([ - 'filesize' => $file->getSize(), - 'folder_id' => $children->id, - 'user_id' => $user->id, - 'basename' => $file->name, - 'name' => "fake-file-$index.pdf", - ]); - }); - - $share = Share::factory(Share::class) - ->create([ - 'item_id' => $children->id, - 'user_id' => $user->id, - 'type' => 'folder', - 'is_protected' => $is_protected, - ]); - - // Check shared item protected by password - if ($is_protected) { - - $cookie = ['share_session' => json_encode([ - 'token' => $share->token, - 'authenticated' => true, - ])]; - - $this - ->withUnencryptedCookies($cookie) - ->get("/api/zip/folder/$children->id/$share->token") - ->assertStatus(201); - } - - // Check public shared item - if (!$is_protected) { - $this->getJson("/api/zip/folder/$children->id/$share->token") - ->assertStatus(201); - } - - $this->assertDatabaseHas('zips', [ - 'user_id' => $user->id, - 'shared_token' => $share->token, - ]); - - Zip::all() - ->each(function ($zip) { - Storage::assertExists("zip/$zip->basename"); - }); - }); - } - - /** - * @test - */ - public function visitor_try_zip_not_shared_folder() - { - $this->setup->create_directories(); - - // check private or public share record - collect([true, false]) - ->each(function ($is_protected) { - - $user = User::factory(User::class) - ->create(); - - $folder = Folder::factory(Folder::class) - ->create([ - 'user_id' => $user->id - ]); - - $share = Share::factory(Share::class) - ->create([ - 'user_id' => $user->id, - 'type' => 'folder', - 'is_protected' => $is_protected, - ]); - - // Check shared item protected by password - if ($is_protected) { - - $cookie = ['share_session' => json_encode([ - 'token' => $share->token, - 'authenticated' => true, - ])]; - - $this - ->withUnencryptedCookies($cookie) - ->get("/api/zip/folder/$folder->id/$share->token") - ->assertStatus(403); - } - - // Check public shared item - if (!$is_protected) { - $this->getJson("/api/zip/folder/$folder->id/$share->token") - ->assertStatus(403); - } - }); - } - /** * @test */ diff --git a/tests/Domain/Sharing/VisitorManipulatingTest.php b/tests/Domain/Sharing/VisitorManipulatingTest.php index 1658296b..d8ed7132 100644 --- a/tests/Domain/Sharing/VisitorManipulatingTest.php +++ b/tests/Domain/Sharing/VisitorManipulatingTest.php @@ -1,12 +1,12 @@ setup->create_directories(); - // check private or public share record collect([true, false]) ->each(function ($is_protected) { diff --git a/tests/Domain/Subscriptions/AdminSubscriptionTest.php b/tests/Domain/Subscriptions/AdminSubscriptionTest.php new file mode 100644 index 00000000..f4865b1d --- /dev/null +++ b/tests/Domain/Subscriptions/AdminSubscriptionTest.php @@ -0,0 +1,56 @@ +create($this->user); + + $this + ->actingAs($user) + ->postJson('/api/user/subscription/upgrade', [ + 'billing' => $this->billing, + 'plan' => $this->plan, + 'payment' => [ + 'type' => 'stripe', + ], + ])->assertStatus(204); + + $admin = User::factory(User::class) + ->create(['role' => 'admin']); + + $this + ->actingAs($admin) + ->getJson("/api/admin/users/$user->id/subscription") + ->assertStatus(200) + ->assertExactJson([ + "data" => [ + "id" => "business-pack", + "type" => "subscription", + "attributes" => [ + "incomplete" => false, + "active" => true, + "canceled" => false, + "name" => "Business Packs", + "capacity" => 1000, + "capacity_formatted" => "1TB", + "slug" => "business-pack", + "canceled_at" => format_date(now(), '%d. %B. %Y'), + "created_at" => format_date(now(), '%d. %B. %Y'), + "ends_at" => format_date(now()->addMonth(), '%d. %B. %Y'), + ] + ] + ]); + } +} \ No newline at end of file diff --git a/tests/Domain/Subscriptions/SubscriptionTest.php b/tests/Domain/Subscriptions/SubscriptionTest.php index fdb89b8a..a60e65ed 100644 --- a/tests/Domain/Subscriptions/SubscriptionTest.php +++ b/tests/Domain/Subscriptions/SubscriptionTest.php @@ -1,19 +1,19 @@ create(); - Sanctum::actingAs($user); - - $this->getJson('/api/user/subscription/setup-intent') + $this + ->actingAs($user) + ->getJson('/api/user/subscription/setup-intent') ->assertStatus(201) ->assertJsonFragment([ "object" => "setup_intent" @@ -85,9 +85,9 @@ class SubscriptionTest extends TestCase $user = User::factory(User::class) ->create($this->user); - Sanctum::actingAs($user); - - $this->postJson('/api/user/subscription/upgrade', [ + $this + ->actingAs($user) + ->postJson('/api/user/subscription/upgrade', [ 'billing' => $this->billing, 'plan' => $this->plan, 'payment' => [ @@ -198,323 +198,4 @@ class SubscriptionTest extends TestCase ] ]); } - - /** - * - */ - public function it_get_user_invoices() - { - $user = User::factory(User::class) - ->create($this->user); - - Sanctum::actingAs($user); - - $this->postJson('/api/user/subscription/upgrade', [ - 'billing' => $this->billing, - 'plan' => $this->plan, - 'payment' => [ - 'type' => 'stripe', - ], - ])->assertStatus(204); - - $this->getJson('/api/user/invoices') - ->assertStatus(200) - ->assertJsonFragment([ - 'customer' => $this->user['stripe_id'] - ]); - } - - /** - * - */ - public function it_get_user_subscription_from_admin() - { - $user = User::factory(User::class) - ->create($this->user); - - Sanctum::actingAs($user); - - $this->postJson('/api/user/subscription/upgrade', [ - 'billing' => $this->billing, - 'plan' => $this->plan, - 'payment' => [ - 'type' => 'stripe', - ], - ])->assertStatus(204); - - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $this->getJson("/api/admin/users/$user->id/subscription") - ->assertStatus(200) - ->assertExactJson([ - "data" => [ - "id" => "business-pack", - "type" => "subscription", - "attributes" => [ - "incomplete" => false, - "active" => true, - "canceled" => false, - "name" => "Business Packs", - "capacity" => 1000, - "capacity_formatted" => "1TB", - "slug" => "business-pack", - "canceled_at" => format_date(now(), '%d. %B. %Y'), - "created_at" => format_date(now(), '%d. %B. %Y'), - "ends_at" => format_date(now()->addMonth(), '%d. %B. %Y'), - ] - ] - ]); - } - - /** - * - */ - public function it_store_stripe_plans_via_setup_wizard() - { - $this->postJson('/api/setup/stripe-plans', [ - 'plans' => [ - [ - 'type' => 'plan', - 'attributes' => [ - 'name' => 'test-plan-' . Str::random(16), - 'price' => (string)rand(1, 99), - 'description' => 'Some random description', - 'capacity' => rand(1, 999), - ], - ], - [ - 'type' => 'plan', - 'attributes' => [ - 'name' => 'test-plan-' . Str::random(16), - 'price' => (string)rand(1, 99), - 'description' => 'Some random description', - 'capacity' => rand(1, 999), - ], - ], - ] - ])->assertStatus(204); - } - - /** - * - */ - public function it_delete_single_plan() - { - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $plan_name = 'test-plan-' . Str::random(16); - - $this->postJson('/api/admin/plans', [ - 'type' => 'plan', - 'attributes' => [ - 'name' => $plan_name, - 'price' => (string)rand(1, 99), - 'description' => 'Some random description', - 'capacity' => rand(1, 999), - ], - ]) - ->assertStatus(201) - ->assertJsonFragment([ - 'name' => $plan_name - ]); - - $this->deleteJson("/api/admin/plans/" . strtolower($plan_name)) - ->assertStatus(204); - } - - /** - * - */ - public function it_update_single_plan_from_admin() - { - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $plan_name = 'test-plan-' . Str::random(16); - - $this->postJson('/api/admin/plans', [ - 'type' => 'plan', - 'attributes' => [ - 'name' => $plan_name, - 'price' => (string)rand(1, 99), - 'description' => 'Some random description', - 'capacity' => rand(1, 999), - ], - ]) - ->assertStatus(201) - ->assertJsonFragment([ - 'name' => $plan_name - ]); - - $this->patchJson("/api/admin/plans/" . strtolower($plan_name), [ - 'name' => 'description', - 'value' => 'updated description' - ])->assertStatus(201); - } - - /** - * - */ - public function it_get_subscribers_from_plan_from_admin() - { - $user = User::factory(User::class) - ->create($this->user); - - Sanctum::actingAs($user); - - $this->postJson('/api/user/subscription/upgrade', [ - 'billing' => $this->billing, - 'plan' => $this->plan, - 'payment' => [ - 'type' => 'stripe', - ], - ])->assertStatus(204); - - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $this->getJson('/api/admin/plans/' . $this->plan['data']['id'] . '/subscribers') - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => $user->id - ]); - } - - /** - * - */ - public function it_get_all_invoices_from_admin() - { - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $this->getJson("/api/admin/invoices") - ->assertStatus(200); - } - - /** - * - */ - public function it_get_single_user_invoice_page_from_admin() - { - $user = User::factory(User::class) - ->create($this->user); - - Sanctum::actingAs($user); - - $invoices = $this->getJson('/api/user/invoices') - ->assertStatus(200) - ->assertJsonFragment([ - 'customer' => $this->user['stripe_id'] - ]); - - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $invoice_id = json_decode($invoices->content(), true)['data'][0]['data']['id']; - - $this->get("/invoice/{$this->user['stripe_id']}/$invoice_id") - ->assertStatus(200) - ->assertSee('Invoice'); - } - - /** - * - */ - public function it_get_user_invoices_from_admin() - { - $user = User::factory(User::class) - ->create($this->user); - - Sanctum::actingAs($user); - - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $this->getJson("/api/admin/users/$user->id/invoices") - ->assertStatus(200) - ->assertJsonFragment([ - 'customer' => $this->user['stripe_id'] - ]); - } - - /** - * - */ - public function it_get_all_plans_from_admin() - { - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $this->getJson('/api/admin/plans') - ->assertStatus(200); - } - - /** - * - */ - public function it_get_all_plans_for_index_page() - { - $this->getJson('/api/pricing') - ->assertStatus(200); - } - - /** - * - */ - public function it_get_single_plan_from_admin() - { - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $this->getJson('/api/admin/plans/' . $this->plan['data']['id']) - ->assertStatus(200); - } - - /** - * - */ - public function it_create_single_plan_from_admin() - { - $admin = User::factory(User::class) - ->create(['role' => 'admin']); - - Sanctum::actingAs($admin); - - $plan_name = 'test-plan-' . Str::random(16); - - $this->postJson('/api/admin/plans', [ - 'type' => 'plan', - 'attributes' => [ - 'name' => $plan_name, - 'price' => (string)rand(1, 99), - 'description' => 'Some random description', - 'capacity' => rand(1, 999), - ], - ]) - ->assertStatus(201) - ->assertJsonFragment([ - 'name' => $plan_name - ]); - } } diff --git a/tests/Domain/Trash/TrashTest.php b/tests/Domain/Trash/TrashTest.php index d737c0f6..0cf77c8c 100644 --- a/tests/Domain/Trash/TrashTest.php +++ b/tests/Domain/Trash/TrashTest.php @@ -1,11 +1,11 @@ setup = app()->make(SetupService::class); - } - /** * @test */ @@ -27,8 +21,6 @@ class TrashTest extends TestCase $user = User::factory(User::class) ->create(); - Sanctum::actingAs($user); - $attributes = [ 'user_id' => $user->id, 'deleted_at' => now(), @@ -40,7 +32,9 @@ class TrashTest extends TestCase $file = File::factory(File::class) ->create($attributes); - $this->postJson("/api/trash/restore", [ + $this + ->actingAs($user) + ->postJson("/api/trash/restore", [ 'items' => [ [ 'id' => $file->id, @@ -67,8 +61,6 @@ class TrashTest extends TestCase */ public function it_dump_trash() { - $this->setup->create_directories(); - $user = User::factory(User::class) ->create(); diff --git a/tests/Domain/Zipping/SharedZippingTest.php b/tests/Domain/Zipping/SharedZippingTest.php new file mode 100644 index 00000000..a2d3753c --- /dev/null +++ b/tests/Domain/Zipping/SharedZippingTest.php @@ -0,0 +1,279 @@ +each(function ($is_protected) { + + $user = User::factory(User::class) + ->create(); + + $folder = Folder::factory(Folder::class) + ->create([ + 'user_id' => $user->id + ]); + + collect([0, 1]) + ->each(function ($index) use ($folder, $user) { + + $file = UploadedFile::fake() + ->create(Str::random() . "-fake-file-$index.pdf", 1000, 'application/pdf'); + + Storage::putFileAs("files/$user->id", $file, $file->name); + + File::factory(File::class) + ->create([ + 'filesize' => $file->getSize(), + 'folder_id' => $folder->id, + 'user_id' => $user->id, + 'basename' => $file->name, + 'name' => "fake-file-$index.pdf", + ]); + }); + + $share = Share::factory(Share::class) + ->create([ + 'item_id' => $folder->id, + 'user_id' => $user->id, + 'type' => 'folder', + 'is_protected' => $is_protected, + ]); + + // Check shared item protected by password + if ($is_protected) { + + $cookie = ['share_session' => json_encode([ + 'token' => $share->token, + 'authenticated' => true, + ])]; + + $this + ->withUnencryptedCookies($cookie) + ->post("/api/zip/files/$share->token", [ + 'items' => File::all()->pluck('id') + ])->assertStatus(201); + } + + // Check public shared item + if (!$is_protected) { + $this->postJson("/api/zip/files/$share->token", [ + 'items' => File::all()->pluck('id') + ])->assertStatus(201); + } + + $this->assertDatabaseHas('zips', [ + 'user_id' => $user->id, + 'shared_token' => $share->token, + ]); + + Storage::assertExists("zip/" . Zip::first()->basename); + }); + } + + /** + * @test + */ + public function visitor_try_zip_not_shared_file_with_already_shared_multiple_files() + { + // check private or public share record + collect([true, false]) + ->each(function ($is_protected) { + + $user = User::factory(User::class) + ->create(); + + $folder = Folder::factory(Folder::class) + ->create([ + 'user_id' => $user->id + ]); + + File::factory(File::class) + ->create([ + 'folder_id' => $folder->id, + 'user_id' => $user->id, + ]); + + File::factory(File::class) + ->create([ + 'user_id' => $user->id, + ]); + + $share = Share::factory(Share::class) + ->create([ + 'item_id' => $folder->id, + 'user_id' => $user->id, + 'type' => 'folder', + 'is_protected' => $is_protected, + ]); + + // Check shared item protected by password + if ($is_protected) { + + $cookie = ['share_session' => json_encode([ + 'token' => $share->token, + 'authenticated' => true, + ])]; + + $this + ->withUnencryptedCookies($cookie) + ->post("/api/zip/files/$share->token", [ + 'items' => File::all()->pluck('id') + ])->assertStatus(403); + } + + // Check public shared item + if (!$is_protected) { + $this->postJson("/api/zip/files/$share->token", [ + 'items' => File::all()->pluck('id') + ])->assertStatus(403); + } + }); + } + + /** + * @test + */ + public function visitor_zip_shared_folder() + { + // check private or public share record + collect([true, false]) + ->each(function ($is_protected) { + + $user = User::factory(User::class) + ->create(); + + $root = Folder::factory(Folder::class) + ->create([ + 'user_id' => $user->id + ]); + + $children = Folder::factory(Folder::class) + ->create([ + 'user_id' => $user->id, + 'parent_id' => $root->id + ]); + + collect([0, 1]) + ->each(function ($index) use ($children, $user) { + + $file = UploadedFile::fake() + ->create(Str::random() . "-fake-file-$index.pdf", 1000, 'application/pdf'); + + Storage::putFileAs("files/$user->id", $file, $file->name); + + File::factory(File::class) + ->create([ + 'filesize' => $file->getSize(), + 'folder_id' => $children->id, + 'user_id' => $user->id, + 'basename' => $file->name, + 'name' => "fake-file-$index.pdf", + ]); + }); + + $share = Share::factory(Share::class) + ->create([ + 'item_id' => $children->id, + 'user_id' => $user->id, + 'type' => 'folder', + 'is_protected' => $is_protected, + ]); + + // Check shared item protected by password + if ($is_protected) { + + $cookie = ['share_session' => json_encode([ + 'token' => $share->token, + 'authenticated' => true, + ])]; + + $this + ->withUnencryptedCookies($cookie) + ->get("/api/zip/folder/$children->id/$share->token") + ->assertStatus(201); + } + + // Check public shared item + if (!$is_protected) { + $this->getJson("/api/zip/folder/$children->id/$share->token") + ->assertStatus(201); + } + + $this->assertDatabaseHas('zips', [ + 'user_id' => $user->id, + 'shared_token' => $share->token, + ]); + + Zip::all() + ->each(function ($zip) { + Storage::assertExists("zip/$zip->basename"); + }); + }); + } + + /** + * @test + */ + public function visitor_try_zip_not_shared_folder() + { + // check private or public share record + collect([true, false]) + ->each(function ($is_protected) { + + $user = User::factory(User::class) + ->create(); + + $folder = Folder::factory(Folder::class) + ->create([ + 'user_id' => $user->id + ]); + + $share = Share::factory(Share::class) + ->create([ + 'user_id' => $user->id, + 'type' => 'folder', + 'is_protected' => $is_protected, + ]); + + // Check shared item protected by password + if ($is_protected) { + + $cookie = ['share_session' => json_encode([ + 'token' => $share->token, + 'authenticated' => true, + ])]; + + $this + ->withUnencryptedCookies($cookie) + ->get("/api/zip/folder/$folder->id/$share->token") + ->assertStatus(403); + } + + // Check public shared item + if (!$is_protected) { + $this->getJson("/api/zip/folder/$folder->id/$share->token") + ->assertStatus(403); + } + }); + } +} \ No newline at end of file diff --git a/tests/Domain/Zipping/UserZippingTest.php b/tests/Domain/Zipping/UserZippingTest.php new file mode 100644 index 00000000..36e63d5a --- /dev/null +++ b/tests/Domain/Zipping/UserZippingTest.php @@ -0,0 +1,100 @@ +create(); + + Sanctum::actingAs($user); + + collect([0, 1]) + ->each(function ($index) { + + $file = UploadedFile::fake() + ->create("fake-file-$index.pdf", 1200, 'application/pdf'); + + $this->postJson('/api/upload', [ + 'filename' => $file->name, + 'file' => $file, + 'folder_id' => null, + 'is_last' => true, + ])->assertStatus(201); + }); + + $file_ids = File::all()->pluck('id'); + + $this->postJson("/api/zip/files", [ + 'items' => $file_ids, + ])->assertStatus(201); + + $this->assertDatabaseHas('zips', [ + 'user_id' => $user->id + ]); + + Storage::disk('local') + ->assertExists( + 'zip/' . Zip::first()->basename + ); + } + + /** + * @test + */ + public function it_zip_folder_with_content_within_and_download() + { + $user = User::factory(User::class) + ->create(); + + Sanctum::actingAs($user); + + $folder = Folder::factory(Folder::class) + ->create([ + 'user_id' => $user->id + ]); + + collect([0, 1]) + ->each(function ($index) use ($folder) { + + $file = UploadedFile::fake() + ->create("fake-file-$index.pdf", 1200, 'application/pdf'); + + $this->postJson('/api/upload', [ + 'filename' => $file->name, + 'file' => $file, + 'folder_id' => $folder->id, + 'is_last' => true, + ])->assertStatus(201); + }); + + $this->getJson("/api/zip/folder/$folder->id") + ->assertStatus(201); + + $this->assertDatabaseHas('zips', [ + 'user_id' => $user->id + ]); + + Storage::disk('local') + ->assertExists( + 'zip/' . Zip::first()->basename + ); + } +} \ No newline at end of file diff --git a/tests/Support/Scheduler/SchedulerTest.php b/tests/Support/Scheduler/SchedulerTest.php index 8a60cb92..f77b2057 100644 --- a/tests/Support/Scheduler/SchedulerTest.php +++ b/tests/Support/Scheduler/SchedulerTest.php @@ -1,25 +1,18 @@ setup = resolve(SetupService::class); - $this->scheduler = resolve(SchedulerService::class); - } - /** * @test */ @@ -31,7 +24,8 @@ class SchedulerTest extends TestCase 'created_at' => now()->subDay(), ]); - $this->scheduler->delete_expired_shared_links(); + resolve(SchedulerService::class) + ->delete_expired_shared_links(); $this->assertDatabaseMissing('shares', [ 'id' => $share->id @@ -43,8 +37,6 @@ class SchedulerTest extends TestCase */ public function it_delete_zips_older_than_one_day() { - $this->setup->create_directories(); - $file = UploadedFile::fake() ->create('archive.zip', 2000, 'application/zip'); @@ -55,7 +47,8 @@ class SchedulerTest extends TestCase 'created_at' => now()->subDay(), ]); - $this->scheduler->delete_old_zips(); + resolve(SchedulerService::class) + ->delete_old_zips(); $this->assertDatabaseMissing('zips', [ 'id' => $zip->id @@ -70,8 +63,6 @@ class SchedulerTest extends TestCase */ public function it_delete_failed_files_older_than_one_day() { - $this->setup->create_directories(); - $this->travel(-26)->hours(); $file = UploadedFile::fake() @@ -82,7 +73,8 @@ class SchedulerTest extends TestCase Storage::putFileAs($folder, $file, 'fake-file.zip'); }); - $this->scheduler->delete_failed_files(); + resolve(SchedulerService::class) + ->delete_failed_files(); collect(['chunks']) ->each(function ($folder) { @@ -115,7 +107,8 @@ class SchedulerTest extends TestCase 'created_at' => now()->subDays(31) ]); - $this->scheduler->delete_unverified_users(); + resolve(SchedulerService::class) + ->delete_unverified_users(); $this->assertDatabaseMissing('users', [ 'id' => $expiredUser->id, diff --git a/tests/TestCase.php b/tests/TestCase.php index 68efa222..76eabf5f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,6 +2,7 @@ namespace Tests; +use Domain\SetupWizard\Services\SetupService; use Carbon\Carbon; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; @@ -22,5 +23,7 @@ abstract class TestCase extends BaseTestCase Notification::fake(); Storage::fake('local'); + + resolve(SetupService::class)->create_directories(); } }