feat: add slug field to events and implement tests for slug uniqueness per tenant
This commit is contained in:
37
tests/Feature/Migrations/AddSlugsToEventsTest.php
Normal file
37
tests/Feature/Migrations/AddSlugsToEventsTest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Migrations;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AddSlugsToEventsTest extends TestCase
|
||||
{
|
||||
public function test_it_backfills_unique_slugs_per_tenant(): void
|
||||
{
|
||||
Schema::create('events', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('tenant_code');
|
||||
$table->string('title');
|
||||
});
|
||||
|
||||
DB::table('events')->insert([
|
||||
['id' => 1, 'tenant_code' => 'acme', 'title' => 'Gran Fiesta'],
|
||||
['id' => 2, 'tenant_code' => 'acme', 'title' => 'Gran Fiesta'],
|
||||
['id' => 3, 'tenant_code' => 'other', 'title' => 'Gran Fiesta'],
|
||||
['id' => 4, 'tenant_code' => 'acme', 'title' => '---'],
|
||||
]);
|
||||
|
||||
$migration = require database_path('migrations/2026_09_22_010000_add_slugs_to_events.php');
|
||||
$migration->up();
|
||||
|
||||
$this->assertSame([
|
||||
1 => 'gran-fiesta',
|
||||
2 => 'gran-fiesta-2',
|
||||
3 => 'gran-fiesta',
|
||||
4 => 'evento-4',
|
||||
], DB::table('events')->orderBy('id')->pluck('slug', 'id')->all());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user