<?php

use App\Domains\Workspace\Actions\CreateWorkspace;
use App\Models\User;

it('creates a workspace and assigns owner as member', function () {
    $user = User::factory()->create();

    $workspace = (new CreateWorkspace)->handle($user, ['name' => 'Acme Corp']);

    expect($workspace->name)->toBe('Acme Corp')
        ->and($workspace->owner_id)->toBe($user->id)
        ->and($workspace->ulid)->toHaveLength(26);

    $this->assertDatabaseHas('workspace_members', [
        'workspace_id' => $workspace->id,
        'user_id' => $user->id,
        'role' => 'owner',
    ]);
});
