trypost/tests/Feature/Actions/Workspace/CreateWorkspaceTest.php
Paulo Castellano a09b1f45c2 Structure brand voice and make generated copy platform-aware
Replace free-text brand_tone/brand_voice_notes with a single structured
brand_voice_traits JSON column backed by the BrandVoiceTrait enum, exposed
as choice-chip pills in the brand settings UI and autofillable from a site.
Brand voice and visuals become per-automation toggles on the Generate node.

Unify the image controls into one 0-10 picker (0 = text-only, 1 = single,
2+ = carousel) and feed the generator the most restrictive selected network
so copy fits every platform. Pass that same platform context through the
humanizer pass — extracted into a shared ResolvesPlatformCopyBudget trait —
so the rewrite can no longer drift past the character cap the generator
respected, in both the automation and manual creation flows.

Persist the trigger node's schedule editor fields on save (they were
silently dropped by validated() for lacking validation rules).
2026-06-12 17:09:39 -03:00

55 lines
2 KiB
PHP

<?php
declare(strict_types=1);
use App\Actions\Workspace\CreateWorkspace;
use App\Enums\UserWorkspace\Role;
use App\Models\Account;
use App\Models\User;
test('CreateWorkspace persists name and brand fields', function () {
$account = Account::factory()->create();
$user = User::factory()->create(['account_id' => $account->id]);
$workspace = CreateWorkspace::execute($user, [
'name' => 'Acme Inc',
'brand_website' => 'https://acme.example',
'brand_description' => 'We sell rockets.',
'brand_voice_traits' => ['third_person', 'no_hype'],
'content_language' => 'en',
]);
expect($workspace->name)->toBe('Acme Inc');
expect($workspace->brand_website)->toBe('https://acme.example');
expect($workspace->brand_description)->toBe('We sell rockets.');
expect($workspace->brand_voice_traits)->toBe(['third_person', 'no_hype']);
expect($workspace->content_language)->toBe('en');
expect($workspace->account_id)->toBe($account->id);
expect($workspace->user_id)->toBe($user->id);
});
test('CreateWorkspace switches user current workspace and attaches as admin', function () {
$account = Account::factory()->create();
$user = User::factory()->create(['account_id' => $account->id, 'current_workspace_id' => null]);
$workspace = CreateWorkspace::execute($user, ['name' => 'Acme']);
$user->refresh();
expect($user->current_workspace_id)->toBe($workspace->id);
expect($workspace->members->contains($user))->toBeTrue();
$member = $workspace->members()->where('user_id', $user->id)->first();
expect($member?->pivot->role)->toBe(Role::Admin->value);
});
test('CreateWorkspace ignores unknown extra keys like logo_url', function () {
$account = Account::factory()->create();
$user = User::factory()->create(['account_id' => $account->id]);
$workspace = CreateWorkspace::execute($user, [
'name' => 'Acme',
'logo_url' => 'https://acme.example/logo.png',
]);
expect($workspace->name)->toBe('Acme');
});