From c8ebb5db9f829c68f47e8daa8c3935e1683efe09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Carodej?= Date: Fri, 29 Apr 2022 08:24:35 +0200 Subject: [PATCH] refactoring --- config/cashier.php | 127 ------------------ .../RemoteUploadFileController.php | 2 +- ...ilesRemotelyForUploadRequestController.php | 2 +- .../VisitorRemoteUploadFileController.php | 2 +- .../Requests/RemoteUploadRequest.php | 2 +- .../Requests/StoreStripeBillingRequest.php | 36 ----- .../StoreStripeCredentialsRequest.php | 32 ----- .../Requests/StoreStripePlansRequest.php | 34 ----- storage/files.index-shm | Bin 32768 -> 32768 bytes tests/Domain/Files/FileTest.php | 54 -------- .../Domain/RemoteUpload/RemoteUploadTest.php | 70 ++++++++++ 11 files changed, 74 insertions(+), 287 deletions(-) delete mode 100644 config/cashier.php rename src/Domain/{Files => RemoteUpload}/Requests/RemoteUploadRequest.php (93%) delete mode 100644 src/Domain/SetupWizard/Requests/StoreStripeBillingRequest.php delete mode 100644 src/Domain/SetupWizard/Requests/StoreStripeCredentialsRequest.php delete mode 100644 src/Domain/SetupWizard/Requests/StoreStripePlansRequest.php create mode 100644 tests/Domain/RemoteUpload/RemoteUploadTest.php diff --git a/config/cashier.php b/config/cashier.php deleted file mode 100644 index 39de19f0..00000000 --- a/config/cashier.php +++ /dev/null @@ -1,127 +0,0 @@ - env('STRIPE_KEY'), - - 'secret' => env('STRIPE_SECRET'), - - /* - |-------------------------------------------------------------------------- - | Cashier Path - |-------------------------------------------------------------------------- - | - | This is the base URI path where Cashier's views, such as the payment - | verification screen, will be available from. You're free to tweak - | this path according to your preferences and application design. - | - */ - - 'path' => env('CASHIER_PATH', 'stripe'), - - /* - |-------------------------------------------------------------------------- - | Stripe Webhooks - |-------------------------------------------------------------------------- - | - | Your Stripe webhook secret is used to prevent unauthorized requests to - | your Stripe webhook handling controllers. The tolerance setting will - | check the drift between the current time and the signed request's. - | - */ - - 'webhook' => [ - 'secret' => env('STRIPE_WEBHOOK_SECRET'), - 'tolerance' => env('STRIPE_WEBHOOK_TOLERANCE', 300), - ], - - /* - |-------------------------------------------------------------------------- - | Cashier Model - |-------------------------------------------------------------------------- - | - | This is the model in your application that implements the Billable trait - | provided by Cashier. It will serve as the primary model you use while - | interacting with Cashier related methods, subscriptions, and so on. - | - */ - - 'model' => env('CASHIER_MODEL', App\Users\Models\User::class), - - /* - |-------------------------------------------------------------------------- - | Currency - |-------------------------------------------------------------------------- - | - | This is the default currency that will be used when generating charges - | from your application. Of course, you are welcome to use any of the - | various world currencies that are currently supported via Stripe. - | - */ - - 'currency' => env('CASHIER_CURRENCY', 'usd'), - - /* - |-------------------------------------------------------------------------- - | Currency Locale - |-------------------------------------------------------------------------- - | - | This is the default locale in which your money values are formatted in - | for display. To utilize other locales besides the default en locale - | verify you have the "intl" PHP extension installed on the system. - | - */ - - 'currency_locale' => env('CASHIER_CURRENCY_LOCALE', 'en'), - - /* - |-------------------------------------------------------------------------- - | Payment Confirmation Notification - |-------------------------------------------------------------------------- - | - | If this setting is enabled, Cashier will automatically notify customers - | whose payments require additional verification. You should listen to - | Stripe's webhooks in order for this feature to function correctly. - | - */ - - 'payment_notification' => env('CASHIER_PAYMENT_NOTIFICATION'), - - /* - |-------------------------------------------------------------------------- - | Invoice Paper Size - |-------------------------------------------------------------------------- - | - | This option is the default paper size for all invoices generated using - | Cashier. You are free to customize this settings based on the usual - | paper size used by the customers using your Laravel applications. - | - | Supported sizes: 'letter', 'legal', 'A4' - | - */ - - 'paper' => env('CASHIER_PAPER', 'letter'), - - /* - |-------------------------------------------------------------------------- - | Stripe Logger - |-------------------------------------------------------------------------- - | - | This setting defines which logging channel will be used by the Stripe - | library to write log messages. You are free to specify any of your - | logging channels listed inside the "logging" configuration file. - | - */ - - 'logger' => env('CASHIER_LOGGER'), -]; diff --git a/src/Domain/RemoteUpload/Controllers/RemoteUploadFileController.php b/src/Domain/RemoteUpload/Controllers/RemoteUploadFileController.php index ee4df71f..080548eb 100644 --- a/src/Domain/RemoteUpload/Controllers/RemoteUploadFileController.php +++ b/src/Domain/RemoteUpload/Controllers/RemoteUploadFileController.php @@ -5,7 +5,7 @@ use Illuminate\Http\Response; use Domain\Sharing\Models\Share; use Domain\Folders\Models\Folder; use App\Http\Controllers\Controller; -use Domain\Files\Requests\RemoteUploadRequest; +use Domain\RemoteUpload\Requests\RemoteUploadRequest; use Domain\RemoteUpload\Actions\GetContentFromExternalSource; class RemoteUploadFileController extends Controller diff --git a/src/Domain/RemoteUpload/Controllers/UploadFilesRemotelyForUploadRequestController.php b/src/Domain/RemoteUpload/Controllers/UploadFilesRemotelyForUploadRequestController.php index e342798f..b585cc10 100644 --- a/src/Domain/RemoteUpload/Controllers/UploadFilesRemotelyForUploadRequestController.php +++ b/src/Domain/RemoteUpload/Controllers/UploadFilesRemotelyForUploadRequestController.php @@ -3,7 +3,7 @@ namespace Domain\RemoteUpload\Controllers; use DB; use Domain\Folders\Models\Folder; -use Domain\Files\Requests\RemoteUploadRequest; +use Domain\RemoteUpload\Requests\RemoteUploadRequest; use Domain\UploadRequest\Models\UploadRequest; use Illuminate\Contracts\Filesystem\FileNotFoundException; use Domain\RemoteUpload\Actions\GetContentFromExternalSource; diff --git a/src/Domain/RemoteUpload/Controllers/VisitorRemoteUploadFileController.php b/src/Domain/RemoteUpload/Controllers/VisitorRemoteUploadFileController.php index f2864a61..6db75769 100644 --- a/src/Domain/RemoteUpload/Controllers/VisitorRemoteUploadFileController.php +++ b/src/Domain/RemoteUpload/Controllers/VisitorRemoteUploadFileController.php @@ -4,7 +4,7 @@ namespace Domain\RemoteUpload\Controllers; use Illuminate\Http\Response; use Domain\Sharing\Models\Share; use App\Http\Controllers\Controller; -use Domain\Files\Requests\RemoteUploadRequest; +use Domain\RemoteUpload\Requests\RemoteUploadRequest; use Domain\Sharing\Actions\ProtectShareRecordAction; use Domain\Sharing\Actions\VerifyAccessToItemAction; use Domain\RemoteUpload\Actions\GetContentFromExternalSource; diff --git a/src/Domain/Files/Requests/RemoteUploadRequest.php b/src/Domain/RemoteUpload/Requests/RemoteUploadRequest.php similarity index 93% rename from src/Domain/Files/Requests/RemoteUploadRequest.php rename to src/Domain/RemoteUpload/Requests/RemoteUploadRequest.php index 24426059..bbb2da52 100644 --- a/src/Domain/Files/Requests/RemoteUploadRequest.php +++ b/src/Domain/RemoteUpload/Requests/RemoteUploadRequest.php @@ -1,5 +1,5 @@ 'sometimes|nullable|string', - 'billing_postal_code' => 'required|string', - 'billing_vat_number' => 'required|string', - 'billing_address' => 'required|string', - 'billing_country' => 'required|string', - 'billing_state' => 'required|string', - 'billing_city' => 'required|string', - 'billing_name' => 'required|string', - ]; - } -} diff --git a/src/Domain/SetupWizard/Requests/StoreStripeCredentialsRequest.php b/src/Domain/SetupWizard/Requests/StoreStripeCredentialsRequest.php deleted file mode 100644 index 52ed8a08..00000000 --- a/src/Domain/SetupWizard/Requests/StoreStripeCredentialsRequest.php +++ /dev/null @@ -1,32 +0,0 @@ - 'required|string', - 'webhookSecret' => 'required|string', - 'secret' => 'required|string', - 'key' => 'required|string', - ]; - } -} diff --git a/src/Domain/SetupWizard/Requests/StoreStripePlansRequest.php b/src/Domain/SetupWizard/Requests/StoreStripePlansRequest.php deleted file mode 100644 index 61bbbdc5..00000000 --- a/src/Domain/SetupWizard/Requests/StoreStripePlansRequest.php +++ /dev/null @@ -1,34 +0,0 @@ - 'required|array', - 'plans.*.type' => 'required|string', - 'plans.*.attributes.name' => 'required|string', - 'plans.*.attributes.price' => 'required|string', - 'plans.*.attributes.description' => 'sometimes|nullable|string', - 'plans.*.attributes.capacity' => 'required|digits_between:1,9', - ]; - } -} diff --git a/storage/files.index-shm b/storage/files.index-shm index 83327bc3eb2d03aa9c6842142f22af2c1298cf27..be01479b47bf4e4c6645bc0b3fa1c4e001b49c17 100644 GIT binary patch delta 86 zcmZo@U}|V!;*@x#%K!!wIpqcQ%61=^$oKdjvY;kR5TcBM!3xOuj|AZ28yoBE0dBw@ Ao&W#< delta 86 ycmZo@U}|V!;*@x#%K!q56FKDtt;=>FSjPAG9hasSettings() - ->create(); - - $folder = Folder::factory() - ->create([ - 'user_id' => $user->id, - ]); - - $fakeFile = UploadedFile::fake() - ->create('top-secret-document.pdf', 12000000, 'application/pdf'); - - Http::fake([ - 'https://fake.com/top-secret-document.pdf' => Http::response($fakeFile->getContent()), - 'https://fake.com/another-secret-document.pdf' => Http::response($fakeFile->getContent()), - ]); - - $this - ->actingAs($user) - ->postJson('/api/upload/remote', [ - 'urls' => [ - 'https://fake.com/top-secret-document.pdf', - 'https://fake.com/another-secret-document.pdf', - ], - 'parent_id' => $folder->id, - ])->assertStatus(201); - - $this - ->assertDatabaseHas('files', [ - 'user_id' => $user->id, - 'name' => 'top-secret-document', - 'parent_id' => $folder->id, - ]) - ->assertDatabaseHas('files', [ - 'name' => 'another-secret-document', - ]); - - File::all() - ->each(function ($file) { - Event::assertDispatched(fn (RemoteFileCreatedEvent $event) => $event->payload['file']->id === $file->id); - - Storage::assertExists("files/$file->user_id/$file->basename"); - }); - } - /** * @test */ diff --git a/tests/Domain/RemoteUpload/RemoteUploadTest.php b/tests/Domain/RemoteUpload/RemoteUploadTest.php new file mode 100644 index 00000000..6fd89dc2 --- /dev/null +++ b/tests/Domain/RemoteUpload/RemoteUploadTest.php @@ -0,0 +1,70 @@ +hasSettings() + ->create(); + + $folder = Folder::factory() + ->create([ + 'user_id' => $user->id, + ]); + + $fakeFile = UploadedFile::fake() + ->create('top-secret-document.pdf', 12000000, 'application/pdf'); + + Http::fake([ + 'https://fake.com/top-secret-document.pdf' => Http::response($fakeFile->getContent()), + 'https://fake.com/another-secret-document.pdf' => Http::response($fakeFile->getContent()), + ]); + + $this + ->actingAs($user) + ->postJson('/api/upload/remote', [ + 'urls' => [ + 'https://fake.com/top-secret-document.pdf', + 'https://fake.com/another-secret-document.pdf', + ], + 'parent_id' => $folder->id, + ])->assertStatus(201); + + $this + ->assertDatabaseHas('files', [ + 'user_id' => $user->id, + 'name' => 'top-secret-document', + 'parent_id' => $folder->id, + ]) + ->assertDatabaseHas('files', [ + 'name' => 'another-secret-document', + ]); + + File::all() + ->each(function ($file) { + Event::assertDispatched(fn (RemoteFileCreatedEvent $event) => $event->payload['file']->id === $file->id); + + Storage::assertExists("files/$file->user_id/$file->basename"); + }); + } +} \ No newline at end of file