feat: add endpoint to retrieve selected bank account for a tenant and update routes with authentication
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Tests\Feature\Tenant;
|
||||
|
||||
use App\Domains\Tenant\Models\BankAccount;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Auth\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -12,6 +13,7 @@ class BankAccountControllerTest extends TestCase
|
||||
use RefreshDatabase;
|
||||
|
||||
private Tenant $tenant;
|
||||
private User $user;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
@@ -48,6 +50,9 @@ class BankAccountControllerTest extends TestCase
|
||||
'header_logo_id' => $headerAttachment->id,
|
||||
'footer_logo_id' => $footerAttachment->id,
|
||||
]);
|
||||
|
||||
$this->user = User::factory()->create();
|
||||
$this->actingAs($this->user, 'sanctum');
|
||||
}
|
||||
|
||||
public function test_it_lists_bank_accounts_for_a_tenant(): void
|
||||
@@ -195,4 +200,43 @@ class BankAccountControllerTest extends TestCase
|
||||
$this->tenant->refresh();
|
||||
$this->assertNull($this->tenant->selected_bank_account_id);
|
||||
}
|
||||
|
||||
public function test_it_gets_the_selected_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',
|
||||
]);
|
||||
|
||||
// When no bank account is selected
|
||||
$response = $this->getJson("/api/tenants/acme/bank-accounts/selected");
|
||||
$response->assertNotFound();
|
||||
|
||||
// Select the bank account
|
||||
$this->tenant->selected_bank_account_id = $account->id;
|
||||
$this->tenant->save();
|
||||
|
||||
// Get selected bank account
|
||||
$response = $this->getJson("/api/tenants/acme/bank-accounts/selected");
|
||||
$response->assertOk()
|
||||
->assertJsonPath('data.id', $account->id)
|
||||
->assertJsonPath('data.titular', 'John Doe');
|
||||
}
|
||||
|
||||
public function test_it_rejects_unauthenticated_requests(): void
|
||||
{
|
||||
$this->app['auth']->forgetGuards();
|
||||
|
||||
$response = $this->getJson("/api/tenants/acme/bank-accounts/selected");
|
||||
$response->assertStatus(401);
|
||||
|
||||
$response2 = $this->getJson("/api/tenants/acme/bank-accounts");
|
||||
$response2->assertStatus(401);
|
||||
|
||||
$response3 = $this->postJson("/api/tenants/acme/bank-accounts", []);
|
||||
$response3->assertStatus(401);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user