Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

1.1 KB
Raw Blame
<?php

declare(strict_types=1);

use App\Models\Workspace;

/**
 * Regression test for a bug where Media rows ended up with
 * `mediable_type = "App\Models\Workspace"` (FQCN) instead of the
 * morphMap alias `"workspace"`. The bug source was code that did
 *   `$media->mediable_type = Workspace::class;`
 * which bypasses the morph map. Using the relationship
 * (`$workspace->media()->create([...])` or
 * `$media->mediable()->associate($workspace)`) is the correct path.
 */
test('Workspace::media()->create persists the morphMap alias, not the FQCN', function () {
    $workspace = Workspace::factory()->create();

    $media = $workspace->media()->create([
        'collection' => 'ai-generated',
        'type' => 'image',
        'path' => 'test/dummy.webp',
        'original_filename' => 'dummy.webp',
        'mime_type' => 'image/webp',
        'size' => 100,
        'order' => 0,
    ]);

    expect($media->mediable_type)->toBe('workspace');
    expect($media->mediable_type)->not->toBe(Workspace::class);
    expect($media->mediable->is($workspace))->toBeTrue();
});