feat(events): associate purchases and integrations with events
This commit is contained in:
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]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user