Make bank selection optional when creating or updating accounts (#261)
## Summary - Makes `bank_id` nullable for all account types in both `StoreAccountRequest` and `UpdateAccountRequest` (previously it was only nullable for real estate) - Shows the bank combobox field for all account types in the `AccountForm` component, including real estate - Removes the `required` attribute from the hidden bank input and the logic that cleared bank selection when switching to real estate type ## Test changes - Updated "validates required fields" test to no longer expect `bank_id` as a required field - Added "can create a new account without a bank" test in `AccountTest` - Updated `RealEstateTest` to verify non-real-estate accounts can also be created without a bank (was previously asserting the opposite)
This commit is contained in:
parent
6ce5b123ce
commit
3990472249
|
|
@ -39,9 +39,7 @@ class StoreAccountRequest extends FormRequest
|
|||
|
||||
$rules = [
|
||||
'name' => ['required', 'string'],
|
||||
'bank_id' => $isRealEstate
|
||||
? ['nullable', 'exists:banks,id']
|
||||
: ['required', 'exists:banks,id'],
|
||||
'bank_id' => ['nullable', 'exists:banks,id'],
|
||||
'currency_code' => [
|
||||
'required',
|
||||
'string',
|
||||
|
|
|
|||
|
|
@ -31,9 +31,7 @@ class UpdateAccountRequest extends FormRequest
|
|||
|
||||
$rules = [
|
||||
'name' => ['required', 'string'],
|
||||
'bank_id' => $isRealEstate
|
||||
? ['nullable', 'exists:banks,id']
|
||||
: ['required', 'exists:banks,id'],
|
||||
'bank_id' => ['nullable', 'exists:banks,id'],
|
||||
'currency_code' => [
|
||||
'required',
|
||||
'string',
|
||||
|
|
|
|||
|
|
@ -294,7 +294,6 @@ export function AccountForm({
|
|||
type="hidden"
|
||||
name="bank_id"
|
||||
value={selectedBankId ?? ''}
|
||||
required
|
||||
/>
|
||||
|
||||
<BankCombobox
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ it('does not require property_type for non-real-estate accounts', function () {
|
|||
$response->assertRedirect();
|
||||
});
|
||||
|
||||
it('requires bank_id for non-real-estate account types', function () {
|
||||
it('does not require bank_id for non-real-estate account types', function () {
|
||||
actingAs($this->user);
|
||||
|
||||
$data = [
|
||||
|
|
@ -222,7 +222,7 @@ it('requires bank_id for non-real-estate account types', function () {
|
|||
|
||||
$response = $this->post(route('accounts.store'), $data);
|
||||
|
||||
$response->assertSessionHasErrors(['bank_id']);
|
||||
$response->assertSessionMissing('errors');
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -55,12 +55,33 @@ it('can create a new account with plaintext name', function () {
|
|||
]);
|
||||
});
|
||||
|
||||
it('can create a new account without a bank', function () {
|
||||
actingAs($this->user);
|
||||
|
||||
$data = [
|
||||
'name' => 'My Savings Account',
|
||||
'currency_code' => 'USD',
|
||||
'type' => AccountType::Savings->value,
|
||||
];
|
||||
|
||||
$response = $this->post(route('accounts.store'), $data);
|
||||
|
||||
$response->assertRedirect();
|
||||
assertDatabaseHas('accounts', [
|
||||
'user_id' => $this->user->id,
|
||||
'bank_id' => null,
|
||||
'name' => 'My Savings Account',
|
||||
'currency_code' => 'USD',
|
||||
'type' => AccountType::Savings->value,
|
||||
]);
|
||||
});
|
||||
|
||||
it('validates required fields when creating account', function () {
|
||||
actingAs($this->user);
|
||||
|
||||
$response = $this->post(route('accounts.store'), []);
|
||||
|
||||
$response->assertSessionHasErrors(['name', 'bank_id', 'currency_code', 'type']);
|
||||
$response->assertSessionHasErrors(['name', 'currency_code', 'type']);
|
||||
});
|
||||
|
||||
it('validates currency_code must be in allowed list', function () {
|
||||
|
|
|
|||
Loading…
Reference in New Issue