49 lines
2.1 KiB
PHP
49 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Migrations;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Tests\TestCase;
|
|
|
|
class AddTenantTimezoneTest extends TestCase
|
|
{
|
|
public function test_it_converts_legacy_event_windows_once_and_preserves_other_windows(): void
|
|
{
|
|
Schema::create('tenants', function (Blueprint $table): void {
|
|
$table->id();
|
|
$table->string('codigo');
|
|
});
|
|
Schema::create('event_dates', function (Blueprint $table): void {
|
|
$table->id();
|
|
$table->string('tenant_code');
|
|
$table->date('date');
|
|
$table->time('time_start');
|
|
$table->time('time_end');
|
|
$table->integer('validity_time_id');
|
|
});
|
|
Schema::create('validity_times', function (Blueprint $table): void {
|
|
$table->id();
|
|
$table->dateTime('fixed_starts_at');
|
|
$table->dateTime('fixed_expires_at');
|
|
});
|
|
DB::table('tenants')->insert(['codigo' => 'football']);
|
|
foreach ([1, 2] as $id) {
|
|
DB::table('validity_times')->insert([
|
|
'id' => $id, 'fixed_starts_at' => '2026-09-21 22:00:00', 'fixed_expires_at' => '2026-09-22 02:00:00',
|
|
]);
|
|
}
|
|
DB::table('event_dates')->insert([
|
|
'tenant_code' => 'football', 'date' => '2026-09-21', 'time_start' => '22:00:00', 'time_end' => '02:00:00', 'validity_time_id' => 1,
|
|
]);
|
|
$migration = require database_path('migrations/2026_09_21_040000_add_timezone_to_tenants.php');
|
|
$migration->up();
|
|
$this->assertDatabaseHas('tenants', ['codigo' => 'football', 'timezone' => 'America/Argentina/Buenos_Aires']);
|
|
$this->assertDatabaseHas('validity_times', ['id' => 1, 'fixed_starts_at' => '2026-09-22 01:00:00', 'fixed_expires_at' => '2026-09-22 05:00:00']);
|
|
$this->assertDatabaseHas('validity_times', ['id' => 2, 'fixed_starts_at' => '2026-09-21 22:00:00']);
|
|
$migration->down();
|
|
$this->assertFalse(Schema::hasColumn('tenants', 'timezone'));
|
|
}
|
|
}
|