dstpabuaran.com/tests/Feature/Admin/Finance/CashAccountTest.php
Yoga Pangestu c3d8ea2f66 feat: implement cash account management with deposit and withdrawal functionality
- Introduced CashAccountController for managing cash accounts.
- Created CashTransactionRequest and CashAccountRequest for transaction validation.
- Developed CashAccountService to handle business logic for cash transactions.
- Added UI components for cash account management, including deposit and withdrawal dialogs.
- Implemented data tables for displaying transactions and cash account details.
- Updated routes to include cash account management endpoints.
- Added tests for cash account functionality, including deposit and withdrawal operations.
2026-07-29 02:08:39 +07:00

154 lines
4.2 KiB
PHP

<?php
use App\Models\CashAccount;
use App\Models\User;
use Inertia\Testing\AssertableInertia as Assert;
test('guests are redirected to the login page', function () {
$response = $this->get(route('admin.finance.cash-accounts.index'));
$response->assertRedirect(route('login'));
});
test('authenticated users can visit the cash account index page', function () {
$user = User::factory()->create();
$this->actingAs($user);
$response = $this->get(route('admin.finance.cash-accounts.index'));
$response->assertOk();
});
test('cash account index page displays cash account and transactions', function () {
$user = User::factory()->create();
$this->actingAs($user);
$cashAccount = CashAccount::factory()->create(['balance' => 500000]);
$response = $this->get(route('admin.finance.cash-accounts.index'));
$response->assertOk();
$response->assertInertia(fn (Assert $page) => $page
->component('admin/finance/cash-account/index')
->has('cashAccount')
->has('transactions')
);
});
test('deposit can be made', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create(['balance' => 100000]);
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => 'Deposit test',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect(route('admin.finance.cash-accounts.index'));
expect(CashAccount::first()->balance)->toBe(150000);
});
test('deposit amount is required', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create();
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => '',
'description' => 'Test',
]);
$response->assertSessionHasErrors('amount');
});
test('deposit amount must be at least 1', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create();
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 0,
'description' => 'Test',
]);
$response->assertSessionHasErrors('amount');
});
test('deposit description is required', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create();
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => '',
]);
$response->assertSessionHasErrors('description');
});
test('withdrawal can be made', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create(['balance' => 100000]);
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 30000,
'description' => 'Withdrawal test',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect(route('admin.finance.cash-accounts.index'));
expect(CashAccount::first()->balance)->toBe(70000);
});
test('withdrawal fails when balance is insufficient', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create(['balance' => 50000]);
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 100000,
'description' => 'Withdrawal test',
]);
$response->assertSessionHasErrors('amount');
});
test('withdrawal amount is required', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create();
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => '',
'description' => 'Test',
]);
$response->assertSessionHasErrors('amount');
});
test('withdrawal description is required', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create();
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 50000,
'description' => '',
]);
$response->assertSessionHasErrors('description');
});