feat(events): associate purchases and integrations with events
This commit is contained in:
57
tests/Feature/Migrations/AddClientIdToEventsTest.php
Normal file
57
tests/Feature/Migrations/AddClientIdToEventsTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Migrations;
|
||||
|
||||
use App\Domains\Core\Client\Models\Client;
|
||||
use App\Domains\Ticketing\Event\Models\Event;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AddClientIdToEventsTest extends TestCase
|
||||
{
|
||||
public function test_event_client_overrides_the_tenant_client_when_configured(): void
|
||||
{
|
||||
Schema::create('clients', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('code');
|
||||
$table->string('name');
|
||||
});
|
||||
Schema::create('tenants', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('client_id');
|
||||
$table->string('codigo');
|
||||
});
|
||||
Schema::create('events', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('tenant_code');
|
||||
$table->string('title');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
DB::table('clients')->insert([
|
||||
['id' => 10, 'code' => 'tenant-client', 'name' => 'Tenant Client'],
|
||||
['id' => 11, 'code' => 'event-client', 'name' => 'Event Client'],
|
||||
]);
|
||||
DB::table('tenants')->insert(['id' => 20, 'client_id' => 10, 'codigo' => 'tenant']);
|
||||
DB::table('events')->insert([
|
||||
'id' => 30,
|
||||
'tenant_code' => 'tenant',
|
||||
'title' => 'Event',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$migration = require database_path('migrations/2026_09_28_000000_add_client_id_to_events.php');
|
||||
$migration->up();
|
||||
|
||||
$event = Event::query()->findOrFail(30);
|
||||
$this->assertSame(10, $event->effectiveClient()->id);
|
||||
|
||||
$event->update(['client_id' => 11]);
|
||||
|
||||
$this->assertSame(11, $event->fresh()->effectiveClient()->id);
|
||||
$this->assertTrue(Client::query()->findOrFail(11)->events()->whereKey(30)->exists());
|
||||
}
|
||||
}
|
||||
44
tests/Feature/Migrations/AddEventIdToPurchasesTest.php
Normal file
44
tests/Feature/Migrations/AddEventIdToPurchasesTest.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Migrations;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AddEventIdToPurchasesTest extends TestCase
|
||||
{
|
||||
public function test_it_backfills_the_event_from_purchase_items(): void
|
||||
{
|
||||
Schema::create('events', fn (Blueprint $table) => $table->id());
|
||||
Schema::create('compras', fn (Blueprint $table) => $table->id());
|
||||
Schema::create('catalog_items', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('event_id')->nullable();
|
||||
});
|
||||
Schema::create('compra_items', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('compra_id');
|
||||
$table->foreignId('source_catalog_item_id');
|
||||
});
|
||||
|
||||
DB::table('events')->insert([['id' => 10], ['id' => 11]]);
|
||||
DB::table('compras')->insert([['id' => 20], ['id' => 21]]);
|
||||
DB::table('catalog_items')->insert([
|
||||
['id' => 30, 'event_id' => 10],
|
||||
['id' => 31, 'event_id' => 11],
|
||||
]);
|
||||
DB::table('compra_items')->insert([
|
||||
['compra_id' => 20, 'source_catalog_item_id' => 30],
|
||||
['compra_id' => 21, 'source_catalog_item_id' => 30],
|
||||
['compra_id' => 21, 'source_catalog_item_id' => 31],
|
||||
]);
|
||||
|
||||
$migration = require database_path('migrations/2026_09_28_000100_add_event_id_to_compras.php');
|
||||
$migration->up();
|
||||
|
||||
$this->assertDatabaseHas('compras', ['id' => 20, 'event_id' => 10]);
|
||||
$this->assertDatabaseHas('compras', ['id' => 21, 'event_id' => null]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Migrations;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AssignArrufoEventToPymeRuralClientTest extends TestCase
|
||||
{
|
||||
public function test_it_assigns_only_the_arrufo_event_to_pyme_rural(): void
|
||||
{
|
||||
Schema::create('clients', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('code');
|
||||
});
|
||||
Schema::create('events', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('client_id')->nullable();
|
||||
$table->string('tenant_code');
|
||||
$table->string('title');
|
||||
});
|
||||
|
||||
DB::table('clients')->insert([
|
||||
['id' => 10, 'code' => 'pyme_rural'],
|
||||
['id' => 11, 'code' => 'onticket'],
|
||||
]);
|
||||
DB::table('events')->insert([
|
||||
[
|
||||
'id' => 20,
|
||||
'client_id' => null,
|
||||
'tenant_code' => 'onticket',
|
||||
'title' => '26.º Fiesta de la Tradición y 4.º Encuentro de Agrupaciones Gauchas',
|
||||
],
|
||||
[
|
||||
'id' => 21,
|
||||
'client_id' => 11,
|
||||
'tenant_code' => 'onticket',
|
||||
'title' => 'Otro evento',
|
||||
],
|
||||
]);
|
||||
|
||||
$migration = require database_path('migrations/2026_09_28_000200_assign_arrufo_event_to_pyme_rural_client.php');
|
||||
$migration->up();
|
||||
|
||||
$this->assertDatabaseHas('events', ['id' => 20, 'client_id' => 10]);
|
||||
$this->assertDatabaseHas('events', ['id' => 21, 'client_id' => 11]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user