feat: implement BankAccount management with CRUD operations and selection for tenants

This commit is contained in:
2026-07-03 13:43:32 -03:00
parent b94efea4e0
commit b1e40b3430
13 changed files with 497 additions and 2 deletions

View File

@@ -0,0 +1,198 @@
<?php
namespace Tests\Feature\Tenant;
use App\Domains\Tenant\Models\BankAccount;
use App\Domains\Tenant\Models\Tenant;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class BankAccountControllerTest extends TestCase
{
use RefreshDatabase;
private Tenant $tenant;
protected function setUp(): void
{
parent::setUp();
$hdrKey = (string) \Illuminate\Support\Str::uuid();
$ftrKey = (string) \Illuminate\Support\Str::uuid();
$headerAttachment = \App\Domains\Attachable\Models\Attachment::create([
'key' => $hdrKey,
'path' => 'tenants/' . $hdrKey . '.png',
'filename' => 'logo_header.png',
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
'mime_type' => 'image/png',
]);
$footerAttachment = \App\Domains\Attachable\Models\Attachment::create([
'key' => $ftrKey,
'path' => 'tenants/' . $ftrKey . '.png',
'filename' => 'logo_footer.png',
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
'mime_type' => 'image/png',
]);
$this->tenant = Tenant::create([
'codigo' => 'acme',
'nombre' => 'Acme',
'dominio' => 'acme.com',
'primary_color' => '#ff0000',
'secondary_color' => '#00ff00',
'danger_color' => '#0000ff',
'success_color' => '#00ff00',
'header_bg_color' => '#ffffff',
'footer_bg_color' => '#ffffff',
'header_logo_id' => $headerAttachment->id,
'footer_logo_id' => $footerAttachment->id,
]);
}
public function test_it_lists_bank_accounts_for_a_tenant(): void
{
BankAccount::query()->create([
'tenant_code' => 'acme',
'titular' => 'John Doe',
'entidad' => 'Banco Galicia',
'alias' => 'john.doe.galicia',
'cvu' => '1234567890123456789012',
]);
$response = $this->getJson("/api/tenants/acme/bank-accounts");
$response->assertOk()
->assertJsonCount(1, 'data')
->assertJsonPath('data.0.titular', 'John Doe');
}
public function test_it_creates_a_bank_account_for_a_tenant(): void
{
$response = $this->postJson("/api/tenants/acme/bank-accounts", [
'titular' => 'Jane Doe',
'entidad' => 'Banco Nación',
'alias' => 'jane.doe.nacion',
'cvu' => '9876543210987654321098',
]);
$response->assertCreated()
->assertJsonPath('data.titular', 'Jane Doe');
$this->assertDatabaseHas('bank_accounts', [
'tenant_code' => 'acme',
'titular' => 'Jane Doe',
]);
}
public function test_it_shows_a_bank_account(): void
{
$account = BankAccount::query()->create([
'tenant_code' => 'acme',
'titular' => 'John Doe',
'entidad' => 'Banco Galicia',
'alias' => 'john.doe.galicia',
'cvu' => '1234567890123456789012',
]);
$response = $this->getJson("/api/tenants/acme/bank-accounts/{$account->id}");
$response->assertOk()
->assertJsonPath('data.titular', 'John Doe');
}
public function test_it_updates_a_bank_account(): void
{
$account = BankAccount::query()->create([
'tenant_code' => 'acme',
'titular' => 'John Doe',
'entidad' => 'Banco Galicia',
'alias' => 'john.doe.galicia',
'cvu' => '1234567890123456789012',
]);
$response = $this->putJson("/api/tenants/acme/bank-accounts/{$account->id}", [
'titular' => 'John Doe Updated',
]);
$response->assertOk()
->assertJsonPath('data.titular', 'John Doe Updated');
$this->assertDatabaseHas('bank_accounts', [
'id' => $account->id,
'titular' => 'John Doe Updated',
]);
}
public function test_it_deletes_a_bank_account(): void
{
$account = BankAccount::query()->create([
'tenant_code' => 'acme',
'titular' => 'John Doe',
'entidad' => 'Banco Galicia',
'alias' => 'john.doe.galicia',
'cvu' => '1234567890123456789012',
]);
$response = $this->deleteJson("/api/tenants/acme/bank-accounts/{$account->id}");
$response->assertNoContent();
$this->assertDatabaseMissing('bank_accounts', ['id' => $account->id]);
}
public function test_it_selects_a_bank_account_for_a_tenant(): void
{
$account = BankAccount::query()->create([
'tenant_code' => 'acme',
'titular' => 'John Doe',
'entidad' => 'Banco Galicia',
'alias' => 'john.doe.galicia',
'cvu' => '1234567890123456789012',
]);
$response = $this->postJson("/api/tenants/acme/bank-accounts/{$account->id}/select");
$response->assertOk()
->assertJsonPath('data.selected_bank_account_id', $account->id);
$this->tenant->refresh();
$this->assertEquals($account->id, $this->tenant->selected_bank_account_id);
}
public function test_it_deletes_related_bank_accounts_when_tenant_is_deleted(): void
{
$account = BankAccount::query()->create([
'tenant_code' => 'acme',
'titular' => 'John Doe',
'entidad' => 'Banco Galicia',
'alias' => 'john.doe.galicia',
'cvu' => '1234567890123456789012',
]);
$this->assertDatabaseHas('bank_accounts', ['id' => $account->id]);
$this->tenant->delete();
$this->assertDatabaseMissing('bank_accounts', ['id' => $account->id]);
}
public function test_it_sets_selected_bank_account_id_to_null_when_selected_bank_account_is_deleted(): void
{
$account = BankAccount::query()->create([
'tenant_code' => 'acme',
'titular' => 'John Doe',
'entidad' => 'Banco Galicia',
'alias' => 'john.doe.galicia',
'cvu' => '1234567890123456789012',
]);
$this->tenant->selected_bank_account_id = $account->id;
$this->tenant->save();
$account->delete();
$this->tenant->refresh();
$this->assertNull($this->tenant->selected_bank_account_id);
}
}