feat: Add tenant code to value changes; implement PurchaseController and related services for tenant-specific purchase management
This commit is contained in:
@@ -30,6 +30,13 @@ class LogsValueChangesTest extends TestCase
|
||||
$table->id();
|
||||
});
|
||||
|
||||
Schema::create('tenants', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('codigo')->unique();
|
||||
});
|
||||
|
||||
Schema::getConnection()->table('tenants')->insert(['codigo' => 'test']);
|
||||
|
||||
Schema::create('logging_test_products', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
@@ -40,12 +47,15 @@ class LogsValueChangesTest extends TestCase
|
||||
|
||||
Schema::create('compras', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('tenant_codigo');
|
||||
$table->string('status')->default(Purchase::STATUS_CREATED);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
$migration = require database_path('migrations/2026_08_03_000200_create_value_changes_table.php');
|
||||
$migration->up();
|
||||
$tenantMigration = require database_path('migrations/2026_08_04_000000_add_tenant_code_to_value_changes_table.php');
|
||||
$tenantMigration->up();
|
||||
}
|
||||
|
||||
public function test_it_creates_one_system_record_per_configured_change(): void
|
||||
@@ -64,6 +74,7 @@ class LogsValueChangesTest extends TestCase
|
||||
|
||||
$this->assertDatabaseCount('value_changes', 2);
|
||||
$this->assertDatabaseHas('value_changes', [
|
||||
'tenant_code' => 'test',
|
||||
'attribute' => 'name',
|
||||
'old_value' => 'Original',
|
||||
'new_value' => 'Updated',
|
||||
@@ -114,6 +125,7 @@ class LogsValueChangesTest extends TestCase
|
||||
public function test_purchase_logs_its_status_changes(): void
|
||||
{
|
||||
$purchase = Purchase::query()->create([
|
||||
'tenant_codigo' => 'test',
|
||||
'status' => Purchase::STATUS_CREATED,
|
||||
]);
|
||||
|
||||
@@ -122,6 +134,7 @@ class LogsValueChangesTest extends TestCase
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('value_changes', [
|
||||
'tenant_code' => 'test',
|
||||
'trackable_type' => $purchase->getMorphClass(),
|
||||
'trackable_id' => $purchase->id,
|
||||
'attribute' => 'status',
|
||||
@@ -145,4 +158,9 @@ class LoggingTestProduct extends Model
|
||||
'name',
|
||||
'price',
|
||||
];
|
||||
|
||||
protected function valueChangeTenantCode(): string
|
||||
{
|
||||
return 'test';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user