Leave created_via null when omitted or invalid.
Provenance is optional analytics — only persist a CreatedVia value when callers set a valid one. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
a545d29cfb
commit
588891767b
2 changed files with 10 additions and 10 deletions
|
|
@ -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<int, mixed>,
|
||||
* date?: ?string,
|
||||
* scheduled_at?: ?string,
|
||||
* created_via?: CreatedVia,
|
||||
* created_via?: ?CreatedVia,
|
||||
* platforms?: array<int, array{social_account_id: string, content_type?: string, meta?: array<string, mixed>}>,
|
||||
* label_ids?: array<int, string>
|
||||
* } $data
|
||||
|
|
@ -102,7 +102,7 @@ public static function execute(Workspace $workspace, User $user, array $data): P
|
|||
*
|
||||
* @param array<string, mixed> $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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Reference in a new issue