feat(migrations): add migration for grouping Pyme Rural tenants and updating client associations
This commit is contained in:
109
tests/Feature/Migrations/GroupPymeRuralTenantsTest.php
Normal file
109
tests/Feature/Migrations/GroupPymeRuralTenantsTest.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Migrations;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GroupPymeRuralTenantsTest extends TestCase
|
||||
{
|
||||
public function test_it_groups_the_futbol_and_desfile_tenants_under_pyme_rural(): void
|
||||
{
|
||||
$this->createSchema();
|
||||
|
||||
$now = now();
|
||||
$onTicketClientId = DB::table('clients')->insertGetId([
|
||||
'code' => 'onticket',
|
||||
'name' => 'OnTicket',
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
DB::table('tenants')->insert([
|
||||
['client_id' => $onTicketClientId, 'codigo' => 'onticket'],
|
||||
['client_id' => $onTicketClientId, 'codigo' => 'fiesta_futbol_infantil'],
|
||||
['client_id' => $onTicketClientId, 'codigo' => 'desfile_pura_tendencia'],
|
||||
]);
|
||||
DB::table('integrations')->insert([
|
||||
'integration_code' => 'email',
|
||||
'name' => 'Email',
|
||||
]);
|
||||
$instanceId = DB::table('integration_instances')->insertGetId([
|
||||
'integration_code' => 'email',
|
||||
'name' => 'OnTicket email',
|
||||
'integration_data' => null,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
DB::table('client_integrations')->insert([
|
||||
'client_id' => $onTicketClientId,
|
||||
'integration_code' => 'email',
|
||||
'integration_instance_id' => $instanceId,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
|
||||
$migration = require database_path(
|
||||
'migrations/2026_09_21_020000_group_pyme_rural_tenants.php'
|
||||
);
|
||||
$migration->up();
|
||||
|
||||
$pymeRuralClient = DB::table('clients')->where('code', 'pyme_rural')->sole();
|
||||
$this->assertSame('Pyme Rural', $pymeRuralClient->name);
|
||||
$this->assertSame(2, DB::table('tenants')
|
||||
->whereIn('codigo', ['fiesta_futbol_infantil', 'desfile_pura_tendencia'])
|
||||
->where('client_id', $pymeRuralClient->id)
|
||||
->count());
|
||||
$this->assertSame($onTicketClientId, DB::table('tenants')
|
||||
->where('codigo', 'onticket')
|
||||
->value('client_id'));
|
||||
|
||||
$this->assertDatabaseHas('client_integrations', [
|
||||
'client_id' => $pymeRuralClient->id,
|
||||
'integration_code' => 'email',
|
||||
'integration_instance_id' => $instanceId,
|
||||
]);
|
||||
|
||||
$migration->down();
|
||||
|
||||
$this->assertSame(2, DB::table('tenants')
|
||||
->whereIn('codigo', ['fiesta_futbol_infantil', 'desfile_pura_tendencia'])
|
||||
->where('client_id', $onTicketClientId)
|
||||
->count());
|
||||
}
|
||||
|
||||
private function createSchema(): void
|
||||
{
|
||||
Schema::create('clients', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('code')->unique();
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
});
|
||||
Schema::create('tenants', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('client_id');
|
||||
$table->string('codigo')->unique();
|
||||
});
|
||||
Schema::create('integrations', function (Blueprint $table): void {
|
||||
$table->string('integration_code')->unique();
|
||||
$table->string('name');
|
||||
});
|
||||
Schema::create('integration_instances', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('integration_code');
|
||||
$table->string('name');
|
||||
$table->longText('integration_data')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
Schema::create('client_integrations', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('client_id');
|
||||
$table->string('integration_code');
|
||||
$table->foreignId('integration_instance_id');
|
||||
$table->timestamps();
|
||||
$table->unique(['client_id', 'integration_code']);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user