fix(bio): add missing url_format columns + update PublicUrl tests

- Migration: url_format_override on bio_pages, bio_url_format on workspaces,
  needs_migration + migration_required_at on bio_pages (model casts existed, columns did not)
- PublicUrl tests updated for effectiveFormat() logic:
  - Pro default = SystemPath (no subdomain without explicit bio_url_format=Subdomain)
  - url_format_override on bio overrides workspace format
  - needs_migration=true → publicUrl() returns ''

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
main
boban 2026-05-17 23:32:53 +02:00
parent 7d2926ce77
commit a3552970fe
2 changed files with 64 additions and 1 deletions

View File

@ -0,0 +1,28 @@
<?php
use App\Enums\BioUrlFormat;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('bio_pages', function (Blueprint $table) {
$table->string('url_format_override', 32)->nullable()->after('slug');
$table->boolean('needs_migration')->default(false)->after('is_published');
$table->timestamp('migration_required_at')->nullable()->after('needs_migration');
});
Schema::table('workspaces', function (Blueprint $table) {
$table->string('bio_url_format', 32)->nullable()->after('subdomain_provisioned_at');
});
}
public function down(): void
{
Schema::table('workspaces', fn (Blueprint $t) => $t->dropColumn('bio_url_format'));
Schema::table('bio_pages', fn (Blueprint $t) => $t->dropColumn(['url_format_override', 'needs_migration', 'migration_required_at']));
}
};

View File

@ -2,6 +2,7 @@
use App\Domains\Bio\Models\BioPage; use App\Domains\Bio\Models\BioPage;
use App\Domains\Workspace\Models\Workspace; use App\Domains\Workspace\Models\Workspace;
use App\Enums\BioUrlFormat;
it('returns free path-url for free plan workspace', function () { it('returns free path-url for free plan workspace', function () {
$ws = Workspace::factory()->free()->create(['slug' => 'nexxo']); $ws = Workspace::factory()->free()->create(['slug' => 'nexxo']);
@ -17,13 +18,37 @@ it('returns shortPublicUrl without scheme', function () {
expect($bio->shortPublicUrl())->toBe('nimu.li/b/nexxo/my-bio'); expect($bio->shortPublicUrl())->toBe('nimu.li/b/nexxo/my-bio');
}); });
it('returns pro subdomain-url when subdomain_full set', function () { it('returns pro subdomain-url when bio_url_format=Subdomain and subdomain_full set', function () {
$ws = Workspace::factory()->pro()->create([
'slug' => 'acme',
'subdomain_full' => 'acme.nimu.li',
'bio_url_format' => BioUrlFormat::Subdomain,
]);
$bio = BioPage::factory()->for($ws)->create(['slug' => 'john']);
expect($bio->publicUrl())->toBe('https://acme.nimu.li/b/john');
});
it('returns pro path-url by default (no bio_url_format set)', function () {
$ws = Workspace::factory()->pro()->create([ $ws = Workspace::factory()->pro()->create([
'slug' => 'acme', 'slug' => 'acme',
'subdomain_full' => 'acme.nimu.li', 'subdomain_full' => 'acme.nimu.li',
]); ]);
$bio = BioPage::factory()->for($ws)->create(['slug' => 'john']); $bio = BioPage::factory()->for($ws)->create(['slug' => 'john']);
expect($bio->publicUrl())->toBe('https://nimu.li/b/acme/john');
});
it('bio url_format_override=Subdomain overrides workspace format', function () {
$ws = Workspace::factory()->pro()->create([
'slug' => 'acme',
'subdomain_full' => 'acme.nimu.li',
]);
$bio = BioPage::factory()->for($ws)->create([
'slug' => 'john',
'url_format_override' => BioUrlFormat::Subdomain,
]);
expect($bio->publicUrl())->toBe('https://acme.nimu.li/b/john'); expect($bio->publicUrl())->toBe('https://acme.nimu.li/b/john');
}); });
@ -46,3 +71,13 @@ it('falls back to free path when no subdomain_full on paid plan', function () {
expect($bio->publicUrl())->toBe('https://nimu.li/b/acme/test'); expect($bio->publicUrl())->toBe('https://nimu.li/b/acme/test');
}); });
it('returns empty string when needs_migration is true', function () {
$ws = Workspace::factory()->free()->create(['slug' => 'nexxo']);
$bio = BioPage::factory()->for($ws)->create([
'slug' => 'migrating',
'needs_migration' => true,
]);
expect($bio->publicUrl())->toBe('');
});