diff --git a/app/Actions/Post/CreatePost.php b/app/Actions/Post/CreatePost.php index f4089db5..11c5a1f4 100644 --- a/app/Actions/Post/CreatePost.php +++ b/app/Actions/Post/CreatePost.php @@ -28,8 +28,7 @@ class CreatePost * works for REST, MCP, and web callers. * * `created_via` records which entry point created the post (web, mcp, - * api, or automation). Analytical only — null when omitted or invalid, - * and never blocks creation. + * api, or automation). Analytical only — null when omitted. * * @param array{ * content?: ?string, @@ -51,7 +50,7 @@ public static function execute(Workspace $workspace, User $user, array $data): P 'content' => data_get($data, 'content', ''), 'media' => data_get($data, 'media', []), 'status' => PostStatus::Draft, - 'created_via' => self::resolveCreatedVia($data), + 'created_via' => data_get($data, 'created_via'), 'scheduled_at' => $scheduledAt, ]); @@ -97,26 +96,6 @@ public static function execute(Workspace $workspace, User $user, array $data): P return $post; } - /** - * Analytical only — never fail creation over a missing/invalid value. - * - * @param array $data - */ - private static function resolveCreatedVia(array $data): ?CreatedVia - { - $value = data_get($data, 'created_via'); - - if ($value instanceof CreatedVia) { - return $value; - } - - if (is_string($value)) { - return CreatedVia::tryFrom($value); - } - - return null; - } - /** * @param array $data */ diff --git a/tests/Feature/Actions/Post/CreatePostTest.php b/tests/Feature/Actions/Post/CreatePostTest.php index c9d7ae64..410257dd 100644 --- a/tests/Feature/Actions/Post/CreatePostTest.php +++ b/tests/Feature/Actions/Post/CreatePostTest.php @@ -54,19 +54,3 @@ expect($post->fresh()->created_via)->toBeNull(); }); - -test('execute leaves created_via null when null or invalid', function (mixed $createdVia) { - $user = User::factory()->create(); - $workspace = Workspace::factory()->create(['user_id' => $user->id]); - - $post = CreatePost::execute($workspace, $user, [ - 'content' => 'Hello world', - 'created_via' => $createdVia, - ]); - - expect($post->fresh()->created_via)->toBeNull(); -})->with([ - 'null' => null, - 'invalid string' => 'not-a-channel', - 'integer' => 1, -]);