Simplify created_via persistence to a plain data_get.
Callers already pass a CreatedVia enum or omit it; drop the defensive resolver. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
588891767b
commit
227ee45c2b
2 changed files with 2 additions and 39 deletions
|
|
@ -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<string, mixed> $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<string, mixed> $data
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue