diff --git a/app/Actions/ApiKey/CreateApiKey.php b/app/Actions/ApiKey/CreateApiKey.php new file mode 100644 index 00000000..1594cf9d --- /dev/null +++ b/app/Actions/ApiKey/CreateApiKey.php @@ -0,0 +1,34 @@ + $workspace->id, + 'name' => data_get($data, 'name'), + 'token_lookup' => substr($plainToken, 3, 16), + 'token_hash' => Hash::make($plainToken), + 'expires_at' => data_get($data, 'expires_at') + ? now()->parse(data_get($data, 'expires_at'))->endOfDay() + : null, + ]); + + return ['token' => $apiToken, 'plain_token' => $plainToken]; + } +} diff --git a/app/Actions/ApiKey/DeleteApiKey.php b/app/Actions/ApiKey/DeleteApiKey.php new file mode 100644 index 00000000..3957d656 --- /dev/null +++ b/app/Actions/ApiKey/DeleteApiKey.php @@ -0,0 +1,15 @@ +delete(); + } +} diff --git a/app/Actions/Hashtag/CreateHashtag.php b/app/Actions/Hashtag/CreateHashtag.php new file mode 100644 index 00000000..47e2eaa4 --- /dev/null +++ b/app/Actions/Hashtag/CreateHashtag.php @@ -0,0 +1,19 @@ +hashtags()->create([ + 'name' => data_get($data, 'name'), + 'hashtags' => data_get($data, 'hashtags'), + ]); + } +} diff --git a/app/Actions/Hashtag/DeleteHashtag.php b/app/Actions/Hashtag/DeleteHashtag.php new file mode 100644 index 00000000..82119e6b --- /dev/null +++ b/app/Actions/Hashtag/DeleteHashtag.php @@ -0,0 +1,15 @@ +delete(); + } +} diff --git a/app/Actions/Hashtag/UpdateHashtag.php b/app/Actions/Hashtag/UpdateHashtag.php new file mode 100644 index 00000000..ec9f98fb --- /dev/null +++ b/app/Actions/Hashtag/UpdateHashtag.php @@ -0,0 +1,20 @@ +update([ + 'name' => data_get($data, 'name'), + 'hashtags' => data_get($data, 'hashtags'), + ]); + + return $hashtag; + } +} diff --git a/app/Actions/Invite/CreateInvite.php b/app/Actions/Invite/CreateInvite.php new file mode 100644 index 00000000..465e17e7 --- /dev/null +++ b/app/Actions/Invite/CreateInvite.php @@ -0,0 +1,26 @@ +invites()->create([ + 'email' => data_get($data, 'email'), + 'role' => data_get($data, 'role', WorkspaceRole::Member), + ]); + + Mail::to($invite->email)->send(new WorkspaceInviteMail($invite)); + + return $invite; + } +} diff --git a/app/Actions/Invite/DeleteInvite.php b/app/Actions/Invite/DeleteInvite.php new file mode 100644 index 00000000..1170f4ad --- /dev/null +++ b/app/Actions/Invite/DeleteInvite.php @@ -0,0 +1,15 @@ +delete(); + } +} diff --git a/app/Actions/Invite/RemoveMember.php b/app/Actions/Invite/RemoveMember.php new file mode 100644 index 00000000..0e978ec8 --- /dev/null +++ b/app/Actions/Invite/RemoveMember.php @@ -0,0 +1,15 @@ +members()->detach($userId); + } +} diff --git a/app/Actions/Label/CreateLabel.php b/app/Actions/Label/CreateLabel.php new file mode 100644 index 00000000..7ab1d95a --- /dev/null +++ b/app/Actions/Label/CreateLabel.php @@ -0,0 +1,19 @@ +labels()->create([ + 'name' => data_get($data, 'name'), + 'color' => data_get($data, 'color'), + ]); + } +} diff --git a/app/Actions/Label/DeleteLabel.php b/app/Actions/Label/DeleteLabel.php new file mode 100644 index 00000000..6e58fc22 --- /dev/null +++ b/app/Actions/Label/DeleteLabel.php @@ -0,0 +1,15 @@ +delete(); + } +} diff --git a/app/Actions/Label/UpdateLabel.php b/app/Actions/Label/UpdateLabel.php new file mode 100644 index 00000000..bfc0cb86 --- /dev/null +++ b/app/Actions/Label/UpdateLabel.php @@ -0,0 +1,20 @@ +update([ + 'name' => data_get($data, 'name'), + 'color' => data_get($data, 'color'), + ]); + + return $label; + } +} diff --git a/app/Actions/Post/CreatePost.php b/app/Actions/Post/CreatePost.php new file mode 100644 index 00000000..7e719cb6 --- /dev/null +++ b/app/Actions/Post/CreatePost.php @@ -0,0 +1,45 @@ +timezone)->format('Y-m-d'); + $scheduledAt = Carbon::parse($date, $workspace->timezone) + ->setTime(9, 0) + ->utc(); + + $post = $workspace->posts()->create([ + 'user_id' => $user->id, + 'status' => PostStatus::Draft, + 'synced' => true, + 'scheduled_at' => $scheduledAt, + ]); + + $socialAccounts = $workspace->socialAccounts; + + foreach ($socialAccounts as $account) { + $post->postPlatforms()->create([ + 'social_account_id' => $account->id, + 'platform' => $account->platform->value, + 'content' => '', + 'content_type' => ContentType::defaultFor($account->platform), + 'status' => 'pending', + 'enabled' => true, + ]); + } + + return $post; + } +} diff --git a/app/Actions/Post/DeletePost.php b/app/Actions/Post/DeletePost.php new file mode 100644 index 00000000..071933c9 --- /dev/null +++ b/app/Actions/Post/DeletePost.php @@ -0,0 +1,15 @@ +delete(); + } +} diff --git a/app/Actions/Post/UpdatePost.php b/app/Actions/Post/UpdatePost.php new file mode 100644 index 00000000..8658a78c --- /dev/null +++ b/app/Actions/Post/UpdatePost.php @@ -0,0 +1,76 @@ +status === PostStatus::Published) { + return ['post' => $post, 'action' => 'already_published']; + } + + $scheduledAt = $post->scheduled_at; + if (data_get($data, 'scheduled_at')) { + $scheduledAt = Carbon::parse(data_get($data, 'scheduled_at'), $workspace->timezone)->utc(); + } + + $status = data_get($data, 'status', $post->status); + + $post->update([ + 'status' => $status === 'publishing' ? PostStatus::Publishing : $status, + 'synced' => data_get($data, 'synced', $post->synced), + 'scheduled_at' => $scheduledAt, + ]); + + if (array_key_exists('label_ids', $data)) { + $post->labels()->sync(data_get($data, 'label_ids', [])); + } + + $post->postPlatforms()->update(['enabled' => false]); + + foreach (data_get($data, 'platforms', []) as $platformData) { + $updateData = [ + 'enabled' => true, + 'content' => data_get($platformData, 'content'), + ]; + + if (data_get($platformData, 'content_type') !== null) { + $updateData['content_type'] = data_get($platformData, 'content_type'); + } + + if (isset($platformData['meta'])) { + $postPlatform = $post->postPlatforms()->where('id', data_get($platformData, 'id'))->first(); + $updateData['meta'] = array_merge($postPlatform->meta ?? [], $platformData['meta']); + } + + $post->postPlatforms() + ->where('id', data_get($platformData, 'id')) + ->update($updateData); + } + + if ($status === 'publishing') { + $post->update(['scheduled_at' => now()]); + PublishPost::dispatch($post); + + return ['post' => $post, 'action' => 'publishing']; + } + + if ($status === 'scheduled') { + return ['post' => $post, 'action' => 'scheduled']; + } + + return ['post' => $post, 'action' => null]; + } +} diff --git a/app/Actions/Workspace/CreateWorkspace.php b/app/Actions/Workspace/CreateWorkspace.php new file mode 100644 index 00000000..37260a1b --- /dev/null +++ b/app/Actions/Workspace/CreateWorkspace.php @@ -0,0 +1,29 @@ + $user->id, + ...$data, + 'timezone' => config('app.timezone', 'UTC'), + ]); + + $workspace->members()->attach($user->id, ['role' => 'owner']); + $user->switchWorkspace($workspace); + + if ($user->hasActiveSubscription()) { + $user->incrementWorkspaceQuantity(); + } + + return $workspace; + } +} diff --git a/app/Actions/Workspace/DeleteWorkspace.php b/app/Actions/Workspace/DeleteWorkspace.php new file mode 100644 index 00000000..f737fcee --- /dev/null +++ b/app/Actions/Workspace/DeleteWorkspace.php @@ -0,0 +1,24 @@ +current_workspace_id === $workspace->id) { + $user->update(['current_workspace_id' => null]); + } + + $workspace->delete(); + + if ($user->hasActiveSubscription()) { + $user->decrementWorkspaceQuantity(); + } + } +} diff --git a/app/Concerns/PasswordValidationRules.php b/app/Concerns/PasswordValidationRules.php index 9b45ef09..e8583028 100644 --- a/app/Concerns/PasswordValidationRules.php +++ b/app/Concerns/PasswordValidationRules.php @@ -2,6 +2,7 @@ namespace App\Concerns; +use Illuminate\Contracts\Validation\Rule; use Illuminate\Validation\Rules\Password; trait PasswordValidationRules @@ -9,7 +10,7 @@ trait PasswordValidationRules /** * Get the validation rules used to validate passwords. * - * @return array|string> + * @return array|string> */ protected function passwordRules(): array { @@ -19,7 +20,7 @@ protected function passwordRules(): array /** * Get the validation rules used to validate the current password. * - * @return array|string> + * @return array|string> */ protected function currentPasswordRules(): array { diff --git a/app/Helpers/upload.php b/app/Helpers/upload.php index 1f475991..72b5c986 100644 --- a/app/Helpers/upload.php +++ b/app/Helpers/upload.php @@ -49,7 +49,7 @@ function uploadFromUrl(?string $url, string $directory = 'social-accounts'): ?st Storage::put($filename, $response->body(), 'public'); return $filename; - } catch (\Exception $e) { + } catch (Exception $e) { Log::warning('uploadFromUrl: Exception', [ 'url' => $url, 'error' => $e->getMessage(), diff --git a/app/Http/Controllers/Api/ApiKeyController.php b/app/Http/Controllers/Api/ApiKeyController.php new file mode 100644 index 00000000..83d5bb68 --- /dev/null +++ b/app/Http/Controllers/Api/ApiKeyController.php @@ -0,0 +1,46 @@ +workspace->apiTokens()->latest()->get(); + + return ApiKeyResource::collection($apiKeys); + } + + public function store(StoreApiKeyRequest $request): JsonResponse + { + $result = CreateApiKey::execute($request->workspace, $request->validated()); + + return response()->json([ + 'token' => new ApiKeyResource(data_get($result, 'token')), + 'plain_token' => data_get($result, 'plain_token'), + ], Response::HTTP_CREATED); + } + + public function destroy(Request $request, ApiToken $apiToken): JsonResponse + { + if ($apiToken->workspace_id !== $request->workspace->id) { + abort(Response::HTTP_NOT_FOUND); + } + + DeleteApiKey::execute($apiToken); + + return response()->json(null, Response::HTTP_NO_CONTENT); + } +} diff --git a/app/Http/Controllers/Api/Controller.php b/app/Http/Controllers/Api/Controller.php new file mode 100644 index 00000000..2fda368d --- /dev/null +++ b/app/Http/Controllers/Api/Controller.php @@ -0,0 +1,12 @@ +workspace->hashtags()->latest()->get(); + + return HashtagResource::collection($hashtags); + } + + public function store(StoreHashtagRequest $request): JsonResponse + { + $hashtag = CreateHashtag::execute($request->workspace, $request->validated()); + + return (new HashtagResource($hashtag)) + ->response() + ->setStatusCode(Response::HTTP_CREATED); + } + + public function update(UpdateHashtagRequest $request, WorkspaceHashtag $hashtag): HashtagResource + { + if ($hashtag->workspace_id !== $request->workspace->id) { + abort(Response::HTTP_NOT_FOUND); + } + + $hashtag = UpdateHashtag::execute($hashtag, $request->validated()); + + return new HashtagResource($hashtag); + } + + public function destroy(Request $request, WorkspaceHashtag $hashtag): JsonResponse + { + if ($hashtag->workspace_id !== $request->workspace->id) { + abort(Response::HTTP_NOT_FOUND); + } + + DeleteHashtag::execute($hashtag); + + return response()->json(null, Response::HTTP_NO_CONTENT); + } +} diff --git a/app/Http/Controllers/Api/LabelController.php b/app/Http/Controllers/Api/LabelController.php new file mode 100644 index 00000000..a453ace0 --- /dev/null +++ b/app/Http/Controllers/Api/LabelController.php @@ -0,0 +1,58 @@ +workspace->labels()->latest()->get(); + + return LabelResource::collection($labels); + } + + public function store(StoreLabelRequest $request): JsonResponse + { + $label = CreateLabel::execute($request->workspace, $request->validated()); + + return (new LabelResource($label)) + ->response() + ->setStatusCode(Response::HTTP_CREATED); + } + + public function update(UpdateLabelRequest $request, WorkspaceLabel $label): LabelResource + { + if ($label->workspace_id !== $request->workspace->id) { + abort(Response::HTTP_NOT_FOUND); + } + + $label = UpdateLabel::execute($label, $request->validated()); + + return new LabelResource($label); + } + + public function destroy(Request $request, WorkspaceLabel $label): JsonResponse + { + if ($label->workspace_id !== $request->workspace->id) { + abort(Response::HTTP_NOT_FOUND); + } + + DeleteLabel::execute($label); + + return response()->json(null, Response::HTTP_NO_CONTENT); + } +} diff --git a/app/Http/Controllers/Api/PostController.php b/app/Http/Controllers/Api/PostController.php new file mode 100644 index 00000000..55ce2fbd --- /dev/null +++ b/app/Http/Controllers/Api/PostController.php @@ -0,0 +1,83 @@ +workspace->posts() + ->with(['postPlatforms.socialAccount', 'user', 'labels']) + ->latest('scheduled_at') + ->paginate(15); + + return PostResource::collection($posts); + } + + public function show(Request $request, Post $post): PostResource + { + if ($post->workspace_id !== $request->workspace->id) { + abort(Response::HTTP_NOT_FOUND); + } + + $post->load(['postPlatforms.socialAccount', 'user', 'labels']); + + return new PostResource($post); + } + + public function store(Request $request): JsonResponse + { + $post = CreatePost::execute( + $request->workspace, + $request->workspace->members()->first(), + $request->all() + ); + + $post->load(['postPlatforms.socialAccount']); + + return (new PostResource($post)) + ->response() + ->setStatusCode(Response::HTTP_CREATED); + } + + public function update(Request $request, Post $post): PostResource|JsonResponse + { + if ($post->workspace_id !== $request->workspace->id) { + abort(Response::HTTP_NOT_FOUND); + } + + $result = UpdatePost::execute($request->workspace, $post, $request->all()); + + if (data_get($result, 'action') === 'already_published') { + return response()->json( + ['message' => 'Cannot edit a published post.'], + Response::HTTP_UNPROCESSABLE_ENTITY + ); + } + + return new PostResource(data_get($result, 'post')); + } + + public function destroy(Request $request, Post $post): JsonResponse + { + if ($post->workspace_id !== $request->workspace->id) { + abort(Response::HTTP_NOT_FOUND); + } + + DeletePost::execute($post); + + return response()->json(null, Response::HTTP_NO_CONTENT); + } +} diff --git a/app/Http/Controllers/Api/WorkspaceController.php b/app/Http/Controllers/Api/WorkspaceController.php new file mode 100644 index 00000000..4bb7340a --- /dev/null +++ b/app/Http/Controllers/Api/WorkspaceController.php @@ -0,0 +1,16 @@ +workspace); + } +} diff --git a/app/Http/Controllers/App/ApiKeyController.php b/app/Http/Controllers/App/ApiKeyController.php new file mode 100644 index 00000000..397b6d88 --- /dev/null +++ b/app/Http/Controllers/App/ApiKeyController.php @@ -0,0 +1,78 @@ +user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + return Inertia::render('settings/ApiKeys', [ + 'workspace' => $workspace, + 'apiTokens' => $workspace->apiTokens()->latest()->get(), + ]); + } + + public function store(Request $request): RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + $validated = $request->validate([ + 'name' => ['required', 'string', 'max:255'], + 'expires_at' => ['nullable', 'date', 'after:today'], + ]); + + $result = CreateApiKey::execute($workspace, $validated); + + session()->flash('flash.banner', __('settings.api_keys.flash.created')); + session()->flash('flash.bannerStyle', 'success'); + session()->flash('flash.plainToken', data_get($result, 'plain_token')); + + return back(); + } + + public function destroy(Request $request, ApiToken $apiToken): RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + if ($apiToken->workspace_id !== $workspace->id) { + abort(404); + } + + DeleteApiKey::execute($apiToken); + + session()->flash('flash.banner', __('settings.api_keys.flash.deleted')); + session()->flash('flash.bannerStyle', 'success'); + + return back(); + } +} diff --git a/app/Http/Controllers/App/BillingController.php b/app/Http/Controllers/App/BillingController.php new file mode 100644 index 00000000..8a33f0a7 --- /dev/null +++ b/app/Http/Controllers/App/BillingController.php @@ -0,0 +1,128 @@ +user(); + + if ($user->subscribed('default')) { + return redirect()->route('app.billing.index'); + } + + return Inertia::render('billing/Subscribe', [ + 'trialDays' => config('cashier.trial_days'), + ]); + } + + public function index(Request $request): Response + { + $user = $request->user(); + $subscription = $user->subscription('default'); + + return Inertia::render('billing/Index', [ + 'hasSubscription' => $user->subscribed('default'), + 'onTrial' => $subscription?->onTrial() ?? false, + 'trialEndsAt' => $subscription?->trial_ends_at?->toFormattedDateString(), + 'subscription' => $subscription?->only([ + 'stripe_status', + 'quantity', + 'ends_at', + ]), + 'workspacesCount' => $user->ownedWorkspacesCount(), + 'invoices' => $user->invoices()->map(fn ($invoice) => [ + 'id' => $invoice->id, + 'date' => $invoice->date()->toFormattedDateString(), + 'total' => $invoice->total(), + 'status' => $invoice->status, + 'invoice_pdf' => $invoice->invoice_pdf, + ]), + 'defaultPaymentMethod' => $user->defaultPaymentMethod()?->card?->only([ + 'brand', + 'last4', + 'exp_month', + 'exp_year', + ]), + ]); + } + + public function checkout(Request $request): SymfonyResponse + { + $user = $request->user(); + + $subscription = $user->newSubscription('default', config('cashier.plans.monthly.price_id')) + ->allowPromotionCodes() + ->trialDays(config('cashier.trial_days')) + ->quantity(1); + + $checkoutSession = $subscription->checkout([ + 'success_url' => route('app.billing.processing').'?status=success', + 'cancel_url' => route('app.billing.processing').'?status=cancelled', + ]); + + return Inertia::location($checkoutSession->url); + } + + public function processing(Request $request): Response|RedirectResponse + { + $user = $request->user(); + $status = $request->query('status', 'processing'); + + if ($user->subscribed('default')) { + return redirect()->route('app.calendar'); + } + + if (! in_array($status, ['processing', 'success', 'cancelled'])) { + $status = 'processing'; + } + + return Inertia::render('billing/Processing', [ + 'userId' => $user->id, + 'status' => $status, + ]); + } + + public function portal(Request $request): RedirectResponse + { + return $request->user()->redirectToBillingPortal( + route('app.billing.index') + ); + } + + public function addWorkspace(Request $request): RedirectResponse + { + $user = $request->user(); + + if (! $user->subscribed('default')) { + return redirect()->route('app.billing.index') + ->withErrors(['subscription' => 'You need an active subscription.']); + } + + $user->incrementWorkspaceQuantity(); + + return back()->with('success', 'Workspace added to subscription.'); + } + + public function removeWorkspace(Request $request): RedirectResponse + { + $user = $request->user(); + + if (! $user->subscribed('default')) { + return back(); + } + + $user->decrementWorkspaceQuantity(); + + return back()->with('success', 'Workspace removed from subscription.'); + } +} diff --git a/app/Http/Controllers/App/Controller.php b/app/Http/Controllers/App/Controller.php new file mode 100644 index 00000000..e5cc1701 --- /dev/null +++ b/app/Http/Controllers/App/Controller.php @@ -0,0 +1,12 @@ +resolveModel($request->input('model'), $request->input('model_id')); + $collection = $request->input('collection', 'default'); + + $media = $model->addMedia( + $request->file('media'), + $collection + ); + + return response()->json([ + 'id' => $media->id, + 'group_id' => $media->group_id, + 'url' => $media->url, + 'type' => $media->type->value, + 'original_filename' => $media->original_filename, + ]); + } + + public function storeChunked(StoreChunkedMediaRequest $request): JsonResponse + { + $tempFile = $this->chunkTempPath($request->chunkIdentifier()); + + $this->appendChunk($tempFile, $request->getContent(), $request->isFirstChunk()); + + if (! $request->isLastChunk()) { + return response()->json([ + 'done' => false, + 'progress' => $request->progress(), + ]); + } + + $model = $this->resolveModel($request->input('model'), $request->input('model_id')); + + $media = $model->addMediaFromPath( + $tempFile, + $request->input('file_name'), + $request->input('collection'), + ); + + @unlink($tempFile); + + return response()->json([ + 'done' => true, + 'id' => $media->id, + 'group_id' => $media->group_id, + 'url' => $media->url, + 'type' => $media->type->value, + 'original_filename' => $media->original_filename, + ]); + } + + public function destroy(string $modelId, Media $media): JsonResponse + { + if ($media->mediable_id !== $modelId) { + abort(403); + } + + $media->delete(); + + return response()->json(['success' => true]); + } + + public function reorder(Request $request): JsonResponse + { + $request->validate([ + 'media' => 'required|array', + 'media.*.id' => 'required|exists:medias,id', + 'media.*.order' => 'required|integer|min:0', + ]); + + foreach ($request->input('media') as $item) { + Media::where('id', $item['id'])->update(['order' => $item['order']]); + } + + return response()->json(['success' => true]); + } + + public function duplicate(Media $media, Request $request): JsonResponse + { + $targets = $request->input('targets', []); + $duplicates = []; + + foreach ($targets as $target) { + $model = $this->resolveModel($target['model'], $target['model_id']); + $collection = $target['collection'] ?? $media->collection; + + $duplicate = $model->media()->create([ + 'group_id' => $media->group_id, + 'collection' => $collection, + 'type' => $media->type, + 'path' => $media->path, + 'original_filename' => $media->original_filename, + 'mime_type' => $media->mime_type, + 'size' => $media->size, + 'order' => $media->order, + 'meta' => $media->meta, + ]); + + $duplicates[] = [ + 'id' => $duplicate->id, + 'group_id' => $duplicate->group_id, + 'mediable_id' => $duplicate->mediable_id, + 'mediable_type' => $duplicate->mediable_type, + 'url' => $duplicate->url, + 'type' => $duplicate->type->value, + 'original_filename' => $duplicate->original_filename, + ]; + } + + return response()->json($duplicates); + } + + private function resolveModel(string $alias, string $id): Model + { + $modelClass = Relation::getMorphedModel($alias) ?? $alias; + + return $modelClass::findOrFail($id); + } + + private function chunkTempPath(string $identifier): string + { + return storage_path("app/private/chunks/{$identifier}"); + } + + private function appendChunk(string $path, string $content, bool $isFirst): void + { + $directory = dirname($path); + + if (! is_dir($directory)) { + mkdir($directory, 0755, true); + } + + file_put_contents($path, $content, $isFirst ? 0 : FILE_APPEND); + } +} diff --git a/app/Http/Controllers/App/OnboardingController.php b/app/Http/Controllers/App/OnboardingController.php new file mode 100644 index 00000000..17fd7ad6 --- /dev/null +++ b/app/Http/Controllers/App/OnboardingController.php @@ -0,0 +1,110 @@ + Persona::toSelectArray(), + ]); + } + + public function storeStep1(Request $request): RedirectResponse + { + $validated = $request->validate([ + 'persona' => ['required', Rule::enum(Persona::class)], + ]); + + $request->user()->update([ + 'persona' => $validated['persona'], + 'setup' => Setup::Connections, + ]); + + return redirect()->route('app.onboarding.step2'); + } + + public function step2(Request $request): Response + { + $user = $request->user(); + $workspace = $user->currentWorkspace; + + $platforms = collect(); + + if ($workspace) { + $connectedAccounts = $workspace->socialAccounts; + + $platforms = collect(SocialPlatform::enabled())->map(fn ($platform) => [ + 'value' => $platform->value, + 'label' => $platform->label(), + 'color' => $platform->color(), + 'connected' => $connectedAccounts->firstWhere('platform', $platform) !== null, + 'account' => $connectedAccounts->firstWhere('platform', $platform), + ])->values(); + } + + return Inertia::render('onboarding/Step2', [ + 'platforms' => $platforms, + 'hasWorkspace' => $workspace !== null, + ]); + } + + public function storeStep2(Request $request): SymfonyResponse|RedirectResponse + { + $user = $request->user(); + + if (config('trypost.self_hosted')) { + $user->update([ + 'setup' => Setup::Completed, + ]); + + session()->flash('flash.banner', __('auth.flash.welcome')); + session()->flash('flash.bannerStyle', 'success'); + + return redirect()->route('app.calendar'); + } + + $user->update([ + 'setup' => Setup::Subscription, + ]); + + $subscription = $user->newSubscription('default', config('cashier.plans.monthly.price_id')) + ->allowPromotionCodes() + ->trialDays(config('cashier.trial_days')) + ->quantity(1); + + $checkoutSession = $subscription->checkout([ + 'success_url' => route('app.onboarding.complete').'?session_id={CHECKOUT_SESSION_ID}', + 'cancel_url' => route('app.onboarding.step2'), + ]); + + return Inertia::location($checkoutSession->url); + } + + public function complete(Request $request): RedirectResponse + { + $user = $request->user(); + + $user->update([ + 'setup' => Setup::Completed, + ]); + + session()->flash('flash.banner', __('auth.flash.welcome_trial')); + session()->flash('flash.bannerStyle', 'success'); + + return redirect()->route('app.calendar'); + } +} diff --git a/app/Http/Controllers/App/PostController.php b/app/Http/Controllers/App/PostController.php new file mode 100644 index 00000000..cf2e8482 --- /dev/null +++ b/app/Http/Controllers/App/PostController.php @@ -0,0 +1,249 @@ +user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + $query = $workspace->posts() + ->with(['postPlatforms' => fn ($query) => $query->where('enabled', true)->with('socialAccount'), 'user', 'labels']); + + if ($status) { + $query = match ($status) { + 'draft' => $query->draft(), + 'scheduled' => $query->scheduled(), + 'published' => $query->published(), + default => $query, + }; + } + + return Inertia::render('posts/Index', [ + 'workspace' => $workspace, + 'posts' => Inertia::scroll(fn () => $query->latest('scheduled_at')->paginate(15)), + 'currentStatus' => $status, + ]); + } + + public function calendar(Request $request): Response|RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + $tz = $workspace->timezone; + $view = $request->input('view', 'week'); + + $currentDay = $request->input('day') + ? Carbon::parse($request->input('day'), $tz)->startOfDay() + : Carbon::now($tz)->startOfDay(); + + $weekStart = $request->input('week') + ? Carbon::parse($request->input('week'), $tz)->startOfWeek() + : Carbon::now($tz)->startOfWeek(); + $weekEnd = $weekStart->copy()->endOfWeek(); + + $monthDate = $request->input('month') + ? Carbon::parse($request->input('month'), $tz)->startOfMonth() + : Carbon::now($tz)->startOfMonth(); + $monthStart = $monthDate->copy()->startOfMonth()->startOfWeek(); + $monthEnd = $monthDate->copy()->endOfMonth()->endOfWeek(); + + $rangeStart = match ($view) { + 'day' => $currentDay, + 'month' => $monthStart, + default => $weekStart, + }; + $rangeEnd = match ($view) { + 'day' => $currentDay->copy()->endOfDay(), + 'month' => $monthEnd, + default => $weekEnd, + }; + + $posts = $workspace->posts() + ->with(['postPlatforms' => fn ($query) => $query->where('enabled', true)->with('socialAccount')]) + ->whereBetween('scheduled_at', [$rangeStart->copy()->utc(), $rangeEnd->copy()->utc()]) + ->orderBy('scheduled_at') + ->get() + ->groupBy(fn ($post) => $post->scheduled_at?->setTimezone($tz)->format('Y-m-d')); + + return Inertia::render('posts/Calendar', [ + 'workspace' => $workspace, + 'posts' => $posts, + 'currentDay' => $currentDay->format('Y-m-d'), + 'currentWeekStart' => $weekStart->format('Y-m-d'), + 'currentMonth' => $monthDate->format('Y-m-d'), + 'view' => $view, + ]); + } + + public function store(Request $request): RedirectResponse|\Symfony\Component\HttpFoundation\Response + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + $socialAccounts = $workspace->socialAccounts; + + if ($socialAccounts->isEmpty()) { + session()->flash('flash.banner', __('posts.flash.connect_first')); + session()->flash('flash.bannerStyle', 'danger'); + + return redirect()->route('app.accounts'); + } + + $post = CreatePost::execute($workspace, $request->user(), [ + 'date' => $request->input('date'), + ]); + + return Inertia::location(route('app.posts.edit', $post)); + } + + public function edit(Request $request, Post $post): Response|RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + if ($post->workspace_id !== $workspace->id) { + abort(404); + } + + $post->load(['postPlatforms.socialAccount', 'postPlatforms.media', 'labels']); + $socialAccounts = $workspace->socialAccounts; + $labels = $workspace->labels; + $hashtags = $workspace->hashtags; + + $platformConfigs = $socialAccounts->mapWithKeys(fn ($account) => [ + $account->id => [ + 'maxContentLength' => $account->platform->maxContentLength(), + 'maxImages' => $account->platform->maxImages(), + 'allowedMediaTypes' => array_map(fn ($type) => $type->value, $account->platform->allowedMediaTypes()), + 'supportsTextOnly' => $account->platform->supportsTextOnly(), + ], + ]); + + $pinterestBoards = []; + $pinterestAccount = $socialAccounts->firstWhere('platform', Platform::Pinterest); + if ($pinterestAccount) { + try { + $pinterestBoards = app(PinterestPublisher::class)->getBoards($pinterestAccount); + } catch (\Exception $e) { + // Silently fail - boards will be empty + } + } + + return Inertia::render('posts/Edit', [ + 'workspace' => $workspace, + 'post' => $post, + 'socialAccounts' => $socialAccounts, + 'platformConfigs' => $platformConfigs, + 'pinterestBoards' => $pinterestBoards, + 'labels' => $labels, + 'hashtags' => $hashtags, + ]); + } + + public function update(UpdatePostRequest $request, Post $post): RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + if ($post->workspace_id !== $workspace->id) { + abort(404); + } + + $result = UpdatePost::execute($workspace, $post, $request->validated()); + + $action = data_get($result, 'action'); + + if ($action === 'already_published') { + session()->flash('flash.banner', __('posts.flash.cannot_edit_published')); + session()->flash('flash.bannerStyle', 'danger'); + + return back(); + } + + if ($action === 'publishing') { + session()->flash('flash.banner', __('posts.flash.publishing')); + session()->flash('flash.bannerStyle', 'success'); + + return redirect()->route('app.posts.edit', $post); + } + + if ($action === 'scheduled') { + session()->flash('flash.banner', __('posts.flash.scheduled')); + session()->flash('flash.bannerStyle', 'success'); + + return redirect()->route('app.posts.edit', $post); + } + + return back(); + } + + public function destroy(Request $request, Post $post): RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + if ($post->workspace_id !== $workspace->id) { + abort(404); + } + + DeletePost::execute($post); + + session()->flash('flash.banner', __('posts.flash.deleted')); + session()->flash('flash.bannerStyle', 'success'); + + if ($redirect = $request->input('redirect')) { + return redirect()->route($redirect); + } + + return back(); + } +} diff --git a/app/Http/Controllers/App/Settings/PasswordController.php b/app/Http/Controllers/App/Settings/PasswordController.php new file mode 100644 index 00000000..afbb14a7 --- /dev/null +++ b/app/Http/Controllers/App/Settings/PasswordController.php @@ -0,0 +1,38 @@ +validate([ + 'current_password' => ['required', 'current_password'], + 'password' => ['required', Password::defaults(), 'confirmed'], + ]); + + $request->user()->update([ + 'password' => Hash::make($validated['password']), + ]); + + session()->flash('flash.banner', __('settings.flash.password_updated')); + session()->flash('flash.bannerStyle', 'success'); + + return back(); + } +} diff --git a/app/Http/Controllers/App/Settings/ProfileController.php b/app/Http/Controllers/App/Settings/ProfileController.php new file mode 100644 index 00000000..838c6f26 --- /dev/null +++ b/app/Http/Controllers/App/Settings/ProfileController.php @@ -0,0 +1,105 @@ + $request->user() instanceof MustVerifyEmail, + 'status' => $request->session()->get('status'), + ]); + } + + public function update(ProfileUpdateRequest $request): RedirectResponse + { + $request->user()->fill($request->validated()); + + if ($request->user()->isDirty('email')) { + $request->user()->email_verified_at = null; + } + + $request->user()->save(); + + session()->flash('flash.banner', __('settings.flash.profile_updated')); + session()->flash('flash.bannerStyle', 'success'); + + return to_route('app.profile.edit'); + } + + public function updateLanguage(Request $request): RedirectResponse + { + $request->validate([ + 'language_id' => ['required', 'exists:languages,id'], + ]); + + $request->user()->update([ + 'language_id' => $request->language_id, + ]); + + $request->user()->refresh(); + + session()->flash('flash.banner', __('settings.flash.language_updated')); + session()->flash('flash.bannerStyle', 'success'); + + return back(); + } + + public function destroy(ProfileDeleteRequest $request): RedirectResponse + { + $user = $request->user(); + + DB::transaction(function () use ($user) { + if ($user->subscribed('default')) { + $user->subscription('default')->cancelNow(); + } + $user->subscriptions()->delete(); + $user->update(['current_workspace_id' => null]); + + $ownedWorkspaces = $user->workspaces()->wherePivot('role', Role::Owner->value)->get(); + + foreach ($ownedWorkspaces as $workspace) { + foreach ($workspace->members as $member) { + if ($member->id !== $user->id && $member->current_workspace_id === $workspace->id) { + $otherWorkspace = $member->workspaces() + ->where('workspaces.id', '!=', $workspace->id) + ->first(); + $member->update(['current_workspace_id' => $otherWorkspace?->id]); + } + } + + $workspace->posts()->delete(); + $workspace->socialAccounts()->delete(); + $workspace->hashtags()->delete(); + $workspace->labels()->delete(); + $workspace->invites()->delete(); + $workspace->members()->detach(); + $workspace->delete(); + } + + $user->workspaces()->detach(); + }); + + Auth::logout(); + $user->delete(); + $request->session()->invalidate(); + $request->session()->regenerateToken(); + + return redirect('/'); + } +} diff --git a/app/Http/Controllers/App/WorkspaceController.php b/app/Http/Controllers/App/WorkspaceController.php new file mode 100644 index 00000000..d94d39dc --- /dev/null +++ b/app/Http/Controllers/App/WorkspaceController.php @@ -0,0 +1,125 @@ +user(); + + $workspaces = $user->workspaces() + ->withCount(['socialAccounts', 'posts']) + ->latest() + ->get(); + + return Inertia::render('workspaces/Index', [ + 'workspaces' => $workspaces, + 'currentWorkspaceId' => $user->current_workspace_id, + ]); + } + + public function create(Request $request): Response|RedirectResponse + { + $user = $request->user(); + + if ($user->ownedWorkspacesCount() > 0 && ! $user->hasActiveSubscription()) { + return redirect()->route('app.billing.index') + ->with('message', 'Subscribe to create more workspaces.'); + } + + return Inertia::render('workspaces/Create'); + } + + public function store(StoreWorkspaceRequest $request): RedirectResponse + { + $user = $request->user(); + + if ($user->ownedWorkspacesCount() > 0 && ! $user->hasActiveSubscription()) { + return redirect()->route('app.billing.index') + ->with('message', 'Subscribe to create more workspaces.'); + } + + CreateWorkspace::execute($user, $request->validated()); + + return redirect()->route('app.calendar') + ->with('success', 'Workspace created successfully!'); + } + + public function switch(Request $request, Workspace $workspace): RedirectResponse + { + $user = $request->user(); + + if (! $user->belongsToWorkspace($workspace)) { + abort(403); + } + + $user->switchWorkspace($workspace); + + return redirect()->route('app.calendar'); + } + + public function settings(Request $request): Response|RedirectResponse + { + $user = $request->user(); + $workspace = $user->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('update', $workspace); + + $timezones = collect(timezone_identifiers_list()) + ->mapWithKeys(fn ($tz) => [$tz => $tz]) + ->toArray(); + + return Inertia::render('settings/Workspace', [ + 'workspace' => $workspace, + 'timezones' => $timezones, + ]); + } + + public function updateSettings(UpdateWorkspaceRequest $request): RedirectResponse + { + $user = $request->user(); + $workspace = $user->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('update', $workspace); + + $workspace->update($request->validated()); + + session()->flash('flash.banner', __('settings.flash.workspace_updated')); + session()->flash('flash.bannerStyle', 'success'); + + return redirect()->route('app.workspace.settings'); + } + + public function destroy(Request $request, Workspace $workspace): RedirectResponse + { + $this->authorize('delete', $workspace); + + $user = $request->user(); + + DeleteWorkspace::execute($user, $workspace); + + return redirect()->route('app.workspaces.index') + ->with('success', 'Workspace deleted successfully!'); + } +} diff --git a/app/Http/Controllers/App/WorkspaceHashtagController.php b/app/Http/Controllers/App/WorkspaceHashtagController.php new file mode 100644 index 00000000..1da673f0 --- /dev/null +++ b/app/Http/Controllers/App/WorkspaceHashtagController.php @@ -0,0 +1,105 @@ +user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + return Inertia::render('hashtags/Index', [ + 'workspace' => $workspace, + 'hashtags' => $workspace->hashtags()->latest()->get(), + ]); + } + + public function store(Request $request): RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + $validated = $request->validate([ + 'name' => ['required', 'string', 'max:255'], + 'hashtags' => ['required', 'string'], + ]); + + CreateHashtag::execute($workspace, $validated); + + session()->flash('flash.banner', __('hashtags.flash.created')); + session()->flash('flash.bannerStyle', 'success'); + + return redirect()->route('app.hashtags.index'); + } + + public function update(Request $request, WorkspaceHashtag $hashtag): RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + if ($hashtag->workspace_id !== $workspace->id) { + abort(404); + } + + $validated = $request->validate([ + 'name' => ['required', 'string', 'max:255'], + 'hashtags' => ['required', 'string'], + ]); + + UpdateHashtag::execute($hashtag, $validated); + + session()->flash('flash.banner', __('hashtags.flash.updated')); + session()->flash('flash.bannerStyle', 'success'); + + return redirect()->route('app.hashtags.index'); + } + + public function destroy(Request $request, WorkspaceHashtag $hashtag): RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + if ($hashtag->workspace_id !== $workspace->id) { + abort(404); + } + + DeleteHashtag::execute($hashtag); + + session()->flash('flash.banner', __('hashtags.flash.deleted')); + session()->flash('flash.bannerStyle', 'success'); + + return redirect()->route('app.hashtags.index'); + } +} diff --git a/app/Http/Controllers/App/WorkspaceInviteController.php b/app/Http/Controllers/App/WorkspaceInviteController.php new file mode 100644 index 00000000..36ca8905 --- /dev/null +++ b/app/Http/Controllers/App/WorkspaceInviteController.php @@ -0,0 +1,136 @@ +user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('manageTeam', $workspace); + + return Inertia::render('settings/Members', [ + 'workspace' => $workspace, + 'invites' => $workspace->invites() + ->latest() + ->get(), + 'members' => $workspace->members() + ->where('user_id', '!=', $workspace->user_id) + ->get() + ->map(fn ($member) => [ + 'id' => $member->id, + 'name' => $member->name, + 'email' => $member->email, + 'role' => $member->pivot->role, + ]), + 'owner' => [ + 'id' => $workspace->owner->id, + 'name' => $workspace->owner->name, + 'email' => $workspace->owner->email, + 'role' => WorkspaceRole::Owner->value, + ], + 'roles' => collect(WorkspaceRole::cases()) + ->filter(fn ($role) => $role !== WorkspaceRole::Owner) + ->map(fn ($role) => [ + 'value' => $role->value, + 'label' => $role->label(), + ])->values(), + ]); + } + + public function store(StoreWorkspaceInviteRequest $request): RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('manageTeam', $workspace); + + $existingInvite = $workspace->invites() + ->where('email', $request->email) + ->first(); + + if ($existingInvite) { + return back()->withErrors([ + 'email' => 'An invite already exists for this email.', + ]); + } + + if ($workspace->members()->where('email', $request->email)->exists()) { + return back()->withErrors([ + 'email' => 'This user is already a member of the workspace.', + ]); + } + + CreateInvite::execute($workspace, $request->validated()); + + session()->flash('flash.banner', __('settings.members.flash.invite_sent')); + session()->flash('flash.bannerStyle', 'success'); + + return back(); + } + + public function destroy(Request $request, WorkspaceInvite $invite): RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('manageTeam', $workspace); + + if ($invite->workspace_id !== $workspace->id) { + abort(404); + } + + DeleteInvite::execute($invite); + + session()->flash('flash.banner', __('settings.members.flash.invite_deleted')); + session()->flash('flash.bannerStyle', 'success'); + + return back(); + } + + public function removeMember(Request $request, string $userId): RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('manageTeam', $workspace); + + if ($workspace->user_id === $userId) { + return back()->withErrors(['member' => 'Cannot remove the workspace owner.']); + } + + RemoveMember::execute($workspace, $userId); + + session()->flash('flash.banner', __('settings.members.flash.member_removed')); + session()->flash('flash.bannerStyle', 'success'); + + return back(); + } +} diff --git a/app/Http/Controllers/App/WorkspaceLabelController.php b/app/Http/Controllers/App/WorkspaceLabelController.php new file mode 100644 index 00000000..44cc0f71 --- /dev/null +++ b/app/Http/Controllers/App/WorkspaceLabelController.php @@ -0,0 +1,105 @@ +user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + return Inertia::render('labels/Index', [ + 'workspace' => $workspace, + 'labels' => $workspace->labels()->latest()->get(), + ]); + } + + public function store(Request $request): RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + $validated = $request->validate([ + 'name' => ['required', 'string', 'max:255'], + 'color' => ['required', 'string', 'max:7', 'regex:/^#[0-9A-Fa-f]{6}$/'], + ]); + + CreateLabel::execute($workspace, $validated); + + session()->flash('flash.banner', __('labels.flash.created')); + session()->flash('flash.bannerStyle', 'success'); + + return redirect()->route('app.labels.index'); + } + + public function update(Request $request, WorkspaceLabel $label): RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + if ($label->workspace_id !== $workspace->id) { + abort(404); + } + + $validated = $request->validate([ + 'name' => ['required', 'string', 'max:255'], + 'color' => ['required', 'string', 'max:7', 'regex:/^#[0-9A-Fa-f]{6}$/'], + ]); + + UpdateLabel::execute($label, $validated); + + session()->flash('flash.banner', __('labels.flash.updated')); + session()->flash('flash.bannerStyle', 'success'); + + return redirect()->route('app.labels.index'); + } + + public function destroy(Request $request, WorkspaceLabel $label): RedirectResponse + { + $workspace = $request->user()->currentWorkspace; + + if (! $workspace) { + return redirect()->route('app.workspaces.create'); + } + + $this->authorize('view', $workspace); + + if ($label->workspace_id !== $workspace->id) { + abort(404); + } + + DeleteLabel::execute($label); + + session()->flash('flash.banner', __('labels.flash.deleted')); + session()->flash('flash.bannerStyle', 'success'); + + return redirect()->route('app.labels.index'); + } +} diff --git a/app/Http/Controllers/Auth/AcceptInviteController.php b/app/Http/Controllers/Auth/AcceptInviteController.php index 4ae3ebf5..cc960fe4 100644 --- a/app/Http/Controllers/Auth/AcceptInviteController.php +++ b/app/Http/Controllers/Auth/AcceptInviteController.php @@ -48,7 +48,7 @@ public function accept(Request $request, WorkspaceInvite $invite): RedirectRespo session()->flash('flash.banner', __('settings.members.flash.wrong_email')); session()->flash('flash.bannerStyle', 'danger'); - return redirect()->route('calendar'); + return redirect()->route('app.calendar'); } // Check if already a member @@ -58,7 +58,7 @@ public function accept(Request $request, WorkspaceInvite $invite): RedirectRespo session()->flash('flash.banner', __('settings.members.flash.already_member')); session()->flash('flash.bannerStyle', 'info'); - return redirect()->route('calendar'); + return redirect()->route('app.calendar'); } // Accept the invite @@ -69,7 +69,7 @@ public function accept(Request $request, WorkspaceInvite $invite): RedirectRespo session()->flash('flash.banner', __('settings.members.flash.invite_accepted')); session()->flash('flash.bannerStyle', 'success'); - return redirect()->route('calendar'); + return redirect()->route('app.calendar'); } /** @@ -84,7 +84,7 @@ public function decline(Request $request, WorkspaceInvite $invite): RedirectResp session()->flash('flash.banner', __('settings.members.flash.wrong_email')); session()->flash('flash.bannerStyle', 'danger'); - return redirect()->route('calendar'); + return redirect()->route('app.calendar'); } $invite->delete(); @@ -92,6 +92,6 @@ public function decline(Request $request, WorkspaceInvite $invite): RedirectResp session()->flash('flash.banner', __('settings.members.flash.invite_declined')); session()->flash('flash.bannerStyle', 'info'); - return redirect()->route('calendar'); + return redirect()->route('app.calendar'); } } diff --git a/app/Http/Controllers/Auth/AuthenticatedSessionController.php b/app/Http/Controllers/Auth/AuthenticatedSessionController.php index a93a85d1..c3ce6dd6 100644 --- a/app/Http/Controllers/Auth/AuthenticatedSessionController.php +++ b/app/Http/Controllers/Auth/AuthenticatedSessionController.php @@ -40,7 +40,7 @@ public function store(LoginRequest $request): RedirectResponse return redirect($redirect); } - return redirect()->intended(route('calendar')); + return redirect()->intended(route('app.calendar')); } /** diff --git a/app/Http/Controllers/Auth/BlueskyController.php b/app/Http/Controllers/Auth/BlueskyController.php index 68d03180..1ed869b7 100644 --- a/app/Http/Controllers/Auth/BlueskyController.php +++ b/app/Http/Controllers/Auth/BlueskyController.php @@ -23,7 +23,7 @@ public function connect(Request $request): Response|RedirectResponse $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('manageAccounts', $workspace); @@ -45,7 +45,7 @@ public function store(Request $request): View|RedirectResponse $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('manageAccounts', $workspace); diff --git a/app/Http/Controllers/Auth/EmailVerificationNotificationController.php b/app/Http/Controllers/Auth/EmailVerificationNotificationController.php index bc769e67..4b28463b 100644 --- a/app/Http/Controllers/Auth/EmailVerificationNotificationController.php +++ b/app/Http/Controllers/Auth/EmailVerificationNotificationController.php @@ -16,7 +16,7 @@ class EmailVerificationNotificationController extends Controller public function store(Request $request): RedirectResponse { if ($request->user()->hasVerifiedEmail()) { - return redirect()->intended(route('calendar')); + return redirect()->intended(route('app.calendar')); } $request->user()->sendEmailVerificationNotification(); diff --git a/app/Http/Controllers/Auth/EmailVerificationPromptController.php b/app/Http/Controllers/Auth/EmailVerificationPromptController.php index 6364157f..01645504 100644 --- a/app/Http/Controllers/Auth/EmailVerificationPromptController.php +++ b/app/Http/Controllers/Auth/EmailVerificationPromptController.php @@ -18,7 +18,7 @@ class EmailVerificationPromptController extends Controller public function __invoke(Request $request): RedirectResponse|Response { return $request->user()->hasVerifiedEmail() - ? redirect()->intended(route('calendar')) + ? redirect()->intended(route('app.calendar')) : Inertia::render('auth/VerifyEmail', [ 'status' => session('status'), ]); diff --git a/app/Http/Controllers/Auth/FacebookController.php b/app/Http/Controllers/Auth/FacebookController.php index 16972390..0982e7db 100644 --- a/app/Http/Controllers/Auth/FacebookController.php +++ b/app/Http/Controllers/Auth/FacebookController.php @@ -34,7 +34,7 @@ public function connect(Request $request): Response|RedirectResponse $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('manageAccounts', $workspace); @@ -159,7 +159,7 @@ public function callback(Request $request): View|RedirectResponse ], ]); - return redirect()->route('social.facebook.select-page'); + return redirect()->route('app.social.facebook.select-page'); } catch (\Exception $e) { Log::error('Facebook OAuth Error', [ 'error' => $e->getMessage(), @@ -179,7 +179,7 @@ public function selectPage(Request $request) session()->flash('flash.banner', __('accounts.flash.session_expired')); session()->flash('flash.bannerStyle', 'danger'); - return redirect()->route('accounts'); + return redirect()->route('app.accounts'); } $workspace = Workspace::find($workspaceId); @@ -188,7 +188,7 @@ public function selectPage(Request $request) session()->flash('flash.banner', __('accounts.flash.workspace_not_found')); session()->flash('flash.bannerStyle', 'danger'); - return redirect()->route('accounts'); + return redirect()->route('app.accounts'); } return Inertia::render('accounts/FacebookPageSelect', [ diff --git a/app/Http/Controllers/Auth/InstagramController.php b/app/Http/Controllers/Auth/InstagramController.php index d26473ca..063565b3 100644 --- a/app/Http/Controllers/Auth/InstagramController.php +++ b/app/Http/Controllers/Auth/InstagramController.php @@ -31,7 +31,7 @@ public function connect(Request $request): Response|RedirectResponse $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('manageAccounts', $workspace); diff --git a/app/Http/Controllers/Auth/LinkedInController.php b/app/Http/Controllers/Auth/LinkedInController.php index 89413d4b..9bf1eb51 100644 --- a/app/Http/Controllers/Auth/LinkedInController.php +++ b/app/Http/Controllers/Auth/LinkedInController.php @@ -34,7 +34,7 @@ public function connect(Request $request): Response|RedirectResponse $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('manageAccounts', $workspace); diff --git a/app/Http/Controllers/Auth/LinkedInPageController.php b/app/Http/Controllers/Auth/LinkedInPageController.php index 6b151cea..1798f1d6 100644 --- a/app/Http/Controllers/Auth/LinkedInPageController.php +++ b/app/Http/Controllers/Auth/LinkedInPageController.php @@ -39,7 +39,7 @@ public function connect(Request $request): SymfonyResponse|RedirectResponse $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('manageAccounts', $workspace); @@ -116,7 +116,7 @@ public function callback(Request $request): View|RedirectResponse ], ]); - return redirect()->route('social.linkedin-page.select-page'); + return redirect()->route('app.social.linkedin-page.select-page'); } catch (\Exception $e) { Log::error('LinkedIn Page OAuth Error', [ 'error' => $e->getMessage(), @@ -134,7 +134,7 @@ public function selectPage(Request $request): Response|RedirectResponse session()->flash('flash.banner', __('accounts.flash.session_expired')); session()->flash('flash.bannerStyle', 'danger'); - return redirect()->route('accounts'); + return redirect()->route('app.accounts'); } $workspace = Workspace::find($pendingData['workspace_id']); @@ -143,7 +143,7 @@ public function selectPage(Request $request): Response|RedirectResponse session()->flash('flash.banner', __('accounts.flash.workspace_not_found')); session()->flash('flash.bannerStyle', 'danger'); - return redirect()->route('accounts'); + return redirect()->route('app.accounts'); } return Inertia::render('accounts/LinkedInPageSelect', [ diff --git a/app/Http/Controllers/Auth/MastodonController.php b/app/Http/Controllers/Auth/MastodonController.php index 6613b2c8..1c2cef18 100644 --- a/app/Http/Controllers/Auth/MastodonController.php +++ b/app/Http/Controllers/Auth/MastodonController.php @@ -30,7 +30,7 @@ public function connect(Request $request): Response|RedirectResponse $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('manageAccounts', $workspace); @@ -54,7 +54,7 @@ public function authorizeInstance(Request $request): SymfonyResponse|RedirectRes $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('manageAccounts', $workspace); @@ -65,7 +65,7 @@ public function authorizeInstance(Request $request): SymfonyResponse|RedirectRes // Register app on the instance $appResponse = Http::post("{$instance}/api/v1/apps", [ 'client_name' => config('app.name'), - 'redirect_uris' => route('social.mastodon.callback'), + 'redirect_uris' => route('app.social.mastodon.callback'), 'scopes' => self::SCOPES, 'website' => config('app.url'), ]); @@ -96,7 +96,7 @@ public function authorizeInstance(Request $request): SymfonyResponse|RedirectRes $params = http_build_query([ 'client_id' => $app['client_id'], 'response_type' => 'code', - 'redirect_uri' => route('social.mastodon.callback'), + 'redirect_uri' => route('app.social.mastodon.callback'), 'scope' => self::SCOPES, 'state' => $state, ]); @@ -149,7 +149,7 @@ public function callback(Request $request): View 'grant_type' => 'authorization_code', 'client_id' => $clientId, 'client_secret' => $clientSecret, - 'redirect_uri' => route('social.mastodon.callback'), + 'redirect_uri' => route('app.social.mastodon.callback'), 'code' => $request->code, ]); diff --git a/app/Http/Controllers/Auth/PinterestController.php b/app/Http/Controllers/Auth/PinterestController.php index 4f335947..2eea1235 100644 --- a/app/Http/Controllers/Auth/PinterestController.php +++ b/app/Http/Controllers/Auth/PinterestController.php @@ -33,7 +33,7 @@ public function connect(Request $request): Response|RedirectResponse $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('manageAccounts', $workspace); diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php index 85284ffb..95672836 100644 --- a/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -6,10 +6,10 @@ use App\Enums\User\Setup; use App\Http\Controllers\Controller; -use App\Rules\Timezone; use App\Models\Language; use App\Models\User; use App\Models\Workspace; +use App\Rules\Timezone; use Illuminate\Auth\Events\Registered; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; @@ -84,6 +84,6 @@ public function store(Request $request): RedirectResponse return redirect($redirect); } - return redirect()->route('onboarding.step1'); + return redirect()->route('app.onboarding.step1'); } } diff --git a/app/Http/Controllers/Auth/SocialController.php b/app/Http/Controllers/Auth/SocialController.php index f65737e5..42dbf9dd 100644 --- a/app/Http/Controllers/Auth/SocialController.php +++ b/app/Http/Controllers/Auth/SocialController.php @@ -32,7 +32,7 @@ public function index(Request $request): Response|RedirectResponse $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('view', $workspace); @@ -62,7 +62,7 @@ public function disconnect(Request $request, SocialAccount $account): RedirectRe $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('manageAccounts', $workspace); @@ -84,7 +84,7 @@ protected function redirectToProvider(Request $request, string $driver, array $s $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } session(['social_connect_workspace' => $workspace->id]); diff --git a/app/Http/Controllers/Auth/ThreadsController.php b/app/Http/Controllers/Auth/ThreadsController.php index d5a61b9c..1653c8d8 100644 --- a/app/Http/Controllers/Auth/ThreadsController.php +++ b/app/Http/Controllers/Auth/ThreadsController.php @@ -29,7 +29,7 @@ public function connect(Request $request): Response|RedirectResponse $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('manageAccounts', $workspace); diff --git a/app/Http/Controllers/Auth/TikTokController.php b/app/Http/Controllers/Auth/TikTokController.php index 597a6cf5..5cd3e725 100644 --- a/app/Http/Controllers/Auth/TikTokController.php +++ b/app/Http/Controllers/Auth/TikTokController.php @@ -31,7 +31,7 @@ public function connect(Request $request): Response|RedirectResponse $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('manageAccounts', $workspace); diff --git a/app/Http/Controllers/Auth/VerifyEmailController.php b/app/Http/Controllers/Auth/VerifyEmailController.php index 567e31d6..aa17b64e 100644 --- a/app/Http/Controllers/Auth/VerifyEmailController.php +++ b/app/Http/Controllers/Auth/VerifyEmailController.php @@ -17,13 +17,13 @@ class VerifyEmailController extends Controller public function __invoke(EmailVerificationRequest $request): RedirectResponse { if ($request->user()->hasVerifiedEmail()) { - return redirect()->intended(route('calendar').'?verified=1'); + return redirect()->intended(route('app.calendar').'?verified=1'); } if ($request->user()->markEmailAsVerified()) { event(new Verified($request->user())); } - return redirect()->intended(route('calendar').'?verified=1'); + return redirect()->intended(route('app.calendar').'?verified=1'); } } diff --git a/app/Http/Controllers/Auth/XController.php b/app/Http/Controllers/Auth/XController.php index 481dc998..10b94f3a 100644 --- a/app/Http/Controllers/Auth/XController.php +++ b/app/Http/Controllers/Auth/XController.php @@ -29,7 +29,7 @@ public function connect(Request $request): Response|RedirectResponse $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('manageAccounts', $workspace); diff --git a/app/Http/Controllers/Auth/YouTubeController.php b/app/Http/Controllers/Auth/YouTubeController.php index e5e07c74..f81ecaf7 100644 --- a/app/Http/Controllers/Auth/YouTubeController.php +++ b/app/Http/Controllers/Auth/YouTubeController.php @@ -7,8 +7,10 @@ use App\Models\Workspace; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; use Illuminate\View\View; +use Inertia\Inertia; use Laravel\Socialite\Facades\Socialite; use Symfony\Component\HttpFoundation\Response; @@ -31,7 +33,7 @@ public function connect(Request $request): Response|RedirectResponse $workspace = $request->user()->currentWorkspace; if (! $workspace) { - return redirect()->route('workspaces.create'); + return redirect()->route('app.workspaces.create'); } $this->authorize('manageAccounts', $workspace); @@ -150,7 +152,7 @@ public function callback(Request $request): View|RedirectResponse ], ]); - return redirect()->route('social.youtube.select-channel'); + return redirect()->route('app.social.youtube.select-channel'); } catch (\Exception $e) { Log::error('YouTube OAuth Error', [ 'error' => $e->getMessage(), @@ -170,7 +172,7 @@ public function selectChannel(Request $request) session()->flash('flash.banner', __('accounts.flash.session_expired')); session()->flash('flash.bannerStyle', 'danger'); - return redirect()->route('accounts'); + return redirect()->route('app.accounts'); } $workspace = Workspace::find($workspaceId); @@ -179,7 +181,7 @@ public function selectChannel(Request $request) session()->flash('flash.banner', __('accounts.flash.workspace_not_found')); session()->flash('flash.bannerStyle', 'danger'); - return redirect()->route('accounts'); + return redirect()->route('app.accounts'); } // Fetch YouTube channels @@ -291,7 +293,7 @@ public function select(Request $request): View private function redirectToGoogle(): Response { - return \Inertia\Inertia::location( + return Inertia::location( Socialite::driver($this->driver) ->scopes($this->scopes) ->with([ @@ -307,7 +309,7 @@ private function redirectToGoogle(): Response private function fetchChannels(string $accessToken): array { try { - $response = \Illuminate\Support\Facades\Http::withToken($accessToken) + $response = Http::withToken($accessToken) ->get('https://www.googleapis.com/youtube/v3/channels', [ 'part' => 'snippet,contentDetails,statistics', 'mine' => 'true', diff --git a/app/Http/Middleware/Api/AuthenticateApiToken.php b/app/Http/Middleware/Api/AuthenticateApiToken.php new file mode 100644 index 00000000..17cec3bf --- /dev/null +++ b/app/Http/Middleware/Api/AuthenticateApiToken.php @@ -0,0 +1,47 @@ +bearerToken(); + + if (! $token) { + return response()->json(['message' => 'Missing API key.'], Response::HTTP_UNAUTHORIZED); + } + + if (! str_starts_with($token, 'tp_') || strlen($token) !== 51) { + return response()->json(['message' => 'Invalid API key.'], Response::HTTP_UNAUTHORIZED); + } + + $lookup = substr($token, 3, 16); + $apiToken = ApiToken::where('token_lookup', $lookup)->first(); + + if (! $apiToken || ! Hash::check($token, $apiToken->token_hash)) { + return response()->json(['message' => 'Invalid API key.'], Response::HTTP_UNAUTHORIZED); + } + + if ($apiToken->status === 'expired') { + return response()->json(['message' => 'API key has expired.'], Response::HTTP_UNAUTHORIZED); + } + + $apiToken->update(['last_used_at' => now()]); + + $request->merge([ + 'workspace' => $apiToken->workspace, + 'api_token' => $apiToken, + ]); + + return $next($request); + } +} diff --git a/app/Http/Middleware/EnsureSubscribed.php b/app/Http/Middleware/EnsureSubscribed.php index 8558d87d..e5e5ec29 100644 --- a/app/Http/Middleware/EnsureSubscribed.php +++ b/app/Http/Middleware/EnsureSubscribed.php @@ -11,7 +11,7 @@ class EnsureSubscribed /** * Handle an incoming request. * - * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next + * @param Closure(Request): (Response) $next */ public function handle(Request $request, Closure $next): Response { @@ -43,6 +43,6 @@ public function handle(Request $request, Closure $next): Response } // Redirect to subscription page - return redirect()->route('subscribe'); + return redirect()->route('app.subscribe'); } } diff --git a/app/Http/Middleware/EnsureUserSetupIsComplete.php b/app/Http/Middleware/EnsureUserSetupIsComplete.php index 17ba7e3b..2ad31d90 100644 --- a/app/Http/Middleware/EnsureUserSetupIsComplete.php +++ b/app/Http/Middleware/EnsureUserSetupIsComplete.php @@ -12,7 +12,7 @@ class EnsureUserSetupIsComplete /** * Handle an incoming request. * - * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next + * @param Closure(Request): (Response) $next */ public function handle(Request $request, Closure $next): Response { @@ -46,10 +46,10 @@ public function handle(Request $request, Closure $next): Response // Redirect to appropriate step return match ($user->setup) { - Setup::Role => redirect()->route('onboarding.step1'), - Setup::Connections => redirect()->route('onboarding.step2'), - Setup::Subscription => redirect()->route('onboarding.step2'), - default => redirect()->route('onboarding.step1'), + Setup::Role => redirect()->route('app.onboarding.step1'), + Setup::Connections => redirect()->route('app.onboarding.step2'), + Setup::Subscription => redirect()->route('app.onboarding.step2'), + default => redirect()->route('app.onboarding.step1'), }; } } diff --git a/app/Http/Middleware/HandleAppearance.php b/app/Http/Middleware/HandleAppearance.php index f1a02bbc..1a01684d 100644 --- a/app/Http/Middleware/HandleAppearance.php +++ b/app/Http/Middleware/HandleAppearance.php @@ -12,7 +12,7 @@ class HandleAppearance /** * Handle an incoming request. * - * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next + * @param Closure(Request): (Response) $next */ public function handle(Request $request, Closure $next): Response { diff --git a/app/Http/Requests/Api/ApiKey/StoreApiKeyRequest.php b/app/Http/Requests/Api/ApiKey/StoreApiKeyRequest.php new file mode 100644 index 00000000..404a552e --- /dev/null +++ b/app/Http/Requests/Api/ApiKey/StoreApiKeyRequest.php @@ -0,0 +1,26 @@ + + */ + public function rules(): array + { + return [ + 'name' => ['required', 'string', 'max:255'], + 'expires_at' => ['nullable', 'date', 'after:today'], + ]; + } +} diff --git a/app/Http/Requests/Api/Hashtag/StoreHashtagRequest.php b/app/Http/Requests/Api/Hashtag/StoreHashtagRequest.php new file mode 100644 index 00000000..7e3ac266 --- /dev/null +++ b/app/Http/Requests/Api/Hashtag/StoreHashtagRequest.php @@ -0,0 +1,26 @@ + + */ + public function rules(): array + { + return [ + 'name' => ['required', 'string', 'max:255'], + 'hashtags' => ['required', 'string'], + ]; + } +} diff --git a/app/Http/Requests/Api/Hashtag/UpdateHashtagRequest.php b/app/Http/Requests/Api/Hashtag/UpdateHashtagRequest.php new file mode 100644 index 00000000..15b48407 --- /dev/null +++ b/app/Http/Requests/Api/Hashtag/UpdateHashtagRequest.php @@ -0,0 +1,26 @@ + + */ + public function rules(): array + { + return [ + 'name' => ['required', 'string', 'max:255'], + 'hashtags' => ['required', 'string'], + ]; + } +} diff --git a/app/Http/Requests/Api/Label/StoreLabelRequest.php b/app/Http/Requests/Api/Label/StoreLabelRequest.php new file mode 100644 index 00000000..eb30d954 --- /dev/null +++ b/app/Http/Requests/Api/Label/StoreLabelRequest.php @@ -0,0 +1,26 @@ + + */ + public function rules(): array + { + return [ + 'name' => ['required', 'string', 'max:255'], + 'color' => ['required', 'string', 'max:7', 'regex:/^#[0-9A-Fa-f]{6}$/'], + ]; + } +} diff --git a/app/Http/Requests/Api/Label/UpdateLabelRequest.php b/app/Http/Requests/Api/Label/UpdateLabelRequest.php new file mode 100644 index 00000000..9cc9532e --- /dev/null +++ b/app/Http/Requests/Api/Label/UpdateLabelRequest.php @@ -0,0 +1,26 @@ + + */ + public function rules(): array + { + return [ + 'name' => ['required', 'string', 'max:255'], + 'color' => ['required', 'string', 'max:7', 'regex:/^#[0-9A-Fa-f]{6}$/'], + ]; + } +} diff --git a/app/Http/Requests/App/ApiKey/StoreApiKeyRequest.php b/app/Http/Requests/App/ApiKey/StoreApiKeyRequest.php new file mode 100644 index 00000000..b4f881ca --- /dev/null +++ b/app/Http/Requests/App/ApiKey/StoreApiKeyRequest.php @@ -0,0 +1,26 @@ + + */ + public function rules(): array + { + return [ + 'name' => ['required', 'string', 'max:255'], + 'expires_at' => ['nullable', 'date', 'after:today'], + ]; + } +} diff --git a/app/Http/Requests/App/Hashtag/StoreHashtagRequest.php b/app/Http/Requests/App/Hashtag/StoreHashtagRequest.php new file mode 100644 index 00000000..860be3bd --- /dev/null +++ b/app/Http/Requests/App/Hashtag/StoreHashtagRequest.php @@ -0,0 +1,26 @@ + + */ + public function rules(): array + { + return [ + 'name' => ['required', 'string', 'max:255'], + 'hashtags' => ['required', 'string'], + ]; + } +} diff --git a/app/Http/Requests/App/Label/StoreLabelRequest.php b/app/Http/Requests/App/Label/StoreLabelRequest.php new file mode 100644 index 00000000..8f8d9d13 --- /dev/null +++ b/app/Http/Requests/App/Label/StoreLabelRequest.php @@ -0,0 +1,26 @@ + + */ + public function rules(): array + { + return [ + 'name' => ['required', 'string', 'max:255'], + 'color' => ['required', 'string', 'max:7', 'regex:/^#[0-9A-Fa-f]{6}$/'], + ]; + } +} diff --git a/app/Http/Requests/Auth/LoginRequest.php b/app/Http/Requests/Auth/LoginRequest.php index 7befcea5..db82457c 100644 --- a/app/Http/Requests/Auth/LoginRequest.php +++ b/app/Http/Requests/Auth/LoginRequest.php @@ -5,6 +5,7 @@ namespace App\Http\Requests\Auth; use Illuminate\Auth\Events\Lockout; +use Illuminate\Contracts\Validation\Rule; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\RateLimiter; @@ -24,7 +25,7 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array + * @return array */ public function rules(): array { @@ -37,7 +38,7 @@ public function rules(): array /** * Attempt to authenticate the request's credentials. * - * @throws \Illuminate\Validation\ValidationException + * @throws ValidationException */ public function authenticate(): void { @@ -57,7 +58,7 @@ public function authenticate(): void /** * Ensure the login request is not rate limited. * - * @throws \Illuminate\Validation\ValidationException + * @throws ValidationException */ public function ensureIsNotRateLimited(): void { diff --git a/app/Http/Requests/StoreWorkspaceInviteRequest.php b/app/Http/Requests/StoreWorkspaceInviteRequest.php index 73d549aa..f5027daa 100644 --- a/app/Http/Requests/StoreWorkspaceInviteRequest.php +++ b/app/Http/Requests/StoreWorkspaceInviteRequest.php @@ -3,6 +3,7 @@ namespace App\Http\Requests; use App\Enums\UserWorkspace\Role as WorkspaceRole; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; @@ -19,7 +20,7 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array|string> + * @return array|string> */ public function rules(): array { diff --git a/app/Http/Resources/Api/ApiKeyResource.php b/app/Http/Resources/Api/ApiKeyResource.php new file mode 100644 index 00000000..e574c2a9 --- /dev/null +++ b/app/Http/Resources/Api/ApiKeyResource.php @@ -0,0 +1,27 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + 'key_hint' => $this->key_hint, + 'status' => $this->status, + 'last_used_at' => $this->last_used_at?->format('Y-m-d H:i:s'), + 'expires_at' => $this->expires_at?->format('Y-m-d H:i:s'), + 'created_at' => $this->created_at->format('Y-m-d H:i:s'), + ]; + } +} diff --git a/app/Http/Resources/Api/HashtagResource.php b/app/Http/Resources/Api/HashtagResource.php new file mode 100644 index 00000000..85ade0c5 --- /dev/null +++ b/app/Http/Resources/Api/HashtagResource.php @@ -0,0 +1,25 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + 'hashtags' => $this->hashtags, + 'created_at' => $this->created_at->format('Y-m-d H:i:s'), + 'updated_at' => $this->updated_at->format('Y-m-d H:i:s'), + ]; + } +} diff --git a/app/Http/Resources/Api/LabelResource.php b/app/Http/Resources/Api/LabelResource.php new file mode 100644 index 00000000..b35a6eb5 --- /dev/null +++ b/app/Http/Resources/Api/LabelResource.php @@ -0,0 +1,25 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + 'color' => $this->color, + 'created_at' => $this->created_at->format('Y-m-d H:i:s'), + 'updated_at' => $this->updated_at->format('Y-m-d H:i:s'), + ]; + } +} diff --git a/app/Http/Resources/Api/PostPlatformResource.php b/app/Http/Resources/Api/PostPlatformResource.php new file mode 100644 index 00000000..b8939cab --- /dev/null +++ b/app/Http/Resources/Api/PostPlatformResource.php @@ -0,0 +1,27 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'platform' => $this->platform, + 'content' => $this->content, + 'content_type' => $this->content_type, + 'status' => $this->status, + 'enabled' => $this->enabled, + 'social_account' => new SocialAccountResource($this->whenLoaded('socialAccount')), + ]; + } +} diff --git a/app/Http/Resources/Api/PostResource.php b/app/Http/Resources/Api/PostResource.php new file mode 100644 index 00000000..34063b40 --- /dev/null +++ b/app/Http/Resources/Api/PostResource.php @@ -0,0 +1,29 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'status' => $this->status, + 'synced' => $this->synced, + 'scheduled_at' => $this->scheduled_at?->format('Y-m-d H:i:s'), + 'published_at' => $this->published_at?->format('Y-m-d H:i:s'), + 'platforms' => PostPlatformResource::collection($this->whenLoaded('postPlatforms')), + 'labels' => LabelResource::collection($this->whenLoaded('labels')), + 'created_at' => $this->created_at->format('Y-m-d H:i:s'), + 'updated_at' => $this->updated_at->format('Y-m-d H:i:s'), + ]; + } +} diff --git a/app/Http/Resources/Api/SocialAccountResource.php b/app/Http/Resources/Api/SocialAccountResource.php new file mode 100644 index 00000000..e7438236 --- /dev/null +++ b/app/Http/Resources/Api/SocialAccountResource.php @@ -0,0 +1,25 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'platform' => $this->platform, + 'name' => $this->name, + 'username' => $this->username, + 'avatar' => $this->avatar, + ]; + } +} diff --git a/app/Http/Resources/Api/WorkspaceResource.php b/app/Http/Resources/Api/WorkspaceResource.php new file mode 100644 index 00000000..b8a26f9f --- /dev/null +++ b/app/Http/Resources/Api/WorkspaceResource.php @@ -0,0 +1,25 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + 'timezone' => $this->timezone, + 'created_at' => $this->created_at->format('Y-m-d H:i:s'), + 'updated_at' => $this->updated_at->format('Y-m-d H:i:s'), + ]; + } +} diff --git a/app/Mail/AccountDisconnected.php b/app/Mail/AccountDisconnected.php index 6c3fa747..a5cbf04f 100644 --- a/app/Mail/AccountDisconnected.php +++ b/app/Mail/AccountDisconnected.php @@ -43,7 +43,7 @@ public function content(): Content 'platformName' => $platformName, 'accountName' => $accountName, 'workspaceName' => $workspaceName, - 'url' => route('accounts'), + 'url' => route('app.accounts'), ], ); } diff --git a/app/Mail/WorkspaceConnectionsDisconnected.php b/app/Mail/WorkspaceConnectionsDisconnected.php index 5f764b79..8390f481 100644 --- a/app/Mail/WorkspaceConnectionsDisconnected.php +++ b/app/Mail/WorkspaceConnectionsDisconnected.php @@ -61,7 +61,7 @@ public function content(): Content 'buttonText' => __('mail.workspace_connections_disconnected.button', [], $locale), 'workspace' => $this->workspace, 'disconnectedAccounts' => $this->disconnectedAccounts, - 'url' => route('accounts'), + 'url' => route('app.accounts'), ], ); } diff --git a/app/Mail/WorkspaceInvite.php b/app/Mail/WorkspaceInvite.php index e666f0dc..47df0c7f 100644 --- a/app/Mail/WorkspaceInvite.php +++ b/app/Mail/WorkspaceInvite.php @@ -33,7 +33,7 @@ public function content(): Content 'title' => "You've been invited to join {$this->invite->workspace->name}", 'previewText' => "You've been invited to join {$this->invite->workspace->name}", 'invite' => $this->invite, - 'url' => route('invites.show', $this->invite->id), + 'url' => route('app.invites.show', $this->invite->id), ], ); } diff --git a/app/Models/ApiToken.php b/app/Models/ApiToken.php new file mode 100644 index 00000000..e5dbacdf --- /dev/null +++ b/app/Models/ApiToken.php @@ -0,0 +1,70 @@ + 'datetime', + 'expires_at' => 'datetime', + ]; + } + + public function workspace(): BelongsTo + { + return $this->belongsTo(Workspace::class); + } + + protected function keyHint(): Attribute + { + return Attribute::make( + get: fn () => 'tp_'.substr($this->token_lookup, 0, 8).'...', + ); + } + + protected function status(): Attribute + { + return Attribute::make( + get: function () { + if ($this->expires_at === null) { + return 'active'; + } + + return now()->greaterThan($this->expires_at) ? 'expired' : 'active'; + } + ); + } +} diff --git a/app/Models/Media.php b/app/Models/Media.php index a397147a..33031c0a 100644 --- a/app/Models/Media.php +++ b/app/Models/Media.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Enums\Media\Type as MediaType; +use Database\Factories\MediaFactory; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -12,7 +13,7 @@ class Media extends Model { - /** @use HasFactory<\Database\Factories\MediaFactory> */ + /** @use HasFactory */ use HasFactory, HasUuids; protected $table = 'medias'; diff --git a/app/Models/Post.php b/app/Models/Post.php index bcf89158..46546f50 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Enums\Post\Status as PostStatus; +use Database\Factories\PostFactory; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -13,7 +14,7 @@ class Post extends Model { - /** @use HasFactory<\Database\Factories\PostFactory> */ + /** @use HasFactory */ use HasFactory, HasUuids; protected $fillable = [ diff --git a/app/Models/PostPlatform.php b/app/Models/PostPlatform.php index 95ccee0a..7c6e1f80 100644 --- a/app/Models/PostPlatform.php +++ b/app/Models/PostPlatform.php @@ -5,6 +5,7 @@ use App\Enums\PostPlatform\ContentType; use App\Enums\SocialAccount\Platform as SocialPlatform; use App\Models\Traits\HasMedia; +use Database\Factories\PostPlatformFactory; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -12,7 +13,7 @@ class PostPlatform extends Model { - /** @use HasFactory<\Database\Factories\PostPlatformFactory> */ + /** @use HasFactory */ use HasFactory, HasMedia, HasUuids; protected $fillable = [ diff --git a/app/Models/SocialAccount.php b/app/Models/SocialAccount.php index 2e0b8af7..53157949 100644 --- a/app/Models/SocialAccount.php +++ b/app/Models/SocialAccount.php @@ -5,6 +5,7 @@ use App\Enums\SocialAccount\Platform as SocialPlatform; use App\Enums\SocialAccount\Status; use App\Mail\AccountDisconnected; +use Database\Factories\SocialAccountFactory; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -17,7 +18,7 @@ class SocialAccount extends Model { - /** @use HasFactory<\Database\Factories\SocialAccountFactory> */ + /** @use HasFactory */ use HasFactory, HasUuids; protected $fillable = [ diff --git a/app/Models/User.php b/app/Models/User.php index 0fbd5e72..180b428d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,6 +6,7 @@ use App\Enums\User\Setup; use App\Models\Traits\HasMedia; use App\Models\Traits\HasWorkspace; +use Database\Factories\UserFactory; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -16,7 +17,7 @@ class User extends Authenticatable implements MustVerifyEmail { - /** @use HasFactory<\Database\Factories\UserFactory> */ + /** @use HasFactory */ use Billable, HasFactory, HasMedia, HasUuids, HasWorkspace, Notifiable; /** diff --git a/app/Models/Workspace.php b/app/Models/Workspace.php index 93e75476..edc275ab 100644 --- a/app/Models/Workspace.php +++ b/app/Models/Workspace.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Models\Traits\HasMedia; +use Database\Factories\WorkspaceFactory; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -12,7 +13,7 @@ class Workspace extends Model { - /** @use HasFactory<\Database\Factories\WorkspaceFactory> */ + /** @use HasFactory */ use HasFactory, HasMedia, HasUuids; protected $fillable = [ @@ -78,6 +79,11 @@ public function labels(): HasMany return $this->hasMany(WorkspaceLabel::class); } + public function apiTokens(): HasMany + { + return $this->hasMany(ApiToken::class); + } + public function hasMember(User $user): bool { return $this->user_id === $user->id || $this->members()->where('user_id', $user->id)->exists(); diff --git a/app/Models/WorkspaceHashtag.php b/app/Models/WorkspaceHashtag.php index 269129d1..b52e9915 100644 --- a/app/Models/WorkspaceHashtag.php +++ b/app/Models/WorkspaceHashtag.php @@ -2,6 +2,7 @@ namespace App\Models; +use Database\Factories\WorkspaceHashtagFactory; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -10,7 +11,7 @@ class WorkspaceHashtag extends Model { - /** @use HasFactory<\Database\Factories\WorkspaceHashtagFactory> */ + /** @use HasFactory */ use HasFactory, HasUuids, SoftDeletes; protected $fillable = [ diff --git a/app/Models/WorkspaceInvite.php b/app/Models/WorkspaceInvite.php index 435149ee..ecf29360 100644 --- a/app/Models/WorkspaceInvite.php +++ b/app/Models/WorkspaceInvite.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Enums\UserWorkspace\Role; +use Database\Factories\WorkspaceInviteFactory; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -12,7 +13,7 @@ class WorkspaceInvite extends Model { - /** @use HasFactory<\Database\Factories\WorkspaceInviteFactory> */ + /** @use HasFactory */ use HasFactory, HasUuids; /** diff --git a/app/Models/WorkspaceLabel.php b/app/Models/WorkspaceLabel.php index 1a74ea88..691bf535 100644 --- a/app/Models/WorkspaceLabel.php +++ b/app/Models/WorkspaceLabel.php @@ -2,6 +2,7 @@ namespace App\Models; +use Database\Factories\WorkspaceLabelFactory; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -11,7 +12,7 @@ class WorkspaceLabel extends Model { - /** @use HasFactory<\Database\Factories\WorkspaceLabelFactory> */ + /** @use HasFactory */ use HasFactory, HasUuids, SoftDeletes; protected $fillable = [ diff --git a/app/Rules/Timezone.php b/app/Rules/Timezone.php index 90301db0..2432498f 100644 --- a/app/Rules/Timezone.php +++ b/app/Rules/Timezone.php @@ -6,11 +6,12 @@ use Closure; use Illuminate\Contracts\Validation\ValidationRule; +use Illuminate\Translation\PotentiallyTranslatedString; class Timezone implements ValidationRule { /** - * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail + * @param Closure(string, ?string=): PotentiallyTranslatedString $fail */ public function validate(string $attribute, mixed $value, Closure $fail): void { diff --git a/bootstrap/app.php b/bootstrap/app.php index cb35c54b..9d575680 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -1,5 +1,6 @@ withRouting( web: __DIR__.'/../routes/web.php', + api: __DIR__.'/../routes/api.php', + apiPrefix: '', commands: __DIR__.'/../routes/console.php', channels: __DIR__.'/../routes/channels.php', health: '/up', - then: function () { - Route::middleware('web') - ->group(base_path('routes/auth.php')); - }, ) ->withMiddleware(function (Middleware $middleware): void { $middleware->encryptCookies(except: ['appearance', 'sidebar_state']); @@ -31,6 +29,11 @@ $middleware->alias([ 'subscribed' => EnsureSubscribed::class, + 'api.auth' => AuthenticateApiToken::class, + ]); + + $middleware->validateCsrfTokens(except: [ + 'stripe/*', ]); }) ->withExceptions(function (Exceptions $exceptions): void { diff --git a/bootstrap/providers.php b/bootstrap/providers.php index 4e3b4407..2345aa62 100644 --- a/bootstrap/providers.php +++ b/bootstrap/providers.php @@ -1,6 +1,9 @@ [ 'users' => [ 'driver' => 'eloquent', - 'model' => env('AUTH_MODEL', App\Models\User::class), + 'model' => env('AUTH_MODEL', User::class), ], // 'users' => [ diff --git a/config/database.php b/config/database.php index c15e8c4a..ee12bd3d 100644 --- a/config/database.php +++ b/config/database.php @@ -1,6 +1,7 @@ true, 'engine' => null, 'options' => extension_loaded('pdo_mysql') ? array_filter([ - (PHP_VERSION_ID >= 80500 ? \Pdo\Mysql::ATTR_SSL_CA : \PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'), + (PHP_VERSION_ID >= 80500 ? Mysql::ATTR_SSL_CA : PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'), ]) : [], ], @@ -79,7 +80,7 @@ 'strict' => true, 'engine' => null, 'options' => extension_loaded('pdo_mysql') ? array_filter([ - (PHP_VERSION_ID >= 80500 ? \Pdo\Mysql::ATTR_SSL_CA : \PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'), + (PHP_VERSION_ID >= 80500 ? Mysql::ATTR_SSL_CA : PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'), ]) : [], ], diff --git a/database/factories/LanguageFactory.php b/database/factories/LanguageFactory.php index 318bbe9b..0357c633 100644 --- a/database/factories/LanguageFactory.php +++ b/database/factories/LanguageFactory.php @@ -2,10 +2,11 @@ namespace Database\Factories; +use App\Models\Language; use Illuminate\Database\Eloquent\Factories\Factory; /** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Language> + * @extends Factory */ class LanguageFactory extends Factory { diff --git a/database/factories/MediaFactory.php b/database/factories/MediaFactory.php index 94c14315..2760ce40 100644 --- a/database/factories/MediaFactory.php +++ b/database/factories/MediaFactory.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; /** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Media> + * @extends Factory */ class MediaFactory extends Factory { diff --git a/database/factories/PostFactory.php b/database/factories/PostFactory.php index c5188ec0..1e67d8eb 100644 --- a/database/factories/PostFactory.php +++ b/database/factories/PostFactory.php @@ -3,12 +3,13 @@ namespace Database\Factories; use App\Enums\Post\Status as PostStatus; +use App\Models\Post; use App\Models\User; use App\Models\Workspace; use Illuminate\Database\Eloquent\Factories\Factory; /** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Post> + * @extends Factory */ class PostFactory extends Factory { diff --git a/database/factories/PostPlatformFactory.php b/database/factories/PostPlatformFactory.php index 95557b2c..a7198162 100644 --- a/database/factories/PostPlatformFactory.php +++ b/database/factories/PostPlatformFactory.php @@ -5,11 +5,12 @@ use App\Enums\PostPlatform\ContentType; use App\Enums\SocialAccount\Platform; use App\Models\Post; +use App\Models\PostPlatform; use App\Models\SocialAccount; use Illuminate\Database\Eloquent\Factories\Factory; /** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PostPlatform> + * @extends Factory */ class PostPlatformFactory extends Factory { diff --git a/database/factories/SocialAccountFactory.php b/database/factories/SocialAccountFactory.php index b0d2e20a..d9a111c5 100644 --- a/database/factories/SocialAccountFactory.php +++ b/database/factories/SocialAccountFactory.php @@ -4,11 +4,12 @@ use App\Enums\SocialAccount\Platform; use App\Enums\SocialAccount\Status; +use App\Models\SocialAccount; use App\Models\Workspace; use Illuminate\Database\Eloquent\Factories\Factory; /** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SocialAccount> + * @extends Factory */ class SocialAccountFactory extends Factory { diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index cba2d87b..6082d653 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -3,12 +3,13 @@ namespace Database\Factories; use App\Models\Language; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; /** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User> + * @extends Factory */ class UserFactory extends Factory { diff --git a/database/factories/WorkspaceFactory.php b/database/factories/WorkspaceFactory.php index 6de65ad6..b7b285de 100644 --- a/database/factories/WorkspaceFactory.php +++ b/database/factories/WorkspaceFactory.php @@ -3,10 +3,11 @@ namespace Database\Factories; use App\Models\User; +use App\Models\Workspace; use Illuminate\Database\Eloquent\Factories\Factory; /** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Workspace> + * @extends Factory */ class WorkspaceFactory extends Factory { diff --git a/database/factories/WorkspaceHashtagFactory.php b/database/factories/WorkspaceHashtagFactory.php index 93de23f8..adda2f0d 100644 --- a/database/factories/WorkspaceHashtagFactory.php +++ b/database/factories/WorkspaceHashtagFactory.php @@ -3,10 +3,11 @@ namespace Database\Factories; use App\Models\Workspace; +use App\Models\WorkspaceHashtag; use Illuminate\Database\Eloquent\Factories\Factory; /** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\WorkspaceHashtag> + * @extends Factory */ class WorkspaceHashtagFactory extends Factory { diff --git a/database/factories/WorkspaceInviteFactory.php b/database/factories/WorkspaceInviteFactory.php index 5a810e94..f5d86192 100644 --- a/database/factories/WorkspaceInviteFactory.php +++ b/database/factories/WorkspaceInviteFactory.php @@ -4,10 +4,11 @@ use App\Enums\UserWorkspace\Role; use App\Models\Workspace; +use App\Models\WorkspaceInvite; use Illuminate\Database\Eloquent\Factories\Factory; /** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\WorkspaceInvite> + * @extends Factory */ class WorkspaceInviteFactory extends Factory { diff --git a/database/factories/WorkspaceLabelFactory.php b/database/factories/WorkspaceLabelFactory.php index 064251fc..3fc0a785 100644 --- a/database/factories/WorkspaceLabelFactory.php +++ b/database/factories/WorkspaceLabelFactory.php @@ -3,10 +3,11 @@ namespace Database\Factories; use App\Models\Workspace; +use App\Models\WorkspaceLabel; use Illuminate\Database\Eloquent\Factories\Factory; /** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\WorkspaceLabel> + * @extends Factory */ class WorkspaceLabelFactory extends Factory { diff --git a/database/migrations/2026_03_29_215341_create_api_tokens_table.php b/database/migrations/2026_03_29_215341_create_api_tokens_table.php new file mode 100644 index 00000000..1390506a --- /dev/null +++ b/database/migrations/2026_03_29_215341_create_api_tokens_table.php @@ -0,0 +1,29 @@ +uuid('id')->primary(); + $table->foreignUuid('workspace_id')->constrained()->cascadeOnDelete(); + $table->string('name'); + $table->string('token_lookup', 16)->unique(); + $table->string('token_hash', 255); + $table->timestamp('last_used_at')->nullable(); + $table->timestamp('expires_at')->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('api_tokens'); + } +}; diff --git a/lang/pt-br/passwords.php b/lang/pt-br/passwords.php index 49fa8f07..600b63b8 100644 --- a/lang/pt-br/passwords.php +++ b/lang/pt-br/passwords.php @@ -17,6 +17,6 @@ 'sent' => 'Enviamos o link de redefinição de senha por e-mail.', 'throttled' => 'Por favor, aguarde antes de tentar novamente.', 'token' => 'Este token de redefinição de senha é inválido.', - 'user' => "Não conseguimos encontrar um usuário com esse endereço de e-mail.", + 'user' => 'Não conseguimos encontrar um usuário com esse endereço de e-mail.', ]; diff --git a/routes/api.php b/routes/api.php new file mode 100644 index 00000000..875a6564 --- /dev/null +++ b/routes/api.php @@ -0,0 +1,45 @@ + 'api.'.parse_url(config('app.url'), PHP_URL_HOST), + 'middleware' => ['api.auth'], + ], + function () { + // Posts + Route::get('/posts', [PostController::class, 'index'])->name('api.posts.index'); + Route::post('/posts', [PostController::class, 'store'])->name('api.posts.store'); + Route::get('/posts/{post}', [PostController::class, 'show'])->name('api.posts.show'); + Route::put('/posts/{post}', [PostController::class, 'update'])->name('api.posts.update'); + Route::delete('/posts/{post}', [PostController::class, 'destroy'])->name('api.posts.destroy'); + + // Workspace + Route::get('/workspace', [WorkspaceController::class, 'show'])->name('api.workspace.show'); + + // Hashtags + Route::get('/hashtags', [HashtagController::class, 'index'])->name('api.hashtags.index'); + Route::post('/hashtags', [HashtagController::class, 'store'])->name('api.hashtags.store'); + Route::put('/hashtags/{hashtag}', [HashtagController::class, 'update'])->name('api.hashtags.update'); + Route::delete('/hashtags/{hashtag}', [HashtagController::class, 'destroy'])->name('api.hashtags.destroy'); + + // Labels + Route::get('/labels', [LabelController::class, 'index'])->name('api.labels.index'); + Route::post('/labels', [LabelController::class, 'store'])->name('api.labels.store'); + Route::put('/labels/{label}', [LabelController::class, 'update'])->name('api.labels.update'); + Route::delete('/labels/{label}', [LabelController::class, 'destroy'])->name('api.labels.destroy'); + + // API Keys + Route::get('/api-keys', [ApiKeyController::class, 'index'])->name('api.api-keys.index'); + Route::post('/api-keys', [ApiKeyController::class, 'store'])->name('api.api-keys.store'); + Route::delete('/api-keys/{apiToken}', [ApiKeyController::class, 'destroy'])->name('api.api-keys.destroy'); + } +); diff --git a/routes/app.php b/routes/app.php new file mode 100644 index 00000000..e5aec5a4 --- /dev/null +++ b/routes/app.php @@ -0,0 +1,179 @@ + 'app.'.parse_url(config('app.url'), PHP_URL_HOST), + 'middleware' => ['web'], + ], + function () { + Route::get('/', function () { + return redirect()->route('app.calendar'); + })->name('app.home')->middleware(['auth', 'verified']); + + // Subscription selection (requires auth but not subscription) + Route::middleware(['auth', 'verified'])->group(function () { + Route::get('subscribe', [BillingController::class, 'subscribe'])->name('app.subscribe'); + Route::post('billing/checkout', [BillingController::class, 'checkout'])->name('app.billing.checkout'); + Route::get('billing/processing', [BillingController::class, 'processing'])->name('app.billing.processing'); + }); + + // Onboarding routes + Route::middleware(['auth', 'verified'])->prefix('onboarding')->group(function () { + Route::get('step1', [OnboardingController::class, 'step1'])->name('app.onboarding.step1'); + Route::post('step1', [OnboardingController::class, 'storeStep1'])->name('app.onboarding.step1.store'); + Route::get('step2', [OnboardingController::class, 'step2'])->name('app.onboarding.step2'); + Route::post('step2', [OnboardingController::class, 'storeStep2'])->name('app.onboarding.step2.store'); + Route::get('complete', [OnboardingController::class, 'complete'])->name('app.onboarding.complete'); + }); + + // Social Connect routes + Route::middleware(['auth', 'verified'])->group(function () { + Route::get('connect/linkedin', [LinkedInController::class, 'connect'])->name('app.social.linkedin.connect'); + Route::get('accounts/linkedin/callback', [LinkedInController::class, 'callback'])->name('app.social.linkedin.callback'); + + Route::get('connect/linkedin-page', [LinkedInPageController::class, 'connect'])->name('app.social.linkedin-page.connect'); + Route::get('accounts/linkedin-page/callback', [LinkedInPageController::class, 'callback'])->name('app.social.linkedin-page.callback'); + Route::get('accounts/linkedin-page/select', [LinkedInPageController::class, 'selectPage'])->name('app.social.linkedin-page.select-page'); + Route::post('accounts/linkedin-page/select', [LinkedInPageController::class, 'select'])->name('app.social.linkedin-page.select'); + + Route::get('connect/x', [XController::class, 'connect'])->name('app.social.x.connect'); + Route::get('accounts/x/callback', [XController::class, 'callback'])->name('app.social.x.callback'); + + Route::get('connect/tiktok', [TikTokController::class, 'connect'])->name('app.social.tiktok.connect'); + Route::get('accounts/tiktok/callback', [TikTokController::class, 'callback'])->name('app.social.tiktok.callback'); + + Route::get('connect/youtube', [YouTubeController::class, 'connect'])->name('app.social.youtube.connect'); + Route::get('accounts/youtube/callback', [YouTubeController::class, 'callback'])->name('app.social.youtube.callback'); + Route::get('accounts/youtube/select', [YouTubeController::class, 'selectChannel'])->name('app.social.youtube.select-channel'); + Route::post('accounts/youtube/select', [YouTubeController::class, 'select'])->name('app.social.youtube.select'); + + Route::get('connect/facebook', [FacebookController::class, 'connect'])->name('app.social.facebook.connect'); + Route::get('accounts/facebook/callback', [FacebookController::class, 'callback'])->name('app.social.facebook.callback'); + Route::get('accounts/facebook/select', [FacebookController::class, 'selectPage'])->name('app.social.facebook.select-page'); + Route::post('accounts/facebook/select', [FacebookController::class, 'select'])->name('app.social.facebook.select'); + + Route::get('connect/instagram', [InstagramController::class, 'connect'])->name('app.social.instagram.connect'); + Route::get('accounts/instagram/callback', [InstagramController::class, 'callback'])->name('app.social.instagram.callback'); + Route::get('accounts/instagram/select', [InstagramController::class, 'selectAccount'])->name('app.social.instagram.select-account'); + Route::post('accounts/instagram/select', [InstagramController::class, 'select'])->name('app.social.instagram.select'); + + Route::get('connect/threads', [ThreadsController::class, 'connect'])->name('app.social.threads.connect'); + Route::get('accounts/threads/callback', [ThreadsController::class, 'callback'])->name('app.social.threads.callback'); + + Route::get('connect/pinterest', [PinterestController::class, 'connect'])->name('app.social.pinterest.connect'); + Route::get('accounts/pinterest/callback', [PinterestController::class, 'callback'])->name('app.social.pinterest.callback'); + + Route::get('connect/bluesky', [BlueskyController::class, 'connect'])->name('app.social.bluesky.connect'); + Route::post('connect/bluesky', [BlueskyController::class, 'store'])->name('app.social.bluesky.store'); + + Route::get('connect/mastodon', [MastodonController::class, 'connect'])->name('app.social.mastodon.connect'); + Route::post('connect/mastodon', [MastodonController::class, 'authorizeInstance'])->name('app.social.mastodon.authorize'); + Route::get('accounts/mastodon/callback', [MastodonController::class, 'callback'])->name('app.social.mastodon.callback'); + }); + + // Routes that require active subscription and completed onboarding + Route::middleware(['auth', 'verified', 'subscribed', EnsureUserSetupIsComplete::class])->group(function () { + // Workspaces + Route::get('workspaces', [WorkspaceController::class, 'index'])->name('app.workspaces.index'); + Route::get('workspaces/create', [WorkspaceController::class, 'create'])->name('app.workspaces.create'); + Route::post('workspaces', [WorkspaceController::class, 'store'])->name('app.workspaces.store'); + Route::post('workspaces/{workspace}/switch', [WorkspaceController::class, 'switch'])->name('app.workspaces.switch'); + Route::delete('workspaces/{workspace}', [WorkspaceController::class, 'destroy'])->name('app.workspaces.destroy'); + + // Workspace settings + Route::get('settings/workspace', [WorkspaceController::class, 'settings'])->name('app.workspace.settings'); + Route::put('settings/workspace', [WorkspaceController::class, 'updateSettings'])->name('app.workspace.settings.update'); + + // Social Accounts + Route::get('accounts', [SocialController::class, 'index'])->name('app.accounts'); + Route::delete('accounts/{account}', [SocialController::class, 'disconnect'])->name('app.accounts.disconnect'); + + // Calendar + Route::get('calendar', [PostController::class, 'calendar'])->name('app.calendar'); + + // Posts + Route::get('posts/{status?}', [PostController::class, 'index'])->name('app.posts.index')->where('status', 'draft|scheduled|published'); + Route::post('posts', [PostController::class, 'store'])->name('app.posts.store'); + Route::get('posts/{post}/edit', [PostController::class, 'edit'])->name('app.posts.edit'); + Route::put('posts/{post}', [PostController::class, 'update'])->name('app.posts.update'); + Route::delete('posts/{post}', [PostController::class, 'destroy'])->name('app.posts.destroy'); + + // Media + Route::post('medias', [MediaController::class, 'store'])->name('app.medias.store'); + Route::post('medias/chunked', [MediaController::class, 'storeChunked'])->name('app.medias.store-chunked'); + Route::post('medias/reorder', [MediaController::class, 'reorder'])->name('app.medias.reorder'); + Route::post('medias/{media}/duplicate', [MediaController::class, 'duplicate'])->name('app.medias.duplicate'); + Route::delete('medias/{modelId}/{media}', [MediaController::class, 'destroy'])->name('app.medias.destroy'); + + // Members + Route::get('settings/members', [WorkspaceInviteController::class, 'index'])->name('app.members'); + Route::post('settings/members/invites', [WorkspaceInviteController::class, 'store'])->name('app.invites.store'); + Route::delete('settings/members/invites/{invite}', [WorkspaceInviteController::class, 'destroy'])->name('app.invites.destroy'); + Route::delete('settings/members/{user}', [WorkspaceInviteController::class, 'removeMember'])->name('app.members.remove'); + + // Hashtags + Route::get('hashtags', [WorkspaceHashtagController::class, 'index'])->name('app.hashtags.index'); + Route::post('hashtags', [WorkspaceHashtagController::class, 'store'])->name('app.hashtags.store'); + Route::put('hashtags/{hashtag}', [WorkspaceHashtagController::class, 'update'])->name('app.hashtags.update'); + Route::delete('hashtags/{hashtag}', [WorkspaceHashtagController::class, 'destroy'])->name('app.hashtags.destroy'); + + // Labels + Route::get('labels', [WorkspaceLabelController::class, 'index'])->name('app.labels.index'); + Route::post('labels', [WorkspaceLabelController::class, 'store'])->name('app.labels.store'); + Route::put('labels/{label}', [WorkspaceLabelController::class, 'update'])->name('app.labels.update'); + Route::delete('labels/{label}', [WorkspaceLabelController::class, 'destroy'])->name('app.labels.destroy'); + + // API Keys + Route::get('api-keys', [ApiKeyController::class, 'index'])->name('app.api-keys.index'); + Route::post('api-keys', [ApiKeyController::class, 'store'])->name('app.api-keys.store'); + Route::delete('api-keys/{apiToken}', [ApiKeyController::class, 'destroy'])->name('app.api-keys.destroy'); + + // Billing + Route::get('settings/billing', [BillingController::class, 'index'])->name('app.billing.index'); + Route::get('settings/billing/portal', [BillingController::class, 'portal'])->name('app.billing.portal'); + }); + + // Settings (auth required) + Route::middleware(['auth'])->group(function () { + Route::get('settings/profile', [ProfileController::class, 'edit'])->name('app.profile.edit'); + Route::patch('settings/profile', [ProfileController::class, 'update'])->name('app.profile.update'); + Route::patch('settings/language', [ProfileController::class, 'updateLanguage'])->name('app.profile.language'); + }); + + Route::middleware(['auth', 'verified'])->group(function () { + Route::delete('settings/profile', [ProfileController::class, 'destroy'])->name('app.profile.destroy'); + Route::get('settings/password', [PasswordController::class, 'edit'])->name('app.user-password.edit'); + Route::put('settings/password', [PasswordController::class, 'update']) + ->middleware('throttle:6,1') + ->name('app.user-password.update'); + }); + } +); diff --git a/routes/auth.php b/routes/auth.php index be29bbc3..2ac434db 100644 --- a/routes/auth.php +++ b/routes/auth.php @@ -12,35 +12,44 @@ use App\Http\Controllers\Auth\VerifyEmailController; use Illuminate\Support\Facades\Route; -Route::middleware('guest')->group(function () { - Route::get('/register', [RegisteredUserController::class, 'create'])->name('register'); - Route::post('/register', [RegisteredUserController::class, 'store'])->name('register.store'); +Route::group( + [ + 'domain' => 'app.'.parse_url(config('app.url'), PHP_URL_HOST), + 'middleware' => ['web'], + ], + function () { - Route::get('/login', [AuthenticatedSessionController::class, 'create'])->name('login'); - Route::post('/login', [AuthenticatedSessionController::class, 'store'])->name('login.store'); + Route::middleware('guest')->group(function () { + Route::get('/register', [RegisteredUserController::class, 'create'])->name('register'); + Route::post('/register', [RegisteredUserController::class, 'store'])->name('register.store'); - Route::get('/forgot-password', [PasswordResetLinkController::class, 'create'])->name('password.request'); - Route::post('/forgot-password', [PasswordResetLinkController::class, 'store'])->name('password.email'); + Route::get('/login', [AuthenticatedSessionController::class, 'create'])->name('login'); + Route::post('/login', [AuthenticatedSessionController::class, 'store'])->name('login.store'); - Route::get('/reset-password/{token}', [NewPasswordController::class, 'create'])->name('password.reset'); - Route::post('/reset-password', [NewPasswordController::class, 'store'])->name('password.store'); -}); + Route::get('/forgot-password', [PasswordResetLinkController::class, 'create'])->name('password.request'); + Route::post('/forgot-password', [PasswordResetLinkController::class, 'store'])->name('password.email'); -// Invite routes - accessible by both guests and authenticated users -Route::get('/invites/{invite}', [AcceptInviteController::class, 'show'])->name('invites.show'); -Route::post('/invites/{invite}/accept', [AcceptInviteController::class, 'accept'])->name('invites.accept')->middleware('auth'); -Route::post('/invites/{invite}/decline', [AcceptInviteController::class, 'decline'])->name('invites.decline')->middleware('auth'); + Route::get('/reset-password/{token}', [NewPasswordController::class, 'create'])->name('password.reset'); + Route::post('/reset-password', [NewPasswordController::class, 'store'])->name('password.store'); + }); -Route::middleware('auth')->group(function () { - Route::get('/verify-email', EmailVerificationPromptController::class)->name('verification.notice'); + // Invite routes - accessible by both guests and authenticated users + Route::get('/invites/{invite}', [AcceptInviteController::class, 'show'])->name('app.invites.show'); + Route::post('/invites/{invite}/accept', [AcceptInviteController::class, 'accept'])->name('app.invites.accept')->middleware('auth'); + Route::post('/invites/{invite}/decline', [AcceptInviteController::class, 'decline'])->name('app.invites.decline')->middleware('auth'); - Route::get('/verify-email/{id}/{hash}', VerifyEmailController::class) - ->middleware(['signed', 'throttle:6,1']) - ->name('verification.verify'); + Route::middleware('auth')->group(function () { + Route::get('/verify-email', EmailVerificationPromptController::class)->name('verification.notice'); - Route::post('/email/verification-notification', [EmailVerificationNotificationController::class, 'store']) - ->middleware('throttle:6,1') - ->name('verification.send'); + Route::get('/verify-email/{id}/{hash}', VerifyEmailController::class) + ->middleware(['signed', 'throttle:6,1']) + ->name('verification.verify'); - Route::post('/logout', [AuthenticatedSessionController::class, 'destroy'])->name('logout'); -}); + Route::post('/email/verification-notification', [EmailVerificationNotificationController::class, 'store']) + ->middleware('throttle:6,1') + ->name('verification.send'); + + Route::post('/logout', [AuthenticatedSessionController::class, 'destroy'])->name('logout'); + }); + + }); // end domain group diff --git a/routes/web.php b/routes/web.php index 4986a5d3..0086ce7e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,148 +1,4 @@ route('calendar'); -})->name('home')->middleware(['auth', 'verified']); - -// Subscription selection (requires auth but not subscription) -Route::middleware(['auth', 'verified'])->group(function () { - Route::get('subscribe', [BillingController::class, 'subscribe'])->name('subscribe'); - Route::post('billing/checkout', [BillingController::class, 'checkout'])->name('billing.checkout'); - Route::get('billing/processing', [BillingController::class, 'processing'])->name('billing.processing'); -}); - -// Onboarding routes (requires auth but not subscription or setup complete) -Route::middleware(['auth', 'verified'])->prefix('onboarding')->group(function () { - Route::get('step1', [OnboardingController::class, 'step1'])->name('onboarding.step1'); - Route::post('step1', [OnboardingController::class, 'storeStep1'])->name('onboarding.step1.store'); - Route::get('step2', [OnboardingController::class, 'step2'])->name('onboarding.step2'); - Route::post('step2', [OnboardingController::class, 'storeStep2'])->name('onboarding.step2.store'); - Route::get('complete', [OnboardingController::class, 'complete'])->name('onboarding.complete'); -}); - -// Social Connect routes (requires auth but not subscription - needed for onboarding) -Route::middleware(['auth', 'verified'])->group(function () { - Route::get('connect/linkedin', [LinkedInController::class, 'connect'])->name('social.linkedin.connect'); - Route::get('accounts/linkedin/callback', [LinkedInController::class, 'callback'])->name('social.linkedin.callback'); - - Route::get('connect/linkedin-page', [LinkedInPageController::class, 'connect'])->name('social.linkedin-page.connect'); - Route::get('accounts/linkedin-page/callback', [LinkedInPageController::class, 'callback'])->name('social.linkedin-page.callback'); - Route::get('accounts/linkedin-page/select', [LinkedInPageController::class, 'selectPage'])->name('social.linkedin-page.select-page'); - Route::post('accounts/linkedin-page/select', [LinkedInPageController::class, 'select'])->name('social.linkedin-page.select'); - - Route::get('connect/x', [XController::class, 'connect'])->name('social.x.connect'); - Route::get('accounts/x/callback', [XController::class, 'callback'])->name('social.x.callback'); - - Route::get('connect/tiktok', [TikTokController::class, 'connect'])->name('social.tiktok.connect'); - Route::get('accounts/tiktok/callback', [TikTokController::class, 'callback'])->name('social.tiktok.callback'); - - Route::get('connect/youtube', [YouTubeController::class, 'connect'])->name('social.youtube.connect'); - Route::get('accounts/youtube/callback', [YouTubeController::class, 'callback'])->name('social.youtube.callback'); - Route::get('accounts/youtube/select', [YouTubeController::class, 'selectChannel'])->name('social.youtube.select-channel'); - Route::post('accounts/youtube/select', [YouTubeController::class, 'select'])->name('social.youtube.select'); - - Route::get('connect/facebook', [FacebookController::class, 'connect'])->name('social.facebook.connect'); - Route::get('accounts/facebook/callback', [FacebookController::class, 'callback'])->name('social.facebook.callback'); - Route::get('accounts/facebook/select', [FacebookController::class, 'selectPage'])->name('social.facebook.select-page'); - Route::post('accounts/facebook/select', [FacebookController::class, 'select'])->name('social.facebook.select'); - - Route::get('connect/instagram', [InstagramController::class, 'connect'])->name('social.instagram.connect'); - Route::get('accounts/instagram/callback', [InstagramController::class, 'callback'])->name('social.instagram.callback'); - Route::get('accounts/instagram/select', [InstagramController::class, 'selectAccount'])->name('social.instagram.select-account'); - Route::post('accounts/instagram/select', [InstagramController::class, 'select'])->name('social.instagram.select'); - - Route::get('connect/threads', [ThreadsController::class, 'connect'])->name('social.threads.connect'); - Route::get('accounts/threads/callback', [ThreadsController::class, 'callback'])->name('social.threads.callback'); - - Route::get('connect/pinterest', [PinterestController::class, 'connect'])->name('social.pinterest.connect'); - Route::get('accounts/pinterest/callback', [PinterestController::class, 'callback'])->name('social.pinterest.callback'); - - Route::get('connect/bluesky', [BlueskyController::class, 'connect'])->name('social.bluesky.connect'); - Route::post('connect/bluesky', [BlueskyController::class, 'store'])->name('social.bluesky.store'); - - Route::get('connect/mastodon', [MastodonController::class, 'connect'])->name('social.mastodon.connect'); - Route::post('connect/mastodon', [MastodonController::class, 'authorizeInstance'])->name('social.mastodon.authorize'); - Route::get('accounts/mastodon/callback', [MastodonController::class, 'callback'])->name('social.mastodon.callback'); -}); - -// Routes that require active subscription and completed onboarding -Route::middleware(['auth', 'verified', 'subscribed', EnsureUserSetupIsComplete::class])->group(function () { - // Workspaces management - Route::get('workspaces', [WorkspaceController::class, 'index'])->name('workspaces.index'); - Route::get('workspaces/create', [WorkspaceController::class, 'create'])->name('workspaces.create'); - Route::post('workspaces', [WorkspaceController::class, 'store'])->name('workspaces.store'); - Route::post('workspaces/{workspace}/switch', [WorkspaceController::class, 'switch'])->name('workspaces.switch'); - Route::delete('workspaces/{workspace}', [WorkspaceController::class, 'destroy'])->name('workspaces.destroy'); - - // Current workspace settings - Route::get('settings/workspace', [WorkspaceController::class, 'settings'])->name('workspace.settings'); - Route::put('settings/workspace', [WorkspaceController::class, 'updateSettings'])->name('workspace.settings.update'); - - // Social Accounts - Route::get('accounts', [SocialController::class, 'index'])->name('accounts'); - Route::delete('accounts/{account}', [SocialController::class, 'disconnect'])->name('accounts.disconnect'); - - // Calendar - Route::get('calendar', [PostController::class, 'calendar'])->name('calendar'); - - // Posts - Route::get('posts/{status?}', [PostController::class, 'index'])->name('posts.index')->where('status', 'draft|scheduled|published'); - Route::post('posts', [PostController::class, 'store'])->name('posts.store'); - Route::get('posts/{post}/edit', [PostController::class, 'edit'])->name('posts.edit'); - Route::put('posts/{post}', [PostController::class, 'update'])->name('posts.update'); - Route::delete('posts/{post}', [PostController::class, 'destroy'])->name('posts.destroy'); - - // Media - Route::post('medias', [MediaController::class, 'store'])->name('medias.store'); - Route::post('medias/chunked', [MediaController::class, 'storeChunked'])->name('medias.store-chunked'); - Route::post('medias/reorder', [MediaController::class, 'reorder'])->name('medias.reorder'); - Route::post('medias/{media}/duplicate', [MediaController::class, 'duplicate'])->name('medias.duplicate'); - Route::delete('medias/{modelId}/{media}', [MediaController::class, 'destroy'])->name('medias.destroy'); - - // Members (Settings) - Route::get('settings/members', [WorkspaceInviteController::class, 'index'])->name('members'); - Route::post('settings/members/invites', [WorkspaceInviteController::class, 'store'])->name('invites.store'); - Route::delete('settings/members/invites/{invite}', [WorkspaceInviteController::class, 'destroy'])->name('invites.destroy'); - Route::delete('settings/members/{user}', [WorkspaceInviteController::class, 'removeMember'])->name('members.remove'); - - // Hashtags - Route::get('hashtags', [WorkspaceHashtagController::class, 'index'])->name('hashtags.index'); - Route::post('hashtags', [WorkspaceHashtagController::class, 'store'])->name('hashtags.store'); - Route::put('hashtags/{hashtag}', [WorkspaceHashtagController::class, 'update'])->name('hashtags.update'); - Route::delete('hashtags/{hashtag}', [WorkspaceHashtagController::class, 'destroy'])->name('hashtags.destroy'); - - // Labels - Route::get('labels', [WorkspaceLabelController::class, 'index'])->name('labels.index'); - Route::post('labels', [WorkspaceLabelController::class, 'store'])->name('labels.store'); - Route::put('labels/{label}', [WorkspaceLabelController::class, 'update'])->name('labels.update'); - Route::delete('labels/{label}', [WorkspaceLabelController::class, 'destroy'])->name('labels.destroy'); - - // Billing (under settings prefix) - Route::get('settings/billing', [BillingController::class, 'index'])->name('billing.index'); - Route::get('settings/billing/portal', [BillingController::class, 'portal'])->name('billing.portal'); -}); - -require __DIR__.'/settings.php'; +require __DIR__.'/auth.php'; +require __DIR__.'/app.php'; diff --git a/tests/Feature/AcceptInviteControllerTest.php b/tests/Feature/AcceptInviteControllerTest.php index ce9d5dfc..66e1c491 100644 --- a/tests/Feature/AcceptInviteControllerTest.php +++ b/tests/Feature/AcceptInviteControllerTest.php @@ -20,7 +20,7 @@ 'role' => WorkspaceRole::Member, ]); - $response = $this->get(route('invites.show', $invite)); + $response = $this->get(route('app.invites.show', $invite)); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -45,7 +45,7 @@ 'role' => WorkspaceRole::Member, ]); - $response = $this->actingAs($user)->get(route('invites.show', $invite)); + $response = $this->actingAs($user)->get(route('app.invites.show', $invite)); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -55,7 +55,7 @@ }); test('show invite returns 404 for non-existent invite', function () { - $response = $this->get(route('invites.show', 'non-existent-uuid')); + $response = $this->get(route('app.invites.show', 'non-existent-uuid')); $response->assertNotFound(); }); @@ -65,7 +65,7 @@ 'workspace_id' => $this->workspace->id, ]); - $response = $this->post(route('invites.accept', $invite)); + $response = $this->post(route('app.invites.accept', $invite)); $response->assertRedirect(route('login')); }); @@ -82,9 +82,9 @@ 'role' => WorkspaceRole::Admin, ]); - $response = $this->actingAs($user)->post(route('invites.accept', $invite)); + $response = $this->actingAs($user)->post(route('app.invites.accept', $invite)); - $response->assertRedirect(route('calendar')); + $response->assertRedirect(route('app.calendar')); // User should be member of workspace expect($this->workspace->hasMember($user))->toBeTrue(); @@ -109,9 +109,9 @@ 'role' => WorkspaceRole::Member, ]); - $response = $this->actingAs($user)->post(route('invites.accept', $invite)); + $response = $this->actingAs($user)->post(route('app.invites.accept', $invite)); - $response->assertRedirect(route('calendar')); + $response->assertRedirect(route('app.calendar')); $response->assertSessionHas('flash.bannerStyle', 'danger'); // Invite should NOT be deleted @@ -132,9 +132,9 @@ 'role' => WorkspaceRole::Admin, ]); - $response = $this->actingAs($user)->post(route('invites.accept', $invite)); + $response = $this->actingAs($user)->post(route('app.invites.accept', $invite)); - $response->assertRedirect(route('calendar')); + $response->assertRedirect(route('app.calendar')); $response->assertSessionHas('flash.bannerStyle', 'info'); // Invite should be deleted @@ -146,7 +146,7 @@ 'workspace_id' => $this->workspace->id, ]); - $response = $this->post(route('invites.decline', $invite)); + $response = $this->post(route('app.invites.decline', $invite)); $response->assertRedirect(route('login')); }); @@ -163,9 +163,9 @@ 'role' => WorkspaceRole::Member, ]); - $response = $this->actingAs($user)->post(route('invites.decline', $invite)); + $response = $this->actingAs($user)->post(route('app.invites.decline', $invite)); - $response->assertRedirect(route('calendar')); + $response->assertRedirect(route('app.calendar')); $response->assertSessionHas('flash.bannerStyle', 'info'); // Invite should be deleted @@ -187,9 +187,9 @@ 'role' => WorkspaceRole::Member, ]); - $response = $this->actingAs($user)->post(route('invites.decline', $invite)); + $response = $this->actingAs($user)->post(route('app.invites.decline', $invite)); - $response->assertRedirect(route('calendar')); + $response->assertRedirect(route('app.calendar')); $response->assertSessionHas('flash.bannerStyle', 'danger'); // Invite should NOT be deleted diff --git a/tests/Feature/Auth/AuthenticationTest.php b/tests/Feature/Auth/AuthenticationTest.php index 17a0bfb5..770d6062 100644 --- a/tests/Feature/Auth/AuthenticationTest.php +++ b/tests/Feature/Auth/AuthenticationTest.php @@ -19,7 +19,7 @@ ]); $this->assertAuthenticated(); - $response->assertRedirect(route('calendar', absolute: false)); + $response->assertRedirect(route('app.calendar', absolute: false)); }); test('users can not authenticate with invalid password', function () { diff --git a/tests/Feature/Auth/EmailVerificationTest.php b/tests/Feature/Auth/EmailVerificationTest.php index eff01195..1abc32c9 100644 --- a/tests/Feature/Auth/EmailVerificationTest.php +++ b/tests/Feature/Auth/EmailVerificationTest.php @@ -28,7 +28,7 @@ Event::assertDispatched(Verified::class); expect($user->fresh()->hasVerifiedEmail())->toBeTrue(); - $response->assertRedirect(route('calendar', absolute: false).'?verified=1'); + $response->assertRedirect(route('app.calendar', absolute: false).'?verified=1'); }); test('email is not verified with invalid hash', function () { @@ -73,7 +73,7 @@ $response = $this->actingAs($user)->get(route('verification.notice')); Event::assertNotDispatched(Verified::class); - $response->assertRedirect(route('calendar', absolute: false)); + $response->assertRedirect(route('app.calendar', absolute: false)); }); test('already verified user visiting verification link is redirected without firing event again', function () { @@ -88,7 +88,7 @@ ); $this->actingAs($user)->get($verificationUrl) - ->assertRedirect(route('calendar', absolute: false).'?verified=1'); + ->assertRedirect(route('app.calendar', absolute: false).'?verified=1'); Event::assertNotDispatched(Verified::class); expect($user->fresh()->hasVerifiedEmail())->toBeTrue(); diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php index 3a5924e1..1ea65128 100644 --- a/tests/Feature/Auth/RegistrationTest.php +++ b/tests/Feature/Auth/RegistrationTest.php @@ -17,7 +17,7 @@ $response->assertSessionHasNoErrors(); $this->assertAuthenticated(); - $response->assertRedirect(route('onboarding.step1', absolute: false)); + $response->assertRedirect(route('app.onboarding.step1', absolute: false)); }); test('new users get a default workspace on registration', function () { diff --git a/tests/Feature/Auth/VerificationNotificationTest.php b/tests/Feature/Auth/VerificationNotificationTest.php index 81bdd287..adec9f6b 100644 --- a/tests/Feature/Auth/VerificationNotificationTest.php +++ b/tests/Feature/Auth/VerificationNotificationTest.php @@ -11,7 +11,7 @@ $this->actingAs($user) ->post(route('verification.send')) - ->assertRedirect(route('home')); + ->assertRedirect(route('app.home')); Notification::assertSentTo($user, VerifyEmail::class); }); @@ -23,7 +23,7 @@ $this->actingAs($user) ->post(route('verification.send')) - ->assertRedirect(route('calendar', absolute: false)); + ->assertRedirect(route('app.calendar', absolute: false)); Notification::assertNothingSent(); }); diff --git a/tests/Feature/BillingControllerTest.php b/tests/Feature/BillingControllerTest.php index 13bdc8f3..2ed7ed5c 100644 --- a/tests/Feature/BillingControllerTest.php +++ b/tests/Feature/BillingControllerTest.php @@ -12,13 +12,13 @@ // Subscribe tests test('subscribe requires authentication', function () { - $response = $this->get(route('subscribe')); + $response = $this->get(route('app.subscribe')); $response->assertRedirect(route('login')); }); test('subscribe shows subscription page', function () { - $response = $this->actingAs($this->user)->get(route('subscribe')); + $response = $this->actingAs($this->user)->get(route('app.subscribe')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -29,13 +29,13 @@ // Index tests test('billing index requires authentication', function () { - $response = $this->get(route('billing.index')); + $response = $this->get(route('app.billing.index')); $response->assertRedirect(route('login')); }); test('billing index shows billing dashboard', function () { - $response = $this->actingAs($this->user)->get(route('billing.index')); + $response = $this->actingAs($this->user)->get(route('app.billing.index')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -47,13 +47,13 @@ // Processing tests test('billing processing requires authentication', function () { - $response = $this->get(route('billing.processing')); + $response = $this->get(route('app.billing.processing')); $response->assertRedirect(route('login')); }); test('billing processing shows processing page', function () { - $response = $this->actingAs($this->user)->get(route('billing.processing')); + $response = $this->actingAs($this->user)->get(route('app.billing.processing')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -64,7 +64,7 @@ }); test('billing processing accepts status parameter', function () { - $response = $this->actingAs($this->user)->get(route('billing.processing', ['status' => 'success'])); + $response = $this->actingAs($this->user)->get(route('app.billing.processing', ['status' => 'success'])); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -73,7 +73,7 @@ }); test('billing processing validates status parameter', function () { - $response = $this->actingAs($this->user)->get(route('billing.processing', ['status' => 'invalid'])); + $response = $this->actingAs($this->user)->get(route('app.billing.processing', ['status' => 'invalid'])); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -83,14 +83,14 @@ // Checkout tests test('checkout requires authentication', function () { - $response = $this->post(route('billing.checkout')); + $response = $this->post(route('app.billing.checkout')); $response->assertRedirect(route('login')); }); // Portal tests test('portal requires authentication', function () { - $response = $this->get(route('billing.portal')); + $response = $this->get(route('app.billing.portal')); $response->assertRedirect(route('login')); }); diff --git a/tests/Feature/Controllers/BillingControllerTest.php b/tests/Feature/Controllers/BillingControllerTest.php index 4bbeaa4b..758ff111 100644 --- a/tests/Feature/Controllers/BillingControllerTest.php +++ b/tests/Feature/Controllers/BillingControllerTest.php @@ -21,7 +21,7 @@ 'quantity' => 2, ]); - $response = $this->actingAs($this->user)->get(route('billing.index')); + $response = $this->actingAs($this->user)->get(route('app.billing.index')); $response->assertSuccessful(); $response->assertInertia(fn ($page) => $page @@ -33,7 +33,7 @@ }); test('billing index shows info for user without subscription', function () { - $response = $this->actingAs($this->user)->get(route('billing.index')); + $response = $this->actingAs($this->user)->get(route('app.billing.index')); $response->assertSuccessful(); $response->assertInertia(fn ($page) => $page @@ -52,7 +52,7 @@ 'trial_ends_at' => now()->addDays(14), ]); - $response = $this->actingAs($this->user)->get(route('billing.index')); + $response = $this->actingAs($this->user)->get(route('app.billing.index')); $response->assertSuccessful(); $response->assertInertia(fn ($page) => $page @@ -63,7 +63,7 @@ }); test('processing page shows for user during checkout', function () { - $response = $this->actingAs($this->user)->get(route('billing.processing', ['status' => 'success'])); + $response = $this->actingAs($this->user)->get(route('app.billing.processing', ['status' => 'success'])); $response->assertSuccessful(); $response->assertInertia(fn ($page) => $page @@ -74,7 +74,7 @@ }); test('processing page shows cancelled status', function () { - $response = $this->actingAs($this->user)->get(route('billing.processing', ['status' => 'cancelled'])); + $response = $this->actingAs($this->user)->get(route('app.billing.processing', ['status' => 'cancelled'])); $response->assertSuccessful(); $response->assertInertia(fn ($page) => $page @@ -83,7 +83,7 @@ }); test('processing page defaults to processing status for invalid status', function () { - $response = $this->actingAs($this->user)->get(route('billing.processing', ['status' => 'invalid'])); + $response = $this->actingAs($this->user)->get(route('app.billing.processing', ['status' => 'invalid'])); $response->assertSuccessful(); $response->assertInertia(fn ($page) => $page diff --git a/tests/Feature/Controllers/ChunkedUploadTest.php b/tests/Feature/Controllers/ChunkedUploadTest.php index 2de2deb1..ca7804cd 100644 --- a/tests/Feature/Controllers/ChunkedUploadTest.php +++ b/tests/Feature/Controllers/ChunkedUploadTest.php @@ -27,7 +27,7 @@ $response = $this->actingAs($this->user)->call( 'POST', - route('medias.store-chunked'), + route('app.medias.store-chunked'), [], [], [], @@ -56,7 +56,7 @@ $response = $this->actingAs($this->user)->call( 'POST', - route('medias.store-chunked'), + route('app.medias.store-chunked'), [], [], [], @@ -88,7 +88,7 @@ // First chunk $this->actingAs($this->user)->call( 'POST', - route('medias.store-chunked'), + route('app.medias.store-chunked'), [], [], [], @@ -107,7 +107,7 @@ // Second chunk (last) $response = $this->actingAs($this->user)->call( 'POST', - route('medias.store-chunked'), + route('app.medias.store-chunked'), [], [], [], @@ -131,7 +131,7 @@ test('chunked upload fails without content range header', function () { $response = $this->actingAs($this->user)->call( 'POST', - route('medias.store-chunked'), + route('app.medias.store-chunked'), [], [], [], @@ -152,7 +152,7 @@ test('chunked upload fails with invalid model type', function () { $response = $this->actingAs($this->user)->call( 'POST', - route('medias.store-chunked'), + route('app.medias.store-chunked'), [], [], [], @@ -174,7 +174,7 @@ test('chunked upload fails without model header', function () { $response = $this->actingAs($this->user)->call( 'POST', - route('medias.store-chunked'), + route('app.medias.store-chunked'), [], [], [], @@ -194,7 +194,7 @@ test('chunked upload fails without file name header', function () { $response = $this->actingAs($this->user)->call( 'POST', - route('medias.store-chunked'), + route('app.medias.store-chunked'), [], [], [], @@ -219,7 +219,7 @@ $this->actingAs($this->user)->call( 'POST', - route('medias.store-chunked'), + route('app.medias.store-chunked'), [], [], [], diff --git a/tests/Feature/Controllers/MediaControllerTest.php b/tests/Feature/Controllers/MediaControllerTest.php index 2cea97af..624b56ca 100644 --- a/tests/Feature/Controllers/MediaControllerTest.php +++ b/tests/Feature/Controllers/MediaControllerTest.php @@ -3,6 +3,7 @@ use App\Enums\User\Setup; use App\Models\Media; use App\Models\PostPlatform; +use App\Models\SocialAccount; use App\Models\User; use App\Models\Workspace; use Illuminate\Http\UploadedFile; @@ -27,7 +28,7 @@ test('user can upload media to workspace', function () { $file = UploadedFile::fake()->image('logo.jpg', 100, 100); - $response = $this->actingAs($this->user)->postJson(route('medias.store'), [ + $response = $this->actingAs($this->user)->postJson(route('app.medias.store'), [ 'media' => $file, 'model' => 'workspace', 'model_id' => $this->workspace->id, @@ -43,7 +44,7 @@ $file = UploadedFile::fake()->image('logo.jpg', 100, 100); $media = $this->workspace->addMedia($file, 'logo'); - $response = $this->actingAs($this->user)->deleteJson(route('medias.destroy', [ + $response = $this->actingAs($this->user)->deleteJson(route('app.medias.destroy', [ 'modelId' => $this->workspace->id, 'media' => $media->id, ])); @@ -58,7 +59,7 @@ $otherWorkspace = Workspace::factory()->create(); - $response = $this->actingAs($this->user)->deleteJson(route('medias.destroy', [ + $response = $this->actingAs($this->user)->deleteJson(route('app.medias.destroy', [ 'modelId' => $otherWorkspace->id, 'media' => $media->id, ])); @@ -71,12 +72,12 @@ $media = $this->workspace->addMedia($file, 'default'); $postPlatform = PostPlatform::factory()->create([ - 'social_account_id' => \App\Models\SocialAccount::factory()->linkedin()->create([ + 'social_account_id' => SocialAccount::factory()->linkedin()->create([ 'workspace_id' => $this->workspace->id, ])->id, ]); - $response = $this->actingAs($this->user)->postJson(route('medias.duplicate', ['media' => $media->id]), [ + $response = $this->actingAs($this->user)->postJson(route('app.medias.duplicate', ['media' => $media->id]), [ 'targets' => [ [ 'model' => 'postPlatform', @@ -93,7 +94,7 @@ test('media store fails with invalid model type', function () { $file = UploadedFile::fake()->image('logo.jpg', 100, 100); - $response = $this->actingAs($this->user)->postJson(route('medias.store'), [ + $response = $this->actingAs($this->user)->postJson(route('app.medias.store'), [ 'media' => $file, 'model' => 'invalid', 'model_id' => $this->workspace->id, diff --git a/tests/Feature/Controllers/OnboardingControllerTest.php b/tests/Feature/Controllers/OnboardingControllerTest.php index b7df7066..ca7db7ed 100644 --- a/tests/Feature/Controllers/OnboardingControllerTest.php +++ b/tests/Feature/Controllers/OnboardingControllerTest.php @@ -12,7 +12,7 @@ }); test('step1 shows persona selection', function () { - $response = $this->actingAs($this->user)->get(route('onboarding.step1')); + $response = $this->actingAs($this->user)->get(route('app.onboarding.step1')); $response->assertSuccessful(); $response->assertInertia(fn ($page) => $page @@ -22,17 +22,17 @@ }); test('step1 can be stored with valid persona', function () { - $response = $this->actingAs($this->user)->post(route('onboarding.step1.store'), [ + $response = $this->actingAs($this->user)->post(route('app.onboarding.step1.store'), [ 'persona' => Persona::Creator->value, ]); - $response->assertRedirect(route('onboarding.step2')); + $response->assertRedirect(route('app.onboarding.step2')); expect($this->user->fresh()->persona)->toBe(Persona::Creator); expect($this->user->fresh()->setup)->toBe(Setup::Connections); }); test('step1 fails with invalid persona', function () { - $response = $this->actingAs($this->user)->post(route('onboarding.step1.store'), [ + $response = $this->actingAs($this->user)->post(route('app.onboarding.step1.store'), [ 'persona' => 'invalid', ]); @@ -44,7 +44,7 @@ $workspace = Workspace::factory()->create(['user_id' => $this->user->id]); $this->user->update(['current_workspace_id' => $workspace->id]); - $response = $this->actingAs($this->user)->get(route('onboarding.step2')); + $response = $this->actingAs($this->user)->get(route('app.onboarding.step2')); $response->assertSuccessful(); $response->assertInertia(fn ($page) => $page @@ -57,7 +57,7 @@ test('step2 shows without workspace', function () { $this->user->update(['setup' => Setup::Connections]); - $response = $this->actingAs($this->user)->get(route('onboarding.step2')); + $response = $this->actingAs($this->user)->get(route('app.onboarding.step2')); $response->assertSuccessful(); $response->assertInertia(fn ($page) => $page @@ -69,17 +69,17 @@ config(['trypost.self_hosted' => true]); $this->user->update(['setup' => Setup::Connections]); - $response = $this->actingAs($this->user)->post(route('onboarding.step2.store')); + $response = $this->actingAs($this->user)->post(route('app.onboarding.step2.store')); - $response->assertRedirect(route('calendar')); + $response->assertRedirect(route('app.calendar')); expect($this->user->fresh()->setup)->toBe(Setup::Completed); }); test('complete sets setup to completed', function () { $this->user->update(['setup' => Setup::Subscription]); - $response = $this->actingAs($this->user)->get(route('onboarding.complete')); + $response = $this->actingAs($this->user)->get(route('app.onboarding.complete')); - $response->assertRedirect(route('calendar')); + $response->assertRedirect(route('app.calendar')); expect($this->user->fresh()->setup)->toBe(Setup::Completed); }); diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php index eb11b08f..0c41590f 100644 --- a/tests/Feature/ExampleTest.php +++ b/tests/Feature/ExampleTest.php @@ -3,7 +3,7 @@ use App\Models\User; test('home redirects to login for guests', function () { - $response = $this->get(route('home')); + $response = $this->get(route('app.home')); $response->assertRedirect(route('login')); }); @@ -11,7 +11,7 @@ test('home redirects to calendar for authenticated users', function () { $user = User::factory()->create(); - $response = $this->actingAs($user)->get(route('home')); + $response = $this->actingAs($user)->get(route('app.home')); - $response->assertRedirect(route('calendar')); + $response->assertRedirect(route('app.calendar')); }); diff --git a/tests/Feature/Jobs/PublishToSocialPlatformTest.php b/tests/Feature/Jobs/PublishToSocialPlatformTest.php index 0a11383c..574fb62a 100644 --- a/tests/Feature/Jobs/PublishToSocialPlatformTest.php +++ b/tests/Feature/Jobs/PublishToSocialPlatformTest.php @@ -70,7 +70,7 @@ Event::fake(); $publisher = Mockery::mock(LinkedInPublisher::class); - $publisher->shouldReceive('publish')->andThrow(new \Exception('API Error')); + $publisher->shouldReceive('publish')->andThrow(new Exception('API Error')); $this->app->instance(LinkedInPublisher::class, $publisher); @@ -147,7 +147,7 @@ Event::fake(); $publisher = Mockery::mock(LinkedInPublisher::class); - $publisher->shouldReceive('publish')->andThrow(new \Exception('API Error')); + $publisher->shouldReceive('publish')->andThrow(new Exception('API Error')); $this->app->instance(LinkedInPublisher::class, $publisher); diff --git a/tests/Feature/MediaControllerTest.php b/tests/Feature/MediaControllerTest.php index 2ef3fd92..c8a0e19b 100644 --- a/tests/Feature/MediaControllerTest.php +++ b/tests/Feature/MediaControllerTest.php @@ -29,7 +29,7 @@ // Store tests test('store media requires authentication', function () { - $response = $this->post(route('medias.store'), [ + $response = $this->post(route('app.medias.store'), [ 'model' => 'postPlatform', 'model_id' => $this->postPlatform->id, 'media' => UploadedFile::fake()->image('test.jpg'), @@ -39,7 +39,7 @@ }); test('store media uploads file', function () { - $response = $this->actingAs($this->user)->post(route('medias.store'), [ + $response = $this->actingAs($this->user)->post(route('app.medias.store'), [ 'model' => 'postPlatform', 'model_id' => $this->postPlatform->id, 'media' => UploadedFile::fake()->image('test.jpg'), @@ -50,7 +50,7 @@ }); test('store media validates required fields', function () { - $response = $this->actingAs($this->user)->post(route('medias.store'), [ + $response = $this->actingAs($this->user)->post(route('app.medias.store'), [ 'model' => '', 'model_id' => '', ]); @@ -65,7 +65,7 @@ 'mediable_type' => 'postPlatform', ]); - $response = $this->delete(route('medias.destroy', [$this->postPlatform->id, $media])); + $response = $this->delete(route('app.medias.destroy', [$this->postPlatform->id, $media])); $response->assertRedirect(route('login')); }); @@ -76,7 +76,7 @@ 'mediable_type' => 'postPlatform', ]); - $response = $this->actingAs($this->user)->delete(route('medias.destroy', [$this->postPlatform->id, $media])); + $response = $this->actingAs($this->user)->delete(route('app.medias.destroy', [$this->postPlatform->id, $media])); $response->assertOk(); $response->assertJson(['success' => true]); @@ -94,7 +94,7 @@ 'mediable_type' => 'postPlatform', ]); - $response = $this->actingAs($this->user)->delete(route('medias.destroy', [$this->postPlatform->id, $media])); + $response = $this->actingAs($this->user)->delete(route('app.medias.destroy', [$this->postPlatform->id, $media])); $response->assertForbidden(); }); @@ -106,7 +106,7 @@ 'mediable_type' => 'postPlatform', ]); - $response = $this->post(route('medias.duplicate', $media), [ + $response = $this->post(route('app.medias.duplicate', $media), [ 'targets' => [], ]); @@ -124,7 +124,7 @@ 'social_account_id' => $this->socialAccount->id, ]); - $response = $this->actingAs($this->user)->post(route('medias.duplicate', $media), [ + $response = $this->actingAs($this->user)->post(route('app.medias.duplicate', $media), [ 'targets' => [ [ 'model' => 'postPlatform', diff --git a/tests/Feature/Middleware/EnsureSubscribedTest.php b/tests/Feature/Middleware/EnsureSubscribedTest.php index 89f3a8b6..042cb6cd 100644 --- a/tests/Feature/Middleware/EnsureSubscribedTest.php +++ b/tests/Feature/Middleware/EnsureSubscribedTest.php @@ -13,14 +13,14 @@ $user->update(['current_workspace_id' => $workspace->id]); $this->actingAs($user) - ->get(route('calendar')) + ->get(route('app.calendar')) ->assertOk(); }); test('unauthenticated user is redirected to login', function () { config(['trypost.self_hosted' => false]); - $this->get(route('calendar')) + $this->get(route('app.calendar')) ->assertRedirect(route('login')); }); @@ -40,7 +40,7 @@ ]); $this->actingAs($user) - ->get(route('calendar')) + ->get(route('app.calendar')) ->assertOk(); }); @@ -62,7 +62,7 @@ ]); $this->actingAs($user) - ->get(route('calendar')) + ->get(route('app.calendar')) ->assertOk(); }); @@ -75,8 +75,8 @@ $user->update(['current_workspace_id' => $workspace->id]); $this->actingAs($user) - ->get(route('calendar')) - ->assertRedirect(route('subscribe')); + ->get(route('app.calendar')) + ->assertRedirect(route('app.subscribe')); }); test('user with expired trial subscription is redirected to subscribe page', function () { @@ -98,8 +98,8 @@ ]); $this->actingAs($user) - ->get(route('calendar')) - ->assertRedirect(route('subscribe')); + ->get(route('app.calendar')) + ->assertRedirect(route('app.subscribe')); }); test('user with cancelled subscription is redirected to subscribe page', function () { @@ -119,8 +119,8 @@ ]); $this->actingAs($user) - ->get(route('calendar')) - ->assertRedirect(route('subscribe')); + ->get(route('app.calendar')) + ->assertRedirect(route('app.subscribe')); }); test('invited member can access workspace when owner has active subscription', function () { @@ -142,7 +142,7 @@ $member->update(['current_workspace_id' => $workspace->id]); $this->actingAs($member) - ->get(route('calendar')) + ->get(route('app.calendar')) ->assertOk(); }); @@ -158,8 +158,8 @@ $member->update(['current_workspace_id' => $workspace->id]); $this->actingAs($member) - ->get(route('calendar')) - ->assertRedirect(route('subscribe')); + ->get(route('app.calendar')) + ->assertRedirect(route('app.subscribe')); }); test('invited member on own workspace without subscription is redirected to subscribe', function () { @@ -184,6 +184,6 @@ $member->update(['current_workspace_id' => $memberWorkspace->id]); $this->actingAs($member) - ->get(route('calendar')) - ->assertRedirect(route('subscribe')); + ->get(route('app.calendar')) + ->assertRedirect(route('app.subscribe')); }); diff --git a/tests/Feature/Middleware/EnsureUserSetupIsCompleteTest.php b/tests/Feature/Middleware/EnsureUserSetupIsCompleteTest.php index 1e61c33c..d5e022aa 100644 --- a/tests/Feature/Middleware/EnsureUserSetupIsCompleteTest.php +++ b/tests/Feature/Middleware/EnsureUserSetupIsCompleteTest.php @@ -13,7 +13,7 @@ $user->update(['current_workspace_id' => $workspace->id]); $this->actingAs($user) - ->get(route('calendar')) + ->get(route('app.calendar')) ->assertOk(); }); @@ -26,8 +26,8 @@ $user->update(['current_workspace_id' => $workspace->id]); $this->actingAs($user) - ->get(route('calendar')) - ->assertRedirect(route('onboarding.step1')); + ->get(route('app.calendar')) + ->assertRedirect(route('app.onboarding.step1')); }); test('user on connections step is redirected to onboarding step 2', function () { @@ -39,8 +39,8 @@ $user->update(['current_workspace_id' => $workspace->id]); $this->actingAs($user) - ->get(route('calendar')) - ->assertRedirect(route('onboarding.step2')); + ->get(route('app.calendar')) + ->assertRedirect(route('app.onboarding.step2')); }); test('user on subscription step is redirected to onboarding step 2', function () { @@ -52,15 +52,15 @@ $user->update(['current_workspace_id' => $workspace->id]); $this->actingAs($user) - ->get(route('calendar')) - ->assertRedirect(route('onboarding.step2')); + ->get(route('app.calendar')) + ->assertRedirect(route('app.onboarding.step2')); }); test('user on role step can access onboarding step 1', function () { $user = User::factory()->create(['setup' => Setup::Role]); $this->actingAs($user) - ->get(route('onboarding.step1')) + ->get(route('app.onboarding.step1')) ->assertOk(); }); @@ -68,7 +68,7 @@ $user = User::factory()->create(['setup' => Setup::Connections]); $this->actingAs($user) - ->get(route('onboarding.step2')) + ->get(route('app.onboarding.step2')) ->assertOk(); }); @@ -76,6 +76,6 @@ $user = User::factory()->create(['setup' => Setup::Connections]); $this->actingAs($user) - ->get(route('social.linkedin.connect')) + ->get(route('app.social.linkedin.connect')) ->assertRedirect(); }); diff --git a/tests/Feature/OnboardingControllerTest.php b/tests/Feature/OnboardingControllerTest.php index 19653bcb..5f5053a6 100644 --- a/tests/Feature/OnboardingControllerTest.php +++ b/tests/Feature/OnboardingControllerTest.php @@ -13,13 +13,13 @@ // Step 1 tests test('step1 requires authentication', function () { - $response = $this->get(route('onboarding.step1')); + $response = $this->get(route('app.onboarding.step1')); $response->assertRedirect(route('login')); }); test('step1 shows persona selection', function () { - $response = $this->actingAs($this->user)->get(route('onboarding.step1')); + $response = $this->actingAs($this->user)->get(route('app.onboarding.step1')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -30,7 +30,7 @@ // Store Step 1 tests test('store step1 requires authentication', function () { - $response = $this->post(route('onboarding.step1.store'), [ + $response = $this->post(route('app.onboarding.step1.store'), [ 'persona' => Persona::Founder->value, ]); @@ -38,11 +38,11 @@ }); test('store step1 saves persona and redirects to step2', function () { - $response = $this->actingAs($this->user)->post(route('onboarding.step1.store'), [ + $response = $this->actingAs($this->user)->post(route('app.onboarding.step1.store'), [ 'persona' => Persona::Founder->value, ]); - $response->assertRedirect(route('onboarding.step2')); + $response->assertRedirect(route('app.onboarding.step2')); $this->user->refresh(); expect($this->user->persona)->toBe(Persona::Founder); @@ -50,7 +50,7 @@ }); test('store step1 validates persona is required', function () { - $response = $this->actingAs($this->user)->post(route('onboarding.step1.store'), [ + $response = $this->actingAs($this->user)->post(route('app.onboarding.step1.store'), [ 'persona' => '', ]); @@ -58,7 +58,7 @@ }); test('store step1 validates persona is valid enum', function () { - $response = $this->actingAs($this->user)->post(route('onboarding.step1.store'), [ + $response = $this->actingAs($this->user)->post(route('app.onboarding.step1.store'), [ 'persona' => 'invalid', ]); @@ -67,7 +67,7 @@ // Step 2 tests test('step2 requires authentication', function () { - $response = $this->get(route('onboarding.step2')); + $response = $this->get(route('app.onboarding.step2')); $response->assertRedirect(route('login')); }); @@ -75,7 +75,7 @@ test('step2 shows social accounts connection', function () { $this->user->update(['setup' => Setup::Connections]); - $response = $this->actingAs($this->user)->get(route('onboarding.step2')); + $response = $this->actingAs($this->user)->get(route('app.onboarding.step2')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -95,7 +95,7 @@ 'platform' => Platform::LinkedIn, ]); - $response = $this->actingAs($this->user)->get(route('onboarding.step2')); + $response = $this->actingAs($this->user)->get(route('app.onboarding.step2')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -105,7 +105,7 @@ // Store Step 2 tests test('store step2 requires authentication', function () { - $response = $this->post(route('onboarding.step2.store')); + $response = $this->post(route('app.onboarding.step2.store')); $response->assertRedirect(route('login')); }); @@ -114,9 +114,9 @@ config(['trypost.self_hosted' => true]); $this->user->update(['setup' => Setup::Connections]); - $response = $this->actingAs($this->user)->post(route('onboarding.step2.store')); + $response = $this->actingAs($this->user)->post(route('app.onboarding.step2.store')); - $response->assertRedirect(route('calendar')); + $response->assertRedirect(route('app.calendar')); $this->user->refresh(); expect($this->user->setup)->toBe(Setup::Completed); @@ -124,7 +124,7 @@ // Complete tests test('complete requires authentication', function () { - $response = $this->get(route('onboarding.complete')); + $response = $this->get(route('app.onboarding.complete')); $response->assertRedirect(route('login')); }); @@ -132,9 +132,9 @@ test('complete marks setup as completed', function () { $this->user->update(['setup' => Setup::Subscription]); - $response = $this->actingAs($this->user)->get(route('onboarding.complete')); + $response = $this->actingAs($this->user)->get(route('app.onboarding.complete')); - $response->assertRedirect(route('calendar')); + $response->assertRedirect(route('app.calendar')); $this->user->refresh(); expect($this->user->setup)->toBe(Setup::Completed); diff --git a/tests/Feature/PostControllerTest.php b/tests/Feature/PostControllerTest.php index 1bd90411..7257f470 100644 --- a/tests/Feature/PostControllerTest.php +++ b/tests/Feature/PostControllerTest.php @@ -24,7 +24,7 @@ // Index tests test('posts index requires authentication', function () { - $response = $this->get(route('posts.index')); + $response = $this->get(route('app.posts.index')); $response->assertRedirect(route('login')); }); @@ -35,7 +35,7 @@ 'user_id' => $this->user->id, ]); - $response = $this->actingAs($this->user)->get(route('posts.index')); + $response = $this->actingAs($this->user)->get(route('app.posts.index')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -47,20 +47,20 @@ test('posts index redirects to create workspace if no workspace', function () { $this->user->update(['current_workspace_id' => null]); - $response = $this->actingAs($this->user)->get(route('posts.index')); + $response = $this->actingAs($this->user)->get(route('app.posts.index')); - $response->assertRedirect(route('workspaces.create')); + $response->assertRedirect(route('app.workspaces.create')); }); // Calendar tests test('calendar requires authentication', function () { - $response = $this->get(route('calendar')); + $response = $this->get(route('app.calendar')); $response->assertRedirect(route('login')); }); test('calendar shows posts for current week', function () { - $response = $this->actingAs($this->user)->get(route('calendar')); + $response = $this->actingAs($this->user)->get(route('app.calendar')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -73,7 +73,7 @@ }); test('calendar supports month view', function () { - $response = $this->actingAs($this->user)->get(route('calendar', ['view' => 'month'])); + $response = $this->actingAs($this->user)->get(route('app.calendar', ['view' => 'month'])); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -83,7 +83,7 @@ // Store tests test('store post requires authentication', function () { - $response = $this->post(route('posts.store')); + $response = $this->post(route('app.posts.store')); $response->assertRedirect(route('login')); }); @@ -91,13 +91,13 @@ test('store post redirects to accounts if no social accounts connected', function () { $this->socialAccount->delete(); - $response = $this->actingAs($this->user)->post(route('posts.store')); + $response = $this->actingAs($this->user)->post(route('app.posts.store')); - $response->assertRedirect(route('accounts')); + $response->assertRedirect(route('app.accounts')); }); test('store post creates draft and redirects to edit', function () { - $response = $this->actingAs($this->user)->post(route('posts.store')); + $response = $this->actingAs($this->user)->post(route('app.posts.store')); $response->assertRedirect(); @@ -114,7 +114,7 @@ 'user_id' => $this->user->id, ]); - $response = $this->get(route('posts.edit', $post)); + $response = $this->get(route('app.posts.edit', $post)); $response->assertRedirect(route('login')); }); @@ -131,7 +131,7 @@ 'social_account_id' => $this->socialAccount->id, ]); - $response = $this->actingAs($this->user)->get(route('posts.edit', $post)); + $response = $this->actingAs($this->user)->get(route('app.posts.edit', $post)); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -148,7 +148,7 @@ 'user_id' => $this->user->id, ]); - $response = $this->actingAs($this->user)->get(route('posts.edit', $post)); + $response = $this->actingAs($this->user)->get(route('app.posts.edit', $post)); $response->assertNotFound(); }); @@ -165,7 +165,7 @@ 'social_account_id' => $this->socialAccount->id, ]); - $response = $this->actingAs($this->user)->get(route('posts.edit', $post)); + $response = $this->actingAs($this->user)->get(route('app.posts.edit', $post)); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -181,7 +181,7 @@ 'user_id' => $this->user->id, ]); - $response = $this->put(route('posts.update', $post), []); + $response = $this->put(route('app.posts.update', $post), []); $response->assertRedirect(route('login')); }); @@ -199,7 +199,7 @@ 'content' => 'Original content', ]); - $response = $this->actingAs($this->user)->put(route('posts.update', $post), [ + $response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [ 'status' => 'draft', 'platforms' => [ [ @@ -223,7 +223,7 @@ 'status' => PostStatus::Published, ]); - $response = $this->actingAs($this->user)->put(route('posts.update', $post), [ + $response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [ 'status' => 'draft', ]); @@ -246,7 +246,7 @@ 'content' => 'Test content', ]); - $response = $this->actingAs($this->user)->put(route('posts.update', $post), [ + $response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [ 'status' => 'publishing', 'platforms' => [ [ @@ -270,7 +270,7 @@ 'user_id' => $this->user->id, ]); - $response = $this->delete(route('posts.destroy', $post)); + $response = $this->delete(route('app.posts.destroy', $post)); $response->assertRedirect(route('login')); }); @@ -282,10 +282,10 @@ ]); $response = $this->actingAs($this->user) - ->from(route('calendar')) - ->delete(route('posts.destroy', $post)); + ->from(route('app.calendar')) + ->delete(route('app.posts.destroy', $post)); - $response->assertRedirect(route('calendar')); + $response->assertRedirect(route('app.calendar')); expect(Post::find($post->id))->toBeNull(); }); @@ -296,10 +296,10 @@ ]); $response = $this->actingAs($this->user) - ->from(route('posts.index', ['status' => $status])) - ->delete(route('posts.destroy', $post)); + ->from(route('app.posts.index', ['status' => $status])) + ->delete(route('app.posts.destroy', $post)); - $response->assertRedirect(route('posts.index', ['status' => $status])); + $response->assertRedirect(route('app.posts.index', ['status' => $status])); expect(Post::find($post->id))->toBeNull(); })->with(['draft', 'scheduled', 'published']); @@ -310,9 +310,9 @@ ]); $response = $this->actingAs($this->user) - ->delete(route('posts.destroy', $post).'?redirect=posts.index'); + ->delete(route('app.posts.destroy', $post).'?redirect=app.posts.index'); - $response->assertRedirect(route('posts.index')); + $response->assertRedirect(route('app.posts.index')); expect(Post::find($post->id))->toBeNull(); }); @@ -323,7 +323,7 @@ 'user_id' => $this->user->id, ]); - $response = $this->actingAs($this->user)->delete(route('posts.destroy', $post)); + $response = $this->actingAs($this->user)->delete(route('app.posts.destroy', $post)); $response->assertNotFound(); }); @@ -347,7 +347,7 @@ 'color' => '#FF0000', ]); - $response = $this->actingAs($this->user)->get(route('posts.edit', $post)); + $response = $this->actingAs($this->user)->get(route('app.posts.edit', $post)); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -373,7 +373,7 @@ 'workspace_id' => $this->workspace->id, ]); - $response = $this->actingAs($this->user)->put(route('posts.update', $post), [ + $response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [ 'status' => 'draft', 'platforms' => [ [ @@ -410,7 +410,7 @@ $post->labels()->attach($label); - $response = $this->actingAs($this->user)->put(route('posts.update', $post), [ + $response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [ 'status' => 'draft', 'platforms' => [ [ @@ -448,7 +448,7 @@ $post->labels()->attach($label1); // Update with different labels - $response = $this->actingAs($this->user)->put(route('posts.update', $post), [ + $response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [ 'status' => 'draft', 'platforms' => [ [ @@ -479,7 +479,7 @@ 'social_account_id' => $this->socialAccount->id, ]); - $response = $this->actingAs($this->user)->put(route('posts.update', $post), [ + $response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [ 'status' => 'draft', 'platforms' => [ [ diff --git a/tests/Feature/Settings/PasswordUpdateTest.php b/tests/Feature/Settings/PasswordUpdateTest.php index 4e53a91c..08d1fef9 100644 --- a/tests/Feature/Settings/PasswordUpdateTest.php +++ b/tests/Feature/Settings/PasswordUpdateTest.php @@ -8,7 +8,7 @@ $response = $this ->actingAs($user) - ->get(route('user-password.edit')); + ->get(route('app.user-password.edit')); $response->assertOk(); }); @@ -18,8 +18,8 @@ $response = $this ->actingAs($user) - ->from(route('user-password.edit')) - ->put(route('user-password.update'), [ + ->from(route('app.user-password.edit')) + ->put(route('app.user-password.update'), [ 'current_password' => 'password', 'password' => 'new-password', 'password_confirmation' => 'new-password', @@ -27,7 +27,7 @@ $response ->assertSessionHasNoErrors() - ->assertRedirect(route('user-password.edit')); + ->assertRedirect(route('app.user-password.edit')); expect(Hash::check('new-password', $user->refresh()->password))->toBeTrue(); }); @@ -37,8 +37,8 @@ $response = $this ->actingAs($user) - ->from(route('user-password.edit')) - ->put(route('user-password.update'), [ + ->from(route('app.user-password.edit')) + ->put(route('app.user-password.update'), [ 'current_password' => 'wrong-password', 'password' => 'new-password', 'password_confirmation' => 'new-password', @@ -46,5 +46,5 @@ $response ->assertSessionHasErrors('current_password') - ->assertRedirect(route('user-password.edit')); -}); \ No newline at end of file + ->assertRedirect(route('app.user-password.edit')); +}); diff --git a/tests/Feature/Settings/ProfileUpdateTest.php b/tests/Feature/Settings/ProfileUpdateTest.php index f4399214..336524d8 100644 --- a/tests/Feature/Settings/ProfileUpdateTest.php +++ b/tests/Feature/Settings/ProfileUpdateTest.php @@ -1,14 +1,16 @@ create(); $response = $this ->actingAs($user) - ->get(route('profile.edit')); + ->get(route('app.profile.edit')); $response->assertOk(); }); @@ -18,14 +20,14 @@ $response = $this ->actingAs($user) - ->patch(route('profile.update'), [ + ->patch(route('app.profile.update'), [ 'name' => 'Test User', 'email' => 'test@example.com', ]); $response ->assertSessionHasNoErrors() - ->assertRedirect(route('profile.edit')); + ->assertRedirect(route('app.profile.edit')); $user->refresh(); @@ -39,14 +41,14 @@ $response = $this ->actingAs($user) - ->patch(route('profile.update'), [ + ->patch(route('app.profile.update'), [ 'name' => 'Test User', 'email' => $user->email, ]); $response ->assertSessionHasNoErrors() - ->assertRedirect(route('profile.edit')); + ->assertRedirect(route('app.profile.edit')); expect($user->refresh()->email_verified_at)->not->toBeNull(); }); @@ -57,14 +59,14 @@ $response = $this ->actingAs($user) - ->from(route('posts.index')) - ->patch(route('profile.language'), [ + ->from(route('app.posts.index')) + ->patch(route('app.profile.language'), [ 'language_id' => $newLanguage->id, ]); $response ->assertSessionHasNoErrors() - ->assertRedirect(route('posts.index')); + ->assertRedirect(route('app.posts.index')); expect($user->refresh()->language_id)->toBe($newLanguage->id); }); @@ -74,7 +76,7 @@ $response = $this ->actingAs($user) - ->patch(route('profile.language'), [ + ->patch(route('app.profile.language'), [ 'language_id' => '00000000-0000-0000-0000-000000000000', ]); @@ -86,13 +88,13 @@ $response = $this ->actingAs($user) - ->delete(route('profile.destroy'), [ + ->delete(route('app.profile.destroy'), [ 'password' => 'password', ]); $response ->assertSessionHasNoErrors() - ->assertRedirect(route('home')); + ->assertRedirect(route('app.home')); $this->assertGuest(); expect($user->fresh())->toBeNull(); @@ -103,14 +105,14 @@ $response = $this ->actingAs($user) - ->from(route('profile.edit')) - ->delete(route('profile.destroy'), [ + ->from(route('app.profile.edit')) + ->delete(route('app.profile.destroy'), [ 'password' => 'wrong-password', ]); $response ->assertSessionHasErrors('password') - ->assertRedirect(route('profile.edit')); + ->assertRedirect(route('app.profile.edit')); expect($user->fresh())->not->toBeNull(); }); @@ -120,12 +122,12 @@ $member = User::factory()->create(); // Create a workspace owned by the owner - $workspace = \App\Models\Workspace::factory()->create(['user_id' => $owner->id]); - $owner->workspaces()->attach($workspace->id, ['role' => \App\Enums\UserWorkspace\Role::Owner->value]); + $workspace = Workspace::factory()->create(['user_id' => $owner->id]); + $owner->workspaces()->attach($workspace->id, ['role' => Role::Owner->value]); $owner->update(['current_workspace_id' => $workspace->id]); // Add member to the workspace and set it as their current - $member->workspaces()->attach($workspace->id, ['role' => \App\Enums\UserWorkspace\Role::Member->value]); + $member->workspaces()->attach($workspace->id, ['role' => Role::Member->value]); $member->update(['current_workspace_id' => $workspace->id]); // Verify setup @@ -134,7 +136,7 @@ // Owner deletes their account $this ->actingAs($owner) - ->delete(route('profile.destroy'), [ + ->delete(route('app.profile.destroy'), [ 'password' => 'password', ]); @@ -148,17 +150,17 @@ $otherOwner = User::factory()->create(); // Create workspace owned by the owner being deleted - $workspaceToDelete = \App\Models\Workspace::factory()->create(['user_id' => $owner->id]); - $owner->workspaces()->attach($workspaceToDelete->id, ['role' => \App\Enums\UserWorkspace\Role::Owner->value]); + $workspaceToDelete = Workspace::factory()->create(['user_id' => $owner->id]); + $owner->workspaces()->attach($workspaceToDelete->id, ['role' => Role::Owner->value]); $owner->update(['current_workspace_id' => $workspaceToDelete->id]); // Create another workspace owned by a different user - $otherWorkspace = \App\Models\Workspace::factory()->create(['user_id' => $otherOwner->id]); - $otherOwner->workspaces()->attach($otherWorkspace->id, ['role' => \App\Enums\UserWorkspace\Role::Owner->value]); + $otherWorkspace = Workspace::factory()->create(['user_id' => $otherOwner->id]); + $otherOwner->workspaces()->attach($otherWorkspace->id, ['role' => Role::Owner->value]); // Add member to both workspaces - $member->workspaces()->attach($workspaceToDelete->id, ['role' => \App\Enums\UserWorkspace\Role::Member->value]); - $member->workspaces()->attach($otherWorkspace->id, ['role' => \App\Enums\UserWorkspace\Role::Member->value]); + $member->workspaces()->attach($workspaceToDelete->id, ['role' => Role::Member->value]); + $member->workspaces()->attach($otherWorkspace->id, ['role' => Role::Member->value]); $member->update(['current_workspace_id' => $workspaceToDelete->id]); // Verify setup @@ -167,7 +169,7 @@ // Owner deletes their account $this ->actingAs($owner) - ->delete(route('profile.destroy'), [ + ->delete(route('app.profile.destroy'), [ 'password' => 'password', ]); diff --git a/tests/Feature/Social/BlueskyControllerTest.php b/tests/Feature/Social/BlueskyControllerTest.php index 5d6165bd..6c79192d 100644 --- a/tests/Feature/Social/BlueskyControllerTest.php +++ b/tests/Feature/Social/BlueskyControllerTest.php @@ -15,7 +15,7 @@ }); test('bluesky connect page can be rendered', function () { - $response = $this->actingAs($this->user)->get(route('social.bluesky.connect')); + $response = $this->actingAs($this->user)->get(route('app.social.bluesky.connect')); $response->assertOk(); }); @@ -36,7 +36,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->post(route('social.bluesky.store'), [ + $response = $this->actingAs($this->user)->post(route('app.social.bluesky.store'), [ 'identifier' => 'testuser.bsky.social', 'password' => 'xxxx-xxxx-xxxx-xxxx', ]); @@ -62,7 +62,7 @@ ], 401), ]); - $response = $this->actingAs($this->user)->post(route('social.bluesky.store'), [ + $response = $this->actingAs($this->user)->post(route('app.social.bluesky.store'), [ 'identifier' => 'testuser.bsky.social', 'password' => 'wrong-password', ]); @@ -96,7 +96,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->post(route('social.bluesky.store'), [ + $response = $this->actingAs($this->user)->post(route('app.social.bluesky.store'), [ 'identifier' => 'newuser.bsky.social', 'password' => 'xxxx-xxxx-xxxx-xxxx', ]); @@ -127,7 +127,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->post(route('social.bluesky.store'), [ + $response = $this->actingAs($this->user)->post(route('app.social.bluesky.store'), [ 'identifier' => 'testuser.bsky.social', 'password' => 'xxxx-xxxx-xxxx-xxxx', ]); @@ -141,7 +141,7 @@ }); test('bluesky connection validates required fields', function () { - $response = $this->actingAs($this->user)->post(route('social.bluesky.store'), [ + $response = $this->actingAs($this->user)->post(route('app.social.bluesky.store'), [ 'identifier' => '', 'password' => '', ]); diff --git a/tests/Feature/Social/FacebookControllerTest.php b/tests/Feature/Social/FacebookControllerTest.php index 16ba4fbf..9d904027 100644 --- a/tests/Feature/Social/FacebookControllerTest.php +++ b/tests/Feature/Social/FacebookControllerTest.php @@ -28,7 +28,7 @@ $response = $this->actingAs($this->user) ->withHeader('X-Inertia', 'true') - ->get(route('social.facebook.connect')); + ->get(route('app.social.facebook.connect')); $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header @@ -64,7 +64,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.facebook.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.facebook.callback')); $response->assertOk(); $response->assertViewIs('auth.social-callback'); @@ -116,9 +116,9 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.facebook.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.facebook.callback')); - $response->assertRedirect(route('social.facebook.select-page')); + $response->assertRedirect(route('app.social.facebook.select-page')); expect(session('facebook_oauth'))->not->toBeNull(); }); @@ -143,7 +143,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.facebook.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.facebook.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -153,7 +153,7 @@ test('facebook callback fails with expired session', function () { // No session data - simulating expired session - $response = $this->actingAs($this->user)->get(route('social.facebook.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.facebook.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -193,7 +193,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.facebook.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.facebook.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -236,7 +236,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.facebook.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.facebook.callback')); $response->assertOk(); $response->assertViewHas('success', true); @@ -252,13 +252,13 @@ ]); $mock = Mockery::mock(); - $mock->shouldReceive('user')->andThrow(new \Exception('OAuth error')); + $mock->shouldReceive('user')->andThrow(new Exception('OAuth error')); Socialite::shouldReceive('driver') ->with('facebook') ->andReturn($mock); - $response = $this->actingAs($this->user)->get(route('social.facebook.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.facebook.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -290,7 +290,7 @@ ], ]); - $response = $this->actingAs($this->user)->post(route('social.facebook.select'), [ + $response = $this->actingAs($this->user)->post(route('app.social.facebook.select'), [ 'page_id' => 'page_123', ]); @@ -308,7 +308,7 @@ test('facebook page selection fails with expired session', function () { // No session data - $response = $this->actingAs($this->user)->post(route('social.facebook.select'), [ + $response = $this->actingAs($this->user)->post(route('app.social.facebook.select'), [ 'page_id' => 'page_123', ]); @@ -334,7 +334,7 @@ ], ]); - $response = $this->actingAs($this->user)->post(route('social.facebook.select'), [ + $response = $this->actingAs($this->user)->post(route('app.social.facebook.select'), [ 'page_id' => 'invalid_page_id', ]); diff --git a/tests/Feature/Social/InstagramControllerTest.php b/tests/Feature/Social/InstagramControllerTest.php index 120e6bee..007c5697 100644 --- a/tests/Feature/Social/InstagramControllerTest.php +++ b/tests/Feature/Social/InstagramControllerTest.php @@ -27,7 +27,7 @@ $response = $this->actingAs($this->user) ->withHeader('X-Inertia', 'true') - ->get(route('social.instagram.connect')); + ->get(route('app.social.instagram.connect')); $response->assertStatus(409); @@ -55,7 +55,7 @@ 'user' => $socialiteUser, ])); - $response = $this->actingAs($this->user)->get(route('social.instagram.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.instagram.callback')); $response->assertOk(); $response->assertViewIs('auth.social-callback'); @@ -71,7 +71,7 @@ }); test('instagram callback fails with expired session', function () { - $response = $this->actingAs($this->user)->get(route('social.instagram.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.instagram.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -106,7 +106,7 @@ 'user' => $socialiteUser, ])); - $response = $this->actingAs($this->user)->get(route('social.instagram.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.instagram.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -141,7 +141,7 @@ 'user' => $socialiteUser, ])); - $response = $this->actingAs($this->user)->get(route('social.instagram.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.instagram.callback')); $response->assertOk(); $response->assertViewHas('success', true); @@ -157,13 +157,13 @@ ]); $mock = Mockery::mock(); - $mock->shouldReceive('user')->andThrow(new \Exception('OAuth error')); + $mock->shouldReceive('user')->andThrow(new Exception('OAuth error')); Socialite::shouldReceive('driver') ->with('instagram') ->andReturn($mock); - $response = $this->actingAs($this->user)->get(route('social.instagram.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.instagram.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -173,7 +173,7 @@ test('instagram connect redirects to create workspace if none exists', function () { $this->user->update(['current_workspace_id' => null]); - $response = $this->actingAs($this->user)->get(route('social.instagram.connect')); + $response = $this->actingAs($this->user)->get(route('app.social.instagram.connect')); - $response->assertRedirect(route('workspaces.create')); + $response->assertRedirect(route('app.workspaces.create')); }); diff --git a/tests/Feature/Social/LinkedInControllerTest.php b/tests/Feature/Social/LinkedInControllerTest.php index 5629773c..da540dae 100644 --- a/tests/Feature/Social/LinkedInControllerTest.php +++ b/tests/Feature/Social/LinkedInControllerTest.php @@ -28,7 +28,7 @@ $response = $this->actingAs($this->user) ->withHeader('X-Inertia', 'true') - ->get(route('social.linkedin.connect')); + ->get(route('app.social.linkedin.connect')); $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header @@ -65,7 +65,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.linkedin.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.linkedin.callback')); $response->assertOk(); $response->assertViewIs('auth.social-callback'); @@ -83,7 +83,7 @@ test('linkedin callback fails with expired session', function () { // No session data - simulating expired session - $response = $this->actingAs($this->user)->get(route('social.linkedin.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.linkedin.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -115,7 +115,7 @@ 'user' => $socialiteUser, ])); - $response = $this->actingAs($this->user)->get(route('social.linkedin.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.linkedin.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -154,7 +154,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.linkedin.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.linkedin.callback')); $response->assertOk(); $response->assertViewHas('success', true); @@ -170,13 +170,13 @@ ]); $mock = Mockery::mock(); - $mock->shouldReceive('user')->andThrow(new \Exception('OAuth error')); + $mock->shouldReceive('user')->andThrow(new Exception('OAuth error')); Socialite::shouldReceive('driver') ->with('linkedin') ->andReturn($mock); - $response = $this->actingAs($this->user)->get(route('social.linkedin.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.linkedin.callback')); $response->assertOk(); $response->assertViewHas('success', false); diff --git a/tests/Feature/Social/LinkedInPageControllerTest.php b/tests/Feature/Social/LinkedInPageControllerTest.php index 84fc110b..37ba3026 100644 --- a/tests/Feature/Social/LinkedInPageControllerTest.php +++ b/tests/Feature/Social/LinkedInPageControllerTest.php @@ -29,7 +29,7 @@ $response = $this->actingAs($this->user) ->withHeader('X-Inertia', 'true') - ->get(route('social.linkedin-page.connect')); + ->get(route('app.social.linkedin-page.connect')); $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header @@ -72,9 +72,9 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.linkedin-page.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.linkedin-page.callback')); - $response->assertRedirect(route('social.linkedin-page.select-page')); + $response->assertRedirect(route('app.social.linkedin-page.select-page')); expect(session('linkedin_page_pending'))->not->toBeNull(); expect(session('linkedin_page_pending.organizations'))->toHaveCount(1); @@ -108,7 +108,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.linkedin-page.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.linkedin-page.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -118,7 +118,7 @@ test('linkedin page callback fails with expired session', function () { // No session data - simulating expired session - $response = $this->actingAs($this->user)->get(route('social.linkedin-page.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.linkedin-page.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -141,7 +141,7 @@ ], ]); - $response = $this->actingAs($this->user)->post(route('social.linkedin-page.select'), [ + $response = $this->actingAs($this->user)->post(route('app.social.linkedin-page.select'), [ 'organization_id' => 123456, 'organization_name' => 'Test Company', 'organization_vanity_name' => 'testcompany', @@ -165,7 +165,7 @@ test('linkedin page select fails with expired session', function () { // No session data - $response = $this->actingAs($this->user)->post(route('social.linkedin-page.select'), [ + $response = $this->actingAs($this->user)->post(route('app.social.linkedin-page.select'), [ 'organization_id' => 123456, 'organization_name' => 'Test Company', 'organization_vanity_name' => 'testcompany', @@ -183,7 +183,7 @@ ]); // The "already connected" check happens in the connect method, not callback - $response = $this->actingAs($this->user)->get(route('social.linkedin-page.connect')); + $response = $this->actingAs($this->user)->get(route('app.social.linkedin-page.connect')); $response->assertRedirect(); $response->assertSessionHas('flash.banner', __('accounts.flash.already_connected')); @@ -212,7 +212,7 @@ ], ]); - $response = $this->actingAs($this->user)->post(route('social.linkedin-page.select'), [ + $response = $this->actingAs($this->user)->post(route('app.social.linkedin-page.select'), [ 'organization_id' => 123456, 'organization_name' => 'Test Company', 'organization_vanity_name' => 'testcompany', @@ -235,13 +235,13 @@ $socialiteMock = Mockery::mock(); $socialiteMock->shouldReceive('scopes')->andReturn($socialiteMock); $socialiteMock->shouldReceive('with')->andReturn($socialiteMock); - $socialiteMock->shouldReceive('user')->andThrow(new \Exception('OAuth error')); + $socialiteMock->shouldReceive('user')->andThrow(new Exception('OAuth error')); Socialite::shouldReceive('driver') ->with('linkedin-openid') ->andReturn($socialiteMock); - $response = $this->actingAs($this->user)->get(route('social.linkedin-page.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.linkedin-page.callback')); $response->assertOk(); $response->assertViewHas('success', false); diff --git a/tests/Feature/Social/MastodonControllerTest.php b/tests/Feature/Social/MastodonControllerTest.php index 92d3f8c4..57111ade 100644 --- a/tests/Feature/Social/MastodonControllerTest.php +++ b/tests/Feature/Social/MastodonControllerTest.php @@ -15,7 +15,7 @@ }); test('mastodon connect page can be rendered', function () { - $response = $this->actingAs($this->user)->get(route('social.mastodon.connect')); + $response = $this->actingAs($this->user)->get(route('app.social.mastodon.connect')); $response->assertOk(); }); @@ -27,13 +27,13 @@ 'client_secret' => 'test-client-secret', 'id' => '12345', 'name' => config('app.name'), - 'redirect_uri' => route('social.mastodon.callback'), + 'redirect_uri' => route('app.social.mastodon.callback'), ], 200), ]); $response = $this->actingAs($this->user) ->withHeader('X-Inertia', 'true') - ->post(route('social.mastodon.authorize'), [ + ->post(route('app.social.mastodon.authorize'), [ 'instance' => 'https://mastodon.social', ]); @@ -49,7 +49,7 @@ 'https://invalid-instance.com/api/v1/apps' => Http::response([], 404), ]); - $response = $this->actingAs($this->user)->post(route('social.mastodon.authorize'), [ + $response = $this->actingAs($this->user)->post(route('app.social.mastodon.authorize'), [ 'instance' => 'https://invalid-instance.com', ]); @@ -83,7 +83,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.mastodon.callback', [ + $response = $this->actingAs($this->user)->get(route('app.social.mastodon.callback', [ 'code' => 'test-auth-code', 'state' => 'test-state', ])); @@ -110,7 +110,7 @@ 'social_connect_workspace' => $this->workspace->id, ]); - $response = $this->actingAs($this->user)->get(route('social.mastodon.callback', [ + $response = $this->actingAs($this->user)->get(route('app.social.mastodon.callback', [ 'code' => 'test-auth-code', 'state' => 'wrong-state', ])); @@ -127,7 +127,7 @@ test('mastodon callback fails with expired session', function () { // No session data - simulating expired session - $response = $this->actingAs($this->user)->get(route('social.mastodon.callback', [ + $response = $this->actingAs($this->user)->get(route('app.social.mastodon.callback', [ 'code' => 'test-auth-code', 'state' => 'test-state', ])); @@ -164,7 +164,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.mastodon.callback', [ + $response = $this->actingAs($this->user)->get(route('app.social.mastodon.callback', [ 'code' => 'test-auth-code', 'state' => 'test-state', ])); @@ -201,7 +201,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.mastodon.callback', [ + $response = $this->actingAs($this->user)->get(route('app.social.mastodon.callback', [ 'code' => 'test-auth-code', 'state' => 'test-state', ])); @@ -215,7 +215,7 @@ }); test('mastodon connection validates instance url', function () { - $response = $this->actingAs($this->user)->post(route('social.mastodon.authorize'), [ + $response = $this->actingAs($this->user)->post(route('app.social.mastodon.authorize'), [ 'instance' => 'not-a-valid-url', ]); @@ -234,7 +234,7 @@ $response = $this->actingAs($this->user) ->withHeader('X-Inertia', 'true') - ->post(route('social.mastodon.authorize'), [ + ->post(route('app.social.mastodon.authorize'), [ 'instance' => 'https://techhub.social', ]); diff --git a/tests/Feature/Social/PinterestControllerTest.php b/tests/Feature/Social/PinterestControllerTest.php index f8945740..b318b946 100644 --- a/tests/Feature/Social/PinterestControllerTest.php +++ b/tests/Feature/Social/PinterestControllerTest.php @@ -27,7 +27,7 @@ $response = $this->actingAs($this->user) ->withHeader('X-Inertia', 'true') - ->get(route('social.pinterest.connect')); + ->get(route('app.social.pinterest.connect')); $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header @@ -55,7 +55,7 @@ 'user' => $socialiteUser, ])); - $response = $this->actingAs($this->user)->get(route('social.pinterest.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.pinterest.callback')); $response->assertOk(); $response->assertViewIs('auth.social-callback'); @@ -73,7 +73,7 @@ test('pinterest callback fails with expired session', function () { // No session data - simulating expired session - $response = $this->actingAs($this->user)->get(route('social.pinterest.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.pinterest.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -105,7 +105,7 @@ 'user' => $socialiteUser, ])); - $response = $this->actingAs($this->user)->get(route('social.pinterest.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.pinterest.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -138,7 +138,7 @@ 'user' => $socialiteUser, ])); - $response = $this->actingAs($this->user)->get(route('social.pinterest.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.pinterest.callback')); $response->assertOk(); $response->assertViewHas('success', true); @@ -154,13 +154,13 @@ ]); $mock = Mockery::mock(); - $mock->shouldReceive('user')->andThrow(new \Exception('OAuth error')); + $mock->shouldReceive('user')->andThrow(new Exception('OAuth error')); Socialite::shouldReceive('driver') ->with('pinterest') ->andReturn($mock); - $response = $this->actingAs($this->user)->get(route('social.pinterest.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.pinterest.callback')); $response->assertOk(); $response->assertViewHas('success', false); diff --git a/tests/Feature/Social/ThreadsControllerTest.php b/tests/Feature/Social/ThreadsControllerTest.php index cb353f92..edfee4d0 100644 --- a/tests/Feature/Social/ThreadsControllerTest.php +++ b/tests/Feature/Social/ThreadsControllerTest.php @@ -17,7 +17,7 @@ test('threads connect redirects to oauth', function () { $response = $this->actingAs($this->user) ->withHeader('X-Inertia', 'true') - ->get(route('social.threads.connect')); + ->get(route('app.social.threads.connect')); $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header @@ -50,7 +50,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.threads.callback', [ + $response = $this->actingAs($this->user)->get(route('app.social.threads.callback', [ 'code' => 'test-auth-code', 'state' => $state, ])); @@ -74,7 +74,7 @@ 'threads_oauth_state' => 'correct-state', ]); - $response = $this->actingAs($this->user)->get(route('social.threads.callback', [ + $response = $this->actingAs($this->user)->get(route('app.social.threads.callback', [ 'code' => 'test-auth-code', 'state' => 'wrong-state', ])); @@ -92,7 +92,7 @@ test('threads callback fails with expired session', function () { // No session data - simulating expired session - $response = $this->actingAs($this->user)->get(route('social.threads.callback', [ + $response = $this->actingAs($this->user)->get(route('app.social.threads.callback', [ 'code' => 'test-auth-code', 'state' => 'test-state', ])); @@ -131,7 +131,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.threads.callback', [ + $response = $this->actingAs($this->user)->get(route('app.social.threads.callback', [ 'code' => 'test-auth-code', 'state' => $state, ])); @@ -171,7 +171,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.threads.callback', [ + $response = $this->actingAs($this->user)->get(route('app.social.threads.callback', [ 'code' => 'test-auth-code', 'state' => $state, ])); @@ -199,7 +199,7 @@ ], 400), ]); - $response = $this->actingAs($this->user)->get(route('social.threads.callback', [ + $response = $this->actingAs($this->user)->get(route('app.social.threads.callback', [ 'code' => 'expired-auth-code', 'state' => $state, ])); diff --git a/tests/Feature/Social/TikTokControllerTest.php b/tests/Feature/Social/TikTokControllerTest.php index e5bfafa4..d20bf679 100644 --- a/tests/Feature/Social/TikTokControllerTest.php +++ b/tests/Feature/Social/TikTokControllerTest.php @@ -27,7 +27,7 @@ $response = $this->actingAs($this->user) ->withHeader('X-Inertia', 'true') - ->get(route('social.tiktok.connect')); + ->get(route('app.social.tiktok.connect')); $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header @@ -57,7 +57,7 @@ ->with('tiktok') ->andReturn($socialiteMock); - $response = $this->actingAs($this->user)->get(route('social.tiktok.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.tiktok.callback')); $response->assertOk(); $response->assertViewIs('auth.social-callback'); @@ -75,7 +75,7 @@ test('tiktok callback fails with expired session', function () { // No session data - simulating expired session - $response = $this->actingAs($this->user)->get(route('social.tiktok.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.tiktok.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -109,7 +109,7 @@ ->with('tiktok') ->andReturn($socialiteMock); - $response = $this->actingAs($this->user)->get(route('social.tiktok.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.tiktok.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -145,7 +145,7 @@ ->with('tiktok') ->andReturn($socialiteMock); - $response = $this->actingAs($this->user)->get(route('social.tiktok.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.tiktok.callback')); $response->assertOk(); $response->assertViewHas('success', true); @@ -162,13 +162,13 @@ $mock = Mockery::mock(); $mock->shouldReceive('scopes')->andReturn($mock); - $mock->shouldReceive('user')->andThrow(new \Exception('OAuth error')); + $mock->shouldReceive('user')->andThrow(new Exception('OAuth error')); Socialite::shouldReceive('driver') ->with('tiktok') ->andReturn($mock); - $response = $this->actingAs($this->user)->get(route('social.tiktok.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.tiktok.callback')); $response->assertOk(); $response->assertViewHas('success', false); diff --git a/tests/Feature/Social/XControllerTest.php b/tests/Feature/Social/XControllerTest.php index 39635c09..92c7fc91 100644 --- a/tests/Feature/Social/XControllerTest.php +++ b/tests/Feature/Social/XControllerTest.php @@ -27,7 +27,7 @@ $response = $this->actingAs($this->user) ->withHeader('X-Inertia', 'true') - ->get(route('social.x.connect')); + ->get(route('app.social.x.connect')); $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header @@ -55,7 +55,7 @@ 'user' => $socialiteUser, ])); - $response = $this->actingAs($this->user)->get(route('social.x.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.x.callback')); $response->assertOk(); $response->assertViewIs('auth.social-callback'); @@ -73,7 +73,7 @@ test('x callback fails with expired session', function () { // No session data - simulating expired session - $response = $this->actingAs($this->user)->get(route('social.x.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.x.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -105,7 +105,7 @@ 'user' => $socialiteUser, ])); - $response = $this->actingAs($this->user)->get(route('social.x.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.x.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -138,7 +138,7 @@ 'user' => $socialiteUser, ])); - $response = $this->actingAs($this->user)->get(route('social.x.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.x.callback')); $response->assertOk(); $response->assertViewHas('success', true); @@ -154,13 +154,13 @@ ]); $mock = Mockery::mock(); - $mock->shouldReceive('user')->andThrow(new \Exception('OAuth error')); + $mock->shouldReceive('user')->andThrow(new Exception('OAuth error')); Socialite::shouldReceive('driver') ->with('x') ->andReturn($mock); - $response = $this->actingAs($this->user)->get(route('social.x.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.x.callback')); $response->assertOk(); $response->assertViewHas('success', false); diff --git a/tests/Feature/Social/YouTubeControllerTest.php b/tests/Feature/Social/YouTubeControllerTest.php index f29da189..e51d8261 100644 --- a/tests/Feature/Social/YouTubeControllerTest.php +++ b/tests/Feature/Social/YouTubeControllerTest.php @@ -29,7 +29,7 @@ $response = $this->actingAs($this->user) ->withHeader('X-Inertia', 'true') - ->get(route('social.youtube.connect')); + ->get(route('app.social.youtube.connect')); $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header @@ -74,7 +74,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.youtube.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.youtube.callback')); $response->assertOk(); $response->assertViewIs('auth.social-callback'); @@ -132,9 +132,9 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.youtube.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.youtube.callback')); - $response->assertRedirect(route('social.youtube.select-channel')); + $response->assertRedirect(route('app.social.youtube.select-channel')); expect(session('youtube_oauth'))->not->toBeNull(); }); @@ -161,7 +161,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.youtube.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.youtube.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -171,7 +171,7 @@ test('youtube callback fails with expired session', function () { // No session data - simulating expired session - $response = $this->actingAs($this->user)->get(route('social.youtube.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.youtube.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -216,7 +216,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.youtube.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.youtube.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -263,7 +263,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->get(route('social.youtube.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.youtube.callback')); $response->assertOk(); $response->assertViewHas('success', true); @@ -279,13 +279,13 @@ ]); $mock = Mockery::mock(); - $mock->shouldReceive('user')->andThrow(new \Exception('OAuth error')); + $mock->shouldReceive('user')->andThrow(new Exception('OAuth error')); Socialite::shouldReceive('driver') ->with('google') ->andReturn($mock); - $response = $this->actingAs($this->user)->get(route('social.youtube.callback')); + $response = $this->actingAs($this->user)->get(route('app.social.youtube.callback')); $response->assertOk(); $response->assertViewHas('success', false); @@ -320,7 +320,7 @@ ], 200), ]); - $response = $this->actingAs($this->user)->post(route('social.youtube.select'), [ + $response = $this->actingAs($this->user)->post(route('app.social.youtube.select'), [ 'channel_id' => 'UC_channel_123', ]); @@ -338,7 +338,7 @@ test('youtube channel selection fails with expired session', function () { // No session data - $response = $this->actingAs($this->user)->post(route('social.youtube.select'), [ + $response = $this->actingAs($this->user)->post(route('app.social.youtube.select'), [ 'channel_id' => 'UC_channel_123', ]); diff --git a/tests/Feature/SocialControllerTest.php b/tests/Feature/SocialControllerTest.php index 12076992..516bc035 100644 --- a/tests/Feature/SocialControllerTest.php +++ b/tests/Feature/SocialControllerTest.php @@ -14,7 +14,7 @@ // Index tests test('accounts index requires authentication', function () { - $response = $this->get(route('accounts')); + $response = $this->get(route('app.accounts')); $response->assertRedirect(route('login')); }); @@ -25,7 +25,7 @@ 'platform' => Platform::LinkedIn, ]); - $response = $this->actingAs($this->user)->get(route('accounts')); + $response = $this->actingAs($this->user)->get(route('app.accounts')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -38,16 +38,16 @@ test('accounts index redirects if no workspace', function () { $this->user->update(['current_workspace_id' => null]); - $response = $this->actingAs($this->user)->get(route('accounts')); + $response = $this->actingAs($this->user)->get(route('app.accounts')); - $response->assertRedirect(route('workspaces.create')); + $response->assertRedirect(route('app.workspaces.create')); }); // Disconnect tests test('disconnect requires authentication', function () { $account = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id]); - $response = $this->delete(route('accounts.disconnect', $account)); + $response = $this->delete(route('app.accounts.disconnect', $account)); $response->assertRedirect(route('login')); }); @@ -55,7 +55,7 @@ test('disconnect removes social account', function () { $account = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id]); - $response = $this->actingAs($this->user)->delete(route('accounts.disconnect', $account)); + $response = $this->actingAs($this->user)->delete(route('app.accounts.disconnect', $account)); $response->assertRedirect(); expect(SocialAccount::find($account->id))->toBeNull(); @@ -65,7 +65,7 @@ $otherWorkspace = Workspace::factory()->create(); $account = SocialAccount::factory()->create(['workspace_id' => $otherWorkspace->id]); - $response = $this->actingAs($this->user)->delete(route('accounts.disconnect', $account)); + $response = $this->actingAs($this->user)->delete(route('app.accounts.disconnect', $account)); $response->assertForbidden(); }); diff --git a/tests/Feature/VerifyWorkspaceConnectionsTest.php b/tests/Feature/VerifyWorkspaceConnectionsTest.php index b39592a1..b2ff3018 100644 --- a/tests/Feature/VerifyWorkspaceConnectionsTest.php +++ b/tests/Feature/VerifyWorkspaceConnectionsTest.php @@ -94,10 +94,10 @@ $verifier = mock(ConnectionVerifier::class); $verifier->shouldReceive('verify') - ->with(\Mockery::on(fn ($acc) => $acc->id === $validAccount->id)) + ->with(Mockery::on(fn ($acc) => $acc->id === $validAccount->id)) ->andReturn(true); $verifier->shouldReceive('verify') - ->with(\Mockery::on(fn ($acc) => $acc->id === $invalidAccount->id)) + ->with(Mockery::on(fn ($acc) => $acc->id === $invalidAccount->id)) ->andThrow(new TokenExpiredException('Token expired')); app()->instance(ConnectionVerifier::class, $verifier); diff --git a/tests/Feature/WorkspaceControllerTest.php b/tests/Feature/WorkspaceControllerTest.php index 0c8b37f8..b00a50ca 100644 --- a/tests/Feature/WorkspaceControllerTest.php +++ b/tests/Feature/WorkspaceControllerTest.php @@ -13,7 +13,7 @@ // Index tests test('workspaces index requires authentication', function () { - $response = $this->get(route('workspaces.index')); + $response = $this->get(route('app.workspaces.index')); $response->assertRedirect(route('login')); }); @@ -24,7 +24,7 @@ $workspace->members()->attach($this->user->id, ['role' => 'owner']); } - $response = $this->actingAs($this->user)->get(route('workspaces.index')); + $response = $this->actingAs($this->user)->get(route('app.workspaces.index')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -36,7 +36,7 @@ // Create tests test('create workspace requires authentication', function () { - $response = $this->get(route('workspaces.create')); + $response = $this->get(route('app.workspaces.create')); $response->assertRedirect(route('login')); }); @@ -46,7 +46,7 @@ $this->user->update(['current_workspace_id' => null]); $this->workspace->delete(); - $response = $this->actingAs($this->user)->get(route('workspaces.create')); + $response = $this->actingAs($this->user)->get(route('app.workspaces.create')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -57,7 +57,7 @@ test('create workspace shows form when user already has workspace in self-hosted mode', function () { config(['trypost.self_hosted' => true]); - $response = $this->actingAs($this->user)->get(route('workspaces.create')); + $response = $this->actingAs($this->user)->get(route('app.workspaces.create')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -67,7 +67,7 @@ // Store tests test('store workspace requires authentication', function () { - $response = $this->post(route('workspaces.store'), ['name' => 'Test Workspace']); + $response = $this->post(route('app.workspaces.store'), ['name' => 'Test Workspace']); $response->assertRedirect(route('login')); }); @@ -77,11 +77,11 @@ $this->user->update(['current_workspace_id' => null]); $this->workspace->delete(); - $response = $this->actingAs($this->user)->post(route('workspaces.store'), [ + $response = $this->actingAs($this->user)->post(route('app.workspaces.store'), [ 'name' => 'New Workspace', ]); - $response->assertRedirect(route('calendar')); + $response->assertRedirect(route('app.calendar')); $this->assertDatabaseHas('workspaces', [ 'name' => 'New Workspace', @@ -92,11 +92,11 @@ test('store workspace creates second workspace in self-hosted mode', function () { config(['trypost.self_hosted' => true]); - $response = $this->actingAs($this->user)->post(route('workspaces.store'), [ + $response = $this->actingAs($this->user)->post(route('app.workspaces.store'), [ 'name' => 'Second Workspace', ]); - $response->assertRedirect(route('calendar')); + $response->assertRedirect(route('app.calendar')); $this->assertDatabaseHas('workspaces', [ 'name' => 'Second Workspace', @@ -105,7 +105,7 @@ }); test('store workspace validates name is required', function () { - $response = $this->actingAs($this->user)->post(route('workspaces.store'), [ + $response = $this->actingAs($this->user)->post(route('app.workspaces.store'), [ 'name' => '', ]); @@ -117,7 +117,7 @@ $this->user->update(['current_workspace_id' => null]); $this->workspace->delete(); - $this->actingAs($this->user)->post(route('workspaces.store'), [ + $this->actingAs($this->user)->post(route('app.workspaces.store'), [ 'name' => 'New Workspace', ]); @@ -129,7 +129,7 @@ // Switch tests test('switch workspace requires authentication', function () { - $response = $this->post(route('workspaces.switch', $this->workspace)); + $response = $this->post(route('app.workspaces.switch', $this->workspace)); $response->assertRedirect(route('login')); }); @@ -138,9 +138,9 @@ $otherWorkspace = Workspace::factory()->create(['user_id' => $this->user->id]); $otherWorkspace->members()->attach($this->user->id, ['role' => 'owner']); - $response = $this->actingAs($this->user)->post(route('workspaces.switch', $otherWorkspace)); + $response = $this->actingAs($this->user)->post(route('app.workspaces.switch', $otherWorkspace)); - $response->assertRedirect(route('calendar')); + $response->assertRedirect(route('app.calendar')); $this->user->refresh(); expect($this->user->current_workspace_id)->toBe($otherWorkspace->id); @@ -150,20 +150,20 @@ $otherUser = User::factory()->create(['setup' => Setup::Completed]); $otherWorkspace = Workspace::factory()->create(['user_id' => $otherUser->id]); - $response = $this->actingAs($this->user)->post(route('workspaces.switch', $otherWorkspace)); + $response = $this->actingAs($this->user)->post(route('app.workspaces.switch', $otherWorkspace)); $response->assertForbidden(); }); // Settings tests test('workspace settings requires authentication', function () { - $response = $this->get(route('workspace.settings')); + $response = $this->get(route('app.workspace.settings')); $response->assertRedirect(route('login')); }); test('workspace settings shows settings page', function () { - $response = $this->actingAs($this->user)->get(route('workspace.settings')); + $response = $this->actingAs($this->user)->get(route('app.workspace.settings')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -176,14 +176,14 @@ test('workspace settings redirects to create if no workspace', function () { $this->user->update(['current_workspace_id' => null]); - $response = $this->actingAs($this->user)->get(route('workspace.settings')); + $response = $this->actingAs($this->user)->get(route('app.workspace.settings')); - $response->assertRedirect(route('workspaces.create')); + $response->assertRedirect(route('app.workspaces.create')); }); // Update settings tests test('update workspace settings requires authentication', function () { - $response = $this->put(route('workspace.settings.update'), [ + $response = $this->put(route('app.workspace.settings.update'), [ 'name' => 'Updated Name', 'timezone' => 'America/New_York', ]); @@ -192,12 +192,12 @@ }); test('update workspace settings updates workspace', function () { - $response = $this->actingAs($this->user)->put(route('workspace.settings.update'), [ + $response = $this->actingAs($this->user)->put(route('app.workspace.settings.update'), [ 'name' => 'Updated Name', 'timezone' => 'America/New_York', ]); - $response->assertRedirect(route('workspace.settings')); + $response->assertRedirect(route('app.workspace.settings')); $this->workspace->refresh(); expect($this->workspace->name)->toBe('Updated Name'); @@ -205,7 +205,7 @@ }); test('update workspace settings validates required fields', function () { - $response = $this->actingAs($this->user)->put(route('workspace.settings.update'), [ + $response = $this->actingAs($this->user)->put(route('app.workspace.settings.update'), [ 'name' => '', 'timezone' => '', ]); @@ -214,7 +214,7 @@ }); test('update workspace settings validates timezone', function () { - $response = $this->actingAs($this->user)->put(route('workspace.settings.update'), [ + $response = $this->actingAs($this->user)->put(route('app.workspace.settings.update'), [ 'name' => 'Valid Name', 'timezone' => 'Invalid/Timezone', ]); @@ -224,7 +224,7 @@ // Destroy tests test('destroy workspace requires authentication', function () { - $response = $this->delete(route('workspaces.destroy', $this->workspace)); + $response = $this->delete(route('app.workspaces.destroy', $this->workspace)); $response->assertRedirect(route('login')); }); @@ -232,14 +232,14 @@ test('destroy workspace deletes the workspace', function () { $workspaceId = $this->workspace->id; - $response = $this->actingAs($this->user)->delete(route('workspaces.destroy', $this->workspace)); + $response = $this->actingAs($this->user)->delete(route('app.workspaces.destroy', $this->workspace)); - $response->assertRedirect(route('workspaces.index')); + $response->assertRedirect(route('app.workspaces.index')); expect(Workspace::find($workspaceId))->toBeNull(); }); test('destroy workspace clears current workspace if deleting current', function () { - $this->actingAs($this->user)->delete(route('workspaces.destroy', $this->workspace)); + $this->actingAs($this->user)->delete(route('app.workspaces.destroy', $this->workspace)); $this->user->refresh(); expect($this->user->current_workspace_id)->toBeNull(); @@ -248,7 +248,7 @@ test('destroy workspace returns 403 for non-owner', function () { $otherUser = User::factory()->create(['setup' => Setup::Completed]); - $response = $this->actingAs($otherUser)->delete(route('workspaces.destroy', $this->workspace)); + $response = $this->actingAs($otherUser)->delete(route('app.workspaces.destroy', $this->workspace)); $response->assertForbidden(); }); diff --git a/tests/Feature/WorkspaceHashtagControllerTest.php b/tests/Feature/WorkspaceHashtagControllerTest.php index 54aca131..3f41a79d 100644 --- a/tests/Feature/WorkspaceHashtagControllerTest.php +++ b/tests/Feature/WorkspaceHashtagControllerTest.php @@ -13,7 +13,7 @@ // Index tests test('hashtags index requires authentication', function () { - $response = $this->get(route('hashtags.index')); + $response = $this->get(route('app.hashtags.index')); $response->assertRedirect(route('login')); }); @@ -21,7 +21,7 @@ test('hashtags index shows hashtags for workspace', function () { WorkspaceHashtag::factory()->count(3)->create(['workspace_id' => $this->workspace->id]); - $response = $this->actingAs($this->user)->get(route('hashtags.index')); + $response = $this->actingAs($this->user)->get(route('app.hashtags.index')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -34,14 +34,14 @@ test('hashtags index redirects if no workspace', function () { $this->user->update(['current_workspace_id' => null]); - $response = $this->actingAs($this->user)->get(route('hashtags.index')); + $response = $this->actingAs($this->user)->get(route('app.hashtags.index')); - $response->assertRedirect(route('workspaces.create')); + $response->assertRedirect(route('app.workspaces.create')); }); // Store tests test('store hashtag requires authentication', function () { - $response = $this->post(route('hashtags.store'), [ + $response = $this->post(route('app.hashtags.store'), [ 'name' => 'Marketing', 'hashtags' => '#marketing #digital #growth', ]); @@ -50,12 +50,12 @@ }); test('store hashtag creates hashtag group', function () { - $response = $this->actingAs($this->user)->post(route('hashtags.store'), [ + $response = $this->actingAs($this->user)->post(route('app.hashtags.store'), [ 'name' => 'Marketing', 'hashtags' => '#marketing #digital #growth', ]); - $response->assertRedirect(route('hashtags.index')); + $response->assertRedirect(route('app.hashtags.index')); $this->assertDatabaseHas('workspace_hashtags', [ 'workspace_id' => $this->workspace->id, @@ -65,7 +65,7 @@ }); test('store hashtag validates required fields', function () { - $response = $this->actingAs($this->user)->post(route('hashtags.store'), [ + $response = $this->actingAs($this->user)->post(route('app.hashtags.store'), [ 'name' => '', 'hashtags' => '', ]); @@ -77,7 +77,7 @@ test('update hashtag requires authentication', function () { $hashtag = WorkspaceHashtag::factory()->create(['workspace_id' => $this->workspace->id]); - $response = $this->put(route('hashtags.update', $hashtag), [ + $response = $this->put(route('app.hashtags.update', $hashtag), [ 'name' => 'Updated Name', 'hashtags' => '#updated #hashtags', ]); @@ -88,12 +88,12 @@ test('update hashtag updates the hashtag group', function () { $hashtag = WorkspaceHashtag::factory()->create(['workspace_id' => $this->workspace->id]); - $response = $this->actingAs($this->user)->put(route('hashtags.update', $hashtag), [ + $response = $this->actingAs($this->user)->put(route('app.hashtags.update', $hashtag), [ 'name' => 'Updated Name', 'hashtags' => '#updated #hashtags', ]); - $response->assertRedirect(route('hashtags.index')); + $response->assertRedirect(route('app.hashtags.index')); $hashtag->refresh(); expect($hashtag->name)->toBe('Updated Name'); @@ -104,7 +104,7 @@ $otherWorkspace = Workspace::factory()->create(); $hashtag = WorkspaceHashtag::factory()->create(['workspace_id' => $otherWorkspace->id]); - $response = $this->actingAs($this->user)->put(route('hashtags.update', $hashtag), [ + $response = $this->actingAs($this->user)->put(route('app.hashtags.update', $hashtag), [ 'name' => 'Updated Name', 'hashtags' => '#updated #hashtags', ]); @@ -116,7 +116,7 @@ test('destroy hashtag requires authentication', function () { $hashtag = WorkspaceHashtag::factory()->create(['workspace_id' => $this->workspace->id]); - $response = $this->delete(route('hashtags.destroy', $hashtag)); + $response = $this->delete(route('app.hashtags.destroy', $hashtag)); $response->assertRedirect(route('login')); }); @@ -124,9 +124,9 @@ test('destroy hashtag deletes the hashtag group', function () { $hashtag = WorkspaceHashtag::factory()->create(['workspace_id' => $this->workspace->id]); - $response = $this->actingAs($this->user)->delete(route('hashtags.destroy', $hashtag)); + $response = $this->actingAs($this->user)->delete(route('app.hashtags.destroy', $hashtag)); - $response->assertRedirect(route('hashtags.index')); + $response->assertRedirect(route('app.hashtags.index')); expect(WorkspaceHashtag::find($hashtag->id))->toBeNull(); }); @@ -134,7 +134,7 @@ $otherWorkspace = Workspace::factory()->create(); $hashtag = WorkspaceHashtag::factory()->create(['workspace_id' => $otherWorkspace->id]); - $response = $this->actingAs($this->user)->delete(route('hashtags.destroy', $hashtag)); + $response = $this->actingAs($this->user)->delete(route('app.hashtags.destroy', $hashtag)); $response->assertNotFound(); }); diff --git a/tests/Feature/WorkspaceInviteControllerTest.php b/tests/Feature/WorkspaceInviteControllerTest.php index a4197760..f68e71f4 100644 --- a/tests/Feature/WorkspaceInviteControllerTest.php +++ b/tests/Feature/WorkspaceInviteControllerTest.php @@ -17,7 +17,7 @@ // Index tests test('members index requires authentication', function () { - $response = $this->get(route('members')); + $response = $this->get(route('app.members')); $response->assertRedirect(route('login')); }); @@ -27,7 +27,7 @@ 'workspace_id' => $this->workspace->id, ]); - $response = $this->actingAs($this->user)->get(route('members')); + $response = $this->actingAs($this->user)->get(route('app.members')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -43,14 +43,14 @@ test('members index redirects if no workspace', function () { $this->user->update(['current_workspace_id' => null]); - $response = $this->actingAs($this->user)->get(route('members')); + $response = $this->actingAs($this->user)->get(route('app.members')); - $response->assertRedirect(route('workspaces.create')); + $response->assertRedirect(route('app.workspaces.create')); }); // Store invite tests test('store invite requires authentication', function () { - $response = $this->post(route('invites.store'), [ + $response = $this->post(route('app.invites.store'), [ 'email' => 'test@example.com', 'role' => WorkspaceRole::Member->value, ]); @@ -59,7 +59,7 @@ }); test('store invite creates invite and sends email', function () { - $response = $this->actingAs($this->user)->post(route('invites.store'), [ + $response = $this->actingAs($this->user)->post(route('app.invites.store'), [ 'email' => 'newmember@example.com', 'role' => WorkspaceRole::Member->value, ]); @@ -80,7 +80,7 @@ 'email' => 'existing@example.com', ]); - $response = $this->actingAs($this->user)->post(route('invites.store'), [ + $response = $this->actingAs($this->user)->post(route('app.invites.store'), [ 'email' => 'existing@example.com', 'role' => WorkspaceRole::Member->value, ]); @@ -92,7 +92,7 @@ $member = User::factory()->create(['setup' => Setup::Completed]); $this->workspace->members()->attach($member->id, ['role' => WorkspaceRole::Member->value]); - $response = $this->actingAs($this->user)->post(route('invites.store'), [ + $response = $this->actingAs($this->user)->post(route('app.invites.store'), [ 'email' => $member->email, 'role' => WorkspaceRole::Member->value, ]); @@ -106,7 +106,7 @@ 'workspace_id' => $this->workspace->id, ]); - $response = $this->delete(route('invites.destroy', $invite)); + $response = $this->delete(route('app.invites.destroy', $invite)); $response->assertRedirect(route('login')); }); @@ -116,7 +116,7 @@ 'workspace_id' => $this->workspace->id, ]); - $response = $this->actingAs($this->user)->delete(route('invites.destroy', $invite)); + $response = $this->actingAs($this->user)->delete(route('app.invites.destroy', $invite)); $response->assertRedirect(); expect(WorkspaceInvite::find($invite->id))->toBeNull(); @@ -128,7 +128,7 @@ 'workspace_id' => $otherWorkspace->id, ]); - $response = $this->actingAs($this->user)->delete(route('invites.destroy', $invite)); + $response = $this->actingAs($this->user)->delete(route('app.invites.destroy', $invite)); $response->assertNotFound(); }); @@ -138,7 +138,7 @@ $member = User::factory()->create(['setup' => Setup::Completed]); $this->workspace->members()->attach($member->id, ['role' => WorkspaceRole::Member->value]); - $response = $this->delete(route('members.remove', $member)); + $response = $this->delete(route('app.members.remove', $member)); $response->assertRedirect(route('login')); }); @@ -147,14 +147,14 @@ $member = User::factory()->create(['setup' => Setup::Completed]); $this->workspace->members()->attach($member->id, ['role' => WorkspaceRole::Member->value]); - $response = $this->actingAs($this->user)->delete(route('members.remove', $member)); + $response = $this->actingAs($this->user)->delete(route('app.members.remove', $member)); $response->assertRedirect(); expect($this->workspace->hasMember($member))->toBeFalse(); }); test('remove member fails for owner', function () { - $response = $this->actingAs($this->user)->delete(route('members.remove', $this->user)); + $response = $this->actingAs($this->user)->delete(route('app.members.remove', $this->user)); $response->assertSessionHasErrors('member'); }); diff --git a/tests/Feature/WorkspaceLabelControllerTest.php b/tests/Feature/WorkspaceLabelControllerTest.php index eb7151c8..3783d2c4 100644 --- a/tests/Feature/WorkspaceLabelControllerTest.php +++ b/tests/Feature/WorkspaceLabelControllerTest.php @@ -13,7 +13,7 @@ // Index tests test('labels index requires authentication', function () { - $response = $this->get(route('labels.index')); + $response = $this->get(route('app.labels.index')); $response->assertRedirect(route('login')); }); @@ -21,7 +21,7 @@ test('labels index shows labels for workspace', function () { WorkspaceLabel::factory()->count(3)->create(['workspace_id' => $this->workspace->id]); - $response = $this->actingAs($this->user)->get(route('labels.index')); + $response = $this->actingAs($this->user)->get(route('app.labels.index')); $response->assertOk(); $response->assertInertia(fn ($page) => $page @@ -34,14 +34,14 @@ test('labels index redirects if no workspace', function () { $this->user->update(['current_workspace_id' => null]); - $response = $this->actingAs($this->user)->get(route('labels.index')); + $response = $this->actingAs($this->user)->get(route('app.labels.index')); - $response->assertRedirect(route('workspaces.create')); + $response->assertRedirect(route('app.workspaces.create')); }); // Store tests test('store label requires authentication', function () { - $response = $this->post(route('labels.store'), [ + $response = $this->post(route('app.labels.store'), [ 'name' => 'Test Label', 'color' => '#FF5733', ]); @@ -50,12 +50,12 @@ }); test('store label creates label', function () { - $response = $this->actingAs($this->user)->post(route('labels.store'), [ + $response = $this->actingAs($this->user)->post(route('app.labels.store'), [ 'name' => 'New Label', 'color' => '#FF5733', ]); - $response->assertRedirect(route('labels.index')); + $response->assertRedirect(route('app.labels.index')); $this->assertDatabaseHas('workspace_labels', [ 'workspace_id' => $this->workspace->id, @@ -65,7 +65,7 @@ }); test('store label validates required fields', function () { - $response = $this->actingAs($this->user)->post(route('labels.store'), [ + $response = $this->actingAs($this->user)->post(route('app.labels.store'), [ 'name' => '', 'color' => '', ]); @@ -74,7 +74,7 @@ }); test('store label validates color format', function () { - $response = $this->actingAs($this->user)->post(route('labels.store'), [ + $response = $this->actingAs($this->user)->post(route('app.labels.store'), [ 'name' => 'Valid Name', 'color' => 'invalid-color', ]); @@ -86,7 +86,7 @@ test('update label requires authentication', function () { $label = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]); - $response = $this->put(route('labels.update', $label), [ + $response = $this->put(route('app.labels.update', $label), [ 'name' => 'Updated Label', 'color' => '#00FF00', ]); @@ -97,12 +97,12 @@ test('update label updates the label', function () { $label = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]); - $response = $this->actingAs($this->user)->put(route('labels.update', $label), [ + $response = $this->actingAs($this->user)->put(route('app.labels.update', $label), [ 'name' => 'Updated Label', 'color' => '#00FF00', ]); - $response->assertRedirect(route('labels.index')); + $response->assertRedirect(route('app.labels.index')); $label->refresh(); expect($label->name)->toBe('Updated Label'); @@ -113,7 +113,7 @@ $otherWorkspace = Workspace::factory()->create(); $label = WorkspaceLabel::factory()->create(['workspace_id' => $otherWorkspace->id]); - $response = $this->actingAs($this->user)->put(route('labels.update', $label), [ + $response = $this->actingAs($this->user)->put(route('app.labels.update', $label), [ 'name' => 'Updated Label', 'color' => '#00FF00', ]); @@ -125,7 +125,7 @@ test('destroy label requires authentication', function () { $label = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]); - $response = $this->delete(route('labels.destroy', $label)); + $response = $this->delete(route('app.labels.destroy', $label)); $response->assertRedirect(route('login')); }); @@ -133,9 +133,9 @@ test('destroy label deletes the label', function () { $label = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]); - $response = $this->actingAs($this->user)->delete(route('labels.destroy', $label)); + $response = $this->actingAs($this->user)->delete(route('app.labels.destroy', $label)); - $response->assertRedirect(route('labels.index')); + $response->assertRedirect(route('app.labels.index')); expect(WorkspaceLabel::find($label->id))->toBeNull(); }); @@ -143,7 +143,7 @@ $otherWorkspace = Workspace::factory()->create(); $label = WorkspaceLabel::factory()->create(['workspace_id' => $otherWorkspace->id]); - $response = $this->actingAs($this->user)->delete(route('labels.destroy', $label)); + $response = $this->actingAs($this->user)->delete(route('app.labels.destroy', $label)); $response->assertNotFound(); }); diff --git a/tests/Pest.php b/tests/Pest.php index b3a25b73..f2e39978 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,5 +1,8 @@ extend(Tests\TestCase::class) - ->use(Illuminate\Foundation\Testing\RefreshDatabase::class) +pest()->extend(TestCase::class) + ->use(RefreshDatabase::class) ->in('Feature', 'Unit'); /* diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php index 27f3f877..44a4f337 100644 --- a/tests/Unit/ExampleTest.php +++ b/tests/Unit/ExampleTest.php @@ -2,4 +2,4 @@ test('that true is true', function () { expect(true)->toBeTrue(); -}); \ No newline at end of file +}); diff --git a/tests/Unit/HelpersTest.php b/tests/Unit/HelpersTest.php index 3c9cb2a4..1c7dc27b 100644 --- a/tests/Unit/HelpersTest.php +++ b/tests/Unit/HelpersTest.php @@ -84,7 +84,7 @@ test('uploadFromUrl handles exceptions gracefully', function () { Http::fake(function () { - throw new \Exception('Network error'); + throw new Exception('Network error'); }); $result = uploadFromUrl('https://example.com/image.jpg'); diff --git a/tests/Unit/Mail/AccountDisconnectedTest.php b/tests/Unit/Mail/AccountDisconnectedTest.php index c62e1977..3e9f6ffa 100644 --- a/tests/Unit/Mail/AccountDisconnectedTest.php +++ b/tests/Unit/Mail/AccountDisconnectedTest.php @@ -4,6 +4,7 @@ use App\Mail\AccountDisconnected; use App\Models\SocialAccount; use App\Models\Workspace; +use Illuminate\Contracts\Queue\ShouldQueue; test('account disconnected mail has correct subject', function () { $workspace = Workspace::factory()->create(['name' => 'My Workspace']); @@ -36,7 +37,7 @@ expect($content->with['platformName'])->toBe('LinkedIn'); expect($content->with['accountName'])->toBe('John Doe'); expect($content->with['workspaceName'])->toBe('Test Team'); - expect($content->with['url'])->toBe(route('accounts')); + expect($content->with['url'])->toBe(route('app.accounts')); }); test('account disconnected mail uses username when display name is null', function () { @@ -64,5 +65,5 @@ $mail = new AccountDisconnected($account); - expect($mail)->toBeInstanceOf(\Illuminate\Contracts\Queue\ShouldQueue::class); + expect($mail)->toBeInstanceOf(ShouldQueue::class); }); diff --git a/tests/Unit/Mail/WorkspaceInviteTest.php b/tests/Unit/Mail/WorkspaceInviteTest.php index d0b5492c..7a903329 100644 --- a/tests/Unit/Mail/WorkspaceInviteTest.php +++ b/tests/Unit/Mail/WorkspaceInviteTest.php @@ -3,6 +3,7 @@ use App\Mail\WorkspaceInvite; use App\Models\Workspace; use App\Models\WorkspaceInvite as WorkspaceInviteModel; +use Illuminate\Contracts\Queue\ShouldQueue; test('workspace invite mail has correct subject', function () { $workspace = Workspace::factory()->create(['name' => 'Test Workspace']); @@ -28,7 +29,7 @@ expect($content->with['title'])->toBe("You've been invited to join My Team"); expect($content->with['previewText'])->toBe("You've been invited to join My Team"); expect($content->with['invite'])->toBe($invite); - expect($content->with['url'])->toBe(route('invites.show', $invite->id)); + expect($content->with['url'])->toBe(route('app.invites.show', $invite->id)); }); test('workspace invite mail has no attachments', function () { @@ -44,5 +45,5 @@ $mail = new WorkspaceInvite($invite); - expect($mail)->toBeInstanceOf(\Illuminate\Contracts\Queue\ShouldQueue::class); + expect($mail)->toBeInstanceOf(ShouldQueue::class); }); diff --git a/tests/Unit/Models/MediaTest.php b/tests/Unit/Models/MediaTest.php index 85a513ee..e33f834a 100644 --- a/tests/Unit/Models/MediaTest.php +++ b/tests/Unit/Models/MediaTest.php @@ -1,7 +1,6 @@ $publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class, 'Instagram requires at least one image or video.'); + ->toThrow(Exception::class, 'Instagram requires at least one image or video.'); }); test('instagram publisher publishes single image', function () { @@ -142,5 +142,5 @@ $publisher = new InstagramPublisher; expect(fn () => $publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class); + ->toThrow(Exception::class); }); diff --git a/tests/Unit/Services/LinkedInPublisherTest.php b/tests/Unit/Services/LinkedInPublisherTest.php index 349a161a..43b3820b 100644 --- a/tests/Unit/Services/LinkedInPublisherTest.php +++ b/tests/Unit/Services/LinkedInPublisherTest.php @@ -9,7 +9,6 @@ use App\Models\Workspace; use App\Services\Social\LinkedInPublisher; use Illuminate\Support\Facades\Http; -use Illuminate\Support\Facades\Storage; beforeEach(function () { $this->workspace = Workspace::factory()->create(); @@ -47,7 +46,7 @@ $publisher = new LinkedInPublisher; expect(fn () => $publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class, 'No valid images for LinkedIn carousel'); + ->toThrow(Exception::class, 'No valid images for LinkedIn carousel'); }); test('linkedin publisher throws token expired exception on oauth error', function () { @@ -138,7 +137,7 @@ $publisher = new LinkedInPublisher; expect(fn () => $publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class); + ->toThrow(Exception::class); }); test('linkedin publisher throws exception for unsupported content type', function () { @@ -147,7 +146,7 @@ $publisher = new LinkedInPublisher; expect(fn () => $publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class, 'Unsupported LinkedIn content type'); + ->toThrow(Exception::class, 'Unsupported LinkedIn content type'); }); test('linkedin publisher handles 401 status as token error', function () { @@ -179,7 +178,7 @@ $publisher = new LinkedInPublisher; expect(fn () => $publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class); + ->toThrow(Exception::class); }); test('linkedin publisher refreshes token when expiring soon', function () { diff --git a/tests/Unit/Services/Social/FacebookPublisherTest.php b/tests/Unit/Services/Social/FacebookPublisherTest.php index 8c567b1b..b8786fcd 100644 --- a/tests/Unit/Services/Social/FacebookPublisherTest.php +++ b/tests/Unit/Services/Social/FacebookPublisherTest.php @@ -332,7 +332,7 @@ $this->postPlatform->update(['content' => null]); expect(fn () => $this->publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class, 'Facebook text posts require content'); + ->toThrow(Exception::class, 'Facebook text posts require content'); }); test('facebook publisher can publish single image with null content', function () { diff --git a/tests/Unit/Services/Social/InstagramPublisherTest.php b/tests/Unit/Services/Social/InstagramPublisherTest.php index aa93d95d..76cc38a2 100644 --- a/tests/Unit/Services/Social/InstagramPublisherTest.php +++ b/tests/Unit/Services/Social/InstagramPublisherTest.php @@ -40,7 +40,7 @@ test('instagram publisher throws exception without media', function () { expect(fn () => $this->publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class, 'Instagram requires at least one image or video'); + ->toThrow(Exception::class, 'Instagram requires at least one image or video'); }); test('instagram publisher can publish single image', function () { diff --git a/tests/Unit/Services/Social/LinkedInTokenSynchronizerTest.php b/tests/Unit/Services/Social/LinkedInTokenSynchronizerTest.php index cf8b43dd..6d5ba301 100644 --- a/tests/Unit/Services/Social/LinkedInTokenSynchronizerTest.php +++ b/tests/Unit/Services/Social/LinkedInTokenSynchronizerTest.php @@ -1,6 +1,5 @@ postPlatform->update(['content' => null]); expect(fn () => $this->publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class, 'Threads text posts require content'); + ->toThrow(Exception::class, 'Threads text posts require content'); }); test('threads publisher can publish image with null content', function () { diff --git a/tests/Unit/Services/Social/XPublisherTest.php b/tests/Unit/Services/Social/XPublisherTest.php index 19d39b7c..31dc06a4 100644 --- a/tests/Unit/Services/Social/XPublisherTest.php +++ b/tests/Unit/Services/Social/XPublisherTest.php @@ -160,14 +160,14 @@ $this->postPlatform->update(['content' => '']); expect(fn () => $this->publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class, 'X posts require either text or media'); + ->toThrow(Exception::class, 'X posts require either text or media'); }); test('x publisher throws exception with null content and no media', function () { $this->postPlatform->update(['content' => null]); expect(fn () => $this->publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class, 'X posts require either text or media'); + ->toThrow(Exception::class, 'X posts require either text or media'); }); test('x publisher throws exception when no refresh token available', function () { diff --git a/tests/Unit/Services/Social/YouTubePublisherTest.php b/tests/Unit/Services/Social/YouTubePublisherTest.php index 00aca658..65a61fed 100644 --- a/tests/Unit/Services/Social/YouTubePublisherTest.php +++ b/tests/Unit/Services/Social/YouTubePublisherTest.php @@ -86,7 +86,7 @@ try { $this->publisher->publish($this->postPlatform); - } catch (\Exception $e) { + } catch (Exception $e) { // Expected to fail on upload, but token should be refreshed } @@ -159,5 +159,5 @@ ]); expect(fn () => $this->publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class, 'YouTube Shorts require a title'); + ->toThrow(Exception::class, 'YouTube Shorts require a title'); }); diff --git a/tests/Unit/Services/XPublisherTest.php b/tests/Unit/Services/XPublisherTest.php index dea9c474..b19ae6a4 100644 --- a/tests/Unit/Services/XPublisherTest.php +++ b/tests/Unit/Services/XPublisherTest.php @@ -105,7 +105,7 @@ $publisher = new XPublisher; expect(fn () => $publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class); + ->toThrow(Exception::class); }); test('x publisher returns unknown id when no id in response', function () { @@ -177,7 +177,7 @@ $publisher = new XPublisher; expect(fn () => $publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class, 'X API error'); + ->toThrow(Exception::class, 'X API error'); }); test('x publisher handles empty error response', function () { @@ -188,5 +188,5 @@ $publisher = new XPublisher; expect(fn () => $publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class); + ->toThrow(Exception::class); }); diff --git a/tests/Unit/Services/YouTubePublisherTest.php b/tests/Unit/Services/YouTubePublisherTest.php index 457fac19..25ff8a4b 100644 --- a/tests/Unit/Services/YouTubePublisherTest.php +++ b/tests/Unit/Services/YouTubePublisherTest.php @@ -33,7 +33,7 @@ $publisher = new YouTubePublisher; expect(fn () => $publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class, 'YouTube Shorts requires a video to publish.'); + ->toThrow(Exception::class, 'YouTube Shorts requires a video to publish.'); }); test('youtube publisher throws exception for non video media', function () { @@ -46,7 +46,7 @@ $publisher = new YouTubePublisher; expect(fn () => $publisher->publish($this->postPlatform)) - ->toThrow(\Exception::class, 'YouTube Shorts only supports video content.'); + ->toThrow(Exception::class, 'YouTube Shorts only supports video content.'); }); test('youtube publisher throws exception when no refresh token for expired token', function () { diff --git a/tests/Unit/Traits/HasMediaTest.php b/tests/Unit/Traits/HasMediaTest.php index 1a7b07cd..186991fd 100644 --- a/tests/Unit/Traits/HasMediaTest.php +++ b/tests/Unit/Traits/HasMediaTest.php @@ -4,6 +4,7 @@ use App\Models\PostPlatform; use App\Models\User; use App\Models\Workspace; +use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; @@ -14,7 +15,7 @@ test('model can get media relationship', function () { $workspace = Workspace::factory()->create(); - expect($workspace->media())->toBeInstanceOf(\Illuminate\Database\Eloquent\Relations\MorphMany::class); + expect($workspace->media())->toBeInstanceOf(MorphMany::class); }); test('model can add media from uploaded file', function () {