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'); });