diff --git a/app/Actions/Post/CreatePost.php b/app/Actions/Post/CreatePost.php index 85adfb06..f4089db5 100644 --- a/app/Actions/Post/CreatePost.php +++ b/app/Actions/Post/CreatePost.php @@ -28,15 +28,15 @@ 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 — defaults to web when omitted - * or invalid, and never blocks creation. + * api, or automation). Analytical only — null when omitted or invalid, + * and never blocks creation. * * @param array{ * content?: ?string, * media?: array, * date?: ?string, * scheduled_at?: ?string, - * created_via?: CreatedVia, + * created_via?: ?CreatedVia, * platforms?: array}>, * label_ids?: array * } $data @@ -102,7 +102,7 @@ public static function execute(Workspace $workspace, User $user, array $data): P * * @param array $data */ - private static function resolveCreatedVia(array $data): CreatedVia + private static function resolveCreatedVia(array $data): ?CreatedVia { $value = data_get($data, 'created_via'); @@ -111,10 +111,10 @@ private static function resolveCreatedVia(array $data): CreatedVia } if (is_string($value)) { - return CreatedVia::tryFrom($value) ?? CreatedVia::Web; + return CreatedVia::tryFrom($value); } - return CreatedVia::Web; + return null; } /** diff --git a/tests/Feature/Actions/Post/CreatePostTest.php b/tests/Feature/Actions/Post/CreatePostTest.php index 20b68490..c9d7ae64 100644 --- a/tests/Feature/Actions/Post/CreatePostTest.php +++ b/tests/Feature/Actions/Post/CreatePostTest.php @@ -44,7 +44,7 @@ 'automation' => CreatedVia::Automation, ]); -test('execute defaults created_via to web when omitted', function () { +test('execute leaves created_via null when omitted', function () { $user = User::factory()->create(); $workspace = Workspace::factory()->create(['user_id' => $user->id]); @@ -52,10 +52,10 @@ 'content' => 'Hello world', ]); - expect($post->fresh()->created_via)->toBe(CreatedVia::Web); + expect($post->fresh()->created_via)->toBeNull(); }); -test('execute defaults created_via to web when null or invalid', function (mixed $createdVia) { +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]); @@ -64,7 +64,7 @@ 'created_via' => $createdVia, ]); - expect($post->fresh()->created_via)->toBe(CreatedVia::Web); + expect($post->fresh()->created_via)->toBeNull(); })->with([ 'null' => null, 'invalid string' => 'not-a-channel',