feat: add receipt_key validation and handling for cash account deposits and expenses

This commit is contained in:
Yoga Pangestu 2026-07-30 10:57:09 +07:00
parent ccf1611e9f
commit 5f0b62638b
2 changed files with 274 additions and 1 deletions

View File

@ -90,6 +90,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => 'Deposit test',
'receipt_key' => 'cash-transaction/deposit-001.jpg',
]);
$response
@ -108,6 +109,7 @@
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => 'Deposit test',
'receipt_key' => 'cash-transaction/deposit-001.jpg',
]);
$this->assertDatabaseCount('cash_transactions', 1);
@ -128,6 +130,7 @@
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => 'Deposit test',
'receipt_key' => 'cash-transaction/deposit-001.jpg',
]);
$this->assertDatabaseHas('cash_transactions', [
@ -144,6 +147,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => '',
'description' => 'Test',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasErrors('amount');
@ -158,6 +162,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 'abc',
'description' => 'Test',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasErrors('amount');
@ -172,6 +177,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 0,
'description' => 'Test',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasErrors('amount');
@ -186,6 +192,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 1,
'description' => 'Minimum deposit',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasNoErrors();
@ -201,6 +208,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => '',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasErrors('description');
@ -215,6 +223,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => str_repeat('a', 101),
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasErrors('description');
@ -229,6 +238,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => str_repeat('a', 100),
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasNoErrors();
@ -243,6 +253,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => '50.000',
'description' => 'Formatted deposit',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasNoErrors();
@ -258,6 +269,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 1000000000,
'description' => 'Large deposit',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasNoErrors();
@ -273,6 +285,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => -50000,
'description' => 'Negative deposit',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasErrors('amount');
@ -287,16 +300,19 @@
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 100000,
'description' => 'First deposit',
'receipt_key' => 'cash-transaction/receipt1.jpg',
]);
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 200000,
'description' => 'Second deposit',
'receipt_key' => 'cash-transaction/receipt2.jpg',
]);
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 300000,
'description' => 'Third deposit',
'receipt_key' => 'cash-transaction/receipt3.jpg',
]);
expect(CashAccount::first()->balance)->toBe(600000);
@ -312,6 +328,7 @@
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => 'First deposit',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
expect(CashAccount::first()->balance)->toBe(50000);
@ -326,11 +343,56 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => 'Deposit toast test',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertRedirect();
});
test('deposit receipt_key is required', 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' => 'Test',
]);
$response->assertSessionHasErrors('receipt_key');
});
test('deposit receipt_key max length is 500', 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' => 'Test',
'receipt_key' => str_repeat('a', 501),
]);
$response->assertSessionHasErrors('receipt_key');
});
test('deposit receipt_key exactly 500 characters is accepted', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create(['balance' => 0]);
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => 'Test',
'receipt_key' => str_repeat('a', 500),
]);
$response->assertSessionHasNoErrors();
});
/*
|--------------------------------------------------------------------------
| WITHDRAWAL
@ -346,6 +408,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 30000,
'description' => 'Withdrawal test',
'receipt_key' => 'cash-transaction/withdrawal-001.jpg',
]);
$response
@ -364,6 +427,7 @@
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 30000,
'description' => 'Withdrawal test',
'receipt_key' => 'cash-transaction/withdrawal-001.jpg',
]);
$this->assertDatabaseCount('cash_transactions', 1);
@ -384,6 +448,7 @@
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 30000,
'description' => 'Withdrawal test',
'receipt_key' => 'cash-transaction/withdrawal-001.jpg',
]);
$this->assertDatabaseHas('cash_transactions', [
@ -400,6 +465,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 100000,
'description' => 'Withdrawal test',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
// Controller catches ValidationException and flashes toast error
@ -416,6 +482,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 50000,
'description' => 'Withdrawal exact balance',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
$response->assertSessionHasNoErrors();
@ -431,6 +498,7 @@
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 100000,
'description' => 'Withdraw all',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
expect(CashAccount::first()->balance)->toBe(0);
@ -445,6 +513,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => '',
'description' => 'Test',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
$response->assertSessionHasErrors('amount');
@ -459,6 +528,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 'abc',
'description' => 'Test',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
$response->assertSessionHasErrors('amount');
@ -473,6 +543,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 0,
'description' => 'Test',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
$response->assertSessionHasErrors('amount');
@ -487,6 +558,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 50000,
'description' => '',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
$response->assertSessionHasErrors('description');
@ -501,6 +573,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 50000,
'description' => str_repeat('a', 101),
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
$response->assertSessionHasErrors('description');
@ -515,6 +588,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => '50.000',
'description' => 'Formatted withdrawal',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
$response->assertSessionHasNoErrors();
@ -530,6 +604,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => -50000,
'description' => 'Negative withdrawal',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
$response->assertSessionHasErrors('amount');
@ -544,16 +619,19 @@
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 100000,
'description' => 'First withdrawal',
'receipt_key' => 'cash-transaction/withdrawal1.jpg',
]);
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 200000,
'description' => 'Second withdrawal',
'receipt_key' => 'cash-transaction/withdrawal2.jpg',
]);
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 300000,
'description' => 'Third withdrawal',
'receipt_key' => 'cash-transaction/withdrawal3.jpg',
]);
expect(CashAccount::first()->balance)->toBe(400000);
@ -569,11 +647,56 @@
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 100000,
'description' => 'Should fail',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
$this->assertDatabaseCount('cash_transactions', 0);
});
test('withdrawal receipt_key is required', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create(['balance' => 100000]);
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 50000,
'description' => 'Test',
]);
$response->assertSessionHasErrors('receipt_key');
});
test('withdrawal receipt_key max length is 500', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create(['balance' => 100000]);
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 50000,
'description' => 'Test',
'receipt_key' => str_repeat('a', 501),
]);
$response->assertSessionHasErrors('receipt_key');
});
test('withdrawal receipt_key exactly 500 characters is accepted', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create(['balance' => 100000]);
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 50000,
'description' => 'Test',
'receipt_key' => str_repeat('a', 500),
]);
$response->assertSessionHasNoErrors();
});
/*
|--------------------------------------------------------------------------
| MIXED DEPOSIT AND WITHDRAWAL
@ -589,24 +712,28 @@
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 500000,
'description' => 'Initial deposit',
'receipt_key' => 'cash-transaction/deposit1.jpg',
]);
expect(CashAccount::first()->balance)->toBe(500000);
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 200000,
'description' => 'First withdrawal',
'receipt_key' => 'cash-transaction/withdrawal1.jpg',
]);
expect(CashAccount::first()->balance)->toBe(300000);
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 100000,
'description' => 'Second deposit',
'receipt_key' => 'cash-transaction/deposit2.jpg',
]);
expect(CashAccount::first()->balance)->toBe(400000);
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 400000,
'description' => 'Final withdrawal',
'receipt_key' => 'cash-transaction/withdrawal2.jpg',
]);
expect(CashAccount::first()->balance)->toBe(0);
@ -622,11 +749,13 @@
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 100000,
'description' => 'Deposit',
'receipt_key' => 'cash-transaction/deposit.jpg',
]);
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 80000,
'description' => 'Withdrawal',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
expect(CashAccount::first()->balance)->toBe(20000);
@ -634,6 +763,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 30000,
'description' => 'Should fail',
'receipt_key' => 'cash-transaction/withdrawal2.jpg',
]);
$response->assertRedirect();
@ -668,6 +798,7 @@
$response = $this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => 75000,
'description' => 'Updated deposit',
'receipt_key' => 'cash-transaction/deposit-updated.jpg',
]);
$response
@ -702,6 +833,7 @@
$response = $this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => 20000,
'description' => 'Updated withdrawal',
'receipt_key' => 'cash-transaction/withdrawal-updated.jpg',
]);
$response->assertSessionHasNoErrors();
@ -731,6 +863,7 @@
$response = $this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => 20000,
'description' => 'Updated expense',
'receipt_key' => 'cash-transaction/expense-updated.jpg',
]);
$response->assertRedirect();
@ -755,6 +888,7 @@
$response = $this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => 20000,
'description' => 'Updated transfer',
'receipt_key' => 'cash-transaction/transfer-updated.jpg',
]);
$response->assertRedirect();
@ -782,6 +916,7 @@
$this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => 80000,
'description' => 'Increased',
'receipt_key' => 'cash-transaction/deposit-increased.jpg',
]);
expect(CashAccount::first()->balance)->toBe(130000);
@ -808,6 +943,7 @@
$this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => 20000,
'description' => 'Decreased',
'receipt_key' => 'cash-transaction/deposit-decreased.jpg',
]);
expect(CashAccount::first()->balance)->toBe(70000);
@ -834,6 +970,7 @@
$this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => 50000,
'description' => 'Increased withdrawal',
'receipt_key' => 'cash-transaction/withdrawal-increased.jpg',
]);
expect(CashAccount::first()->balance)->toBe(80000);
@ -860,6 +997,7 @@
$this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => 10000,
'description' => 'Decreased withdrawal',
'receipt_key' => 'cash-transaction/withdrawal-decreased.jpg',
]);
expect(CashAccount::first()->balance)->toBe(120000);
@ -883,6 +1021,7 @@
$response = $this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => 0,
'description' => 'Zero amount',
'receipt_key' => 'cash-transaction/deposit.jpg',
]);
$response->assertSessionHasErrors('amount');
@ -910,12 +1049,36 @@
$response = $this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => '75.000',
'description' => 'Formatted amount',
'receipt_key' => 'cash-transaction/deposit.jpg',
]);
$response->assertSessionHasNoErrors();
expect(CashAccount::first()->balance)->toBe(125000);
});
test('transaction update requires receipt_key', function () {
$user = User::factory()->create();
$this->actingAs($user);
$cashAccount = CashAccount::factory()->create(['balance' => 100000]);
$transaction = CashTransaction::factory()->create([
'cash_account_id' => $cashAccount->id,
'created_by_id' => $user->id,
'type' => CashTransactionType::DEPOSIT,
'amount' => 50000,
'balance_after' => 100000,
'description' => 'Original',
]);
$response = $this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => 75000,
'description' => 'Updated',
]);
$response->assertSessionHasErrors('receipt_key');
});
/*
|--------------------------------------------------------------------------
| DELETE TRANSACTION
@ -1024,12 +1187,14 @@
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 100000,
'description' => 'Deposit 1',
'receipt_key' => 'cash-transaction/deposit1.jpg',
]);
$t1 = CashTransaction::latest()->first();
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => 'Deposit 2',
'receipt_key' => 'cash-transaction/deposit2.jpg',
]);
expect(CashAccount::first()->balance)->toBe(150000);
@ -1050,12 +1215,14 @@
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 50000,
'description' => 'Withdrawal 1',
'receipt_key' => 'cash-transaction/withdrawal1.jpg',
]);
$t1 = CashTransaction::latest()->first();
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 30000,
'description' => 'Withdrawal 2',
'receipt_key' => 'cash-transaction/withdrawal2.jpg',
]);
expect(CashAccount::first()->balance)->toBe(120000);
@ -1076,6 +1243,7 @@
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => 'Deposit',
'receipt_key' => 'cash-transaction/deposit.jpg',
]);
$deposit = CashTransaction::latest()->first();
@ -1083,6 +1251,7 @@
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 80000,
'description' => 'Withdrawal',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
expect(CashAccount::first()->balance)->toBe(20000);
@ -1157,6 +1326,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => 'Unauthorized',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertRedirect(route('login'));
@ -1169,6 +1339,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 50000,
'description' => 'Unauthorized',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertRedirect(route('login'));
@ -1338,11 +1509,13 @@
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 500000,
'description' => 'Modal usaha',
'receipt_key' => 'cash-transaction/deposit.jpg',
]);
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 100000,
'description' => 'Belanja inventory',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
expect(CashAccount::first()->balance)->toBe(400000);
@ -1358,16 +1531,19 @@
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 200000,
'description' => 'Penjualan pagi',
'receipt_key' => 'cash-transaction/deposit1.jpg',
]);
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 350000,
'description' => 'Penjualan siang',
'receipt_key' => 'cash-transaction/deposit2.jpg',
]);
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 150000,
'description' => 'Penjualan sore',
'receipt_key' => 'cash-transaction/deposit3.jpg',
]);
expect(CashAccount::first()->balance)->toBe(700000);
@ -1383,16 +1559,19 @@
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 50000,
'description' => 'Bayar listrik',
'receipt_key' => 'cash-transaction/withdrawal1.jpg',
]);
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 30000,
'description' => 'Bayar air',
'receipt_key' => 'cash-transaction/withdrawal2.jpg',
]);
$this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 200000,
'description' => 'Gaji karyawan',
'receipt_key' => 'cash-transaction/withdrawal3.jpg',
]);
expect(CashAccount::first()->balance)->toBe(720000);
@ -1416,6 +1595,7 @@
$response = $this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => 100000,
'description' => 'Penjualan produk A',
'receipt_key' => 'cash-transaction/deposit.jpg',
]);
$response->assertSessionHasNoErrors();
@ -1436,6 +1616,7 @@
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 100000,
'description' => 'Wrong amount',
'receipt_key' => 'cash-transaction/deposit.jpg',
]);
$wrongDeposit = CashTransaction::where('cash_account_id', $cashAccount->id)->first();
@ -1449,6 +1630,7 @@
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 150000,
'description' => 'Correct amount',
'receipt_key' => 'cash-transaction/deposit-correct.jpg',
]);
expect(CashAccount::first()->balance)->toBe(150000);
@ -1465,6 +1647,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 100000,
'description' => 'Withdraw all',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
$response->assertSessionHasNoErrors();
@ -1480,6 +1663,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 100001,
'description' => 'Over balance',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
$response->assertRedirect();
@ -1496,6 +1680,7 @@
$this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 100000,
'description' => "Deposit {$i}",
'receipt_key' => "cash-transaction/deposit{$i}.jpg",
]);
}
@ -1524,6 +1709,7 @@
$response = $this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => 20000,
'description' => 'Reduced',
'receipt_key' => 'cash-transaction/withdrawal-reduced.jpg',
]);
$response->assertSessionHasNoErrors();
@ -1551,6 +1737,7 @@
$response = $this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => 60000,
'description' => 'Increased',
'receipt_key' => 'cash-transaction/withdrawal-increased.jpg',
]);
$response->assertSessionHasNoErrors();
@ -1580,6 +1767,7 @@
$response = $this->put(route('admin.finance.cash-accounts.transactions.update', $transaction), [
'amount' => 200000,
'description' => 'Way too much',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
$response->assertRedirect();
@ -1595,6 +1783,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'description' => 'Deposit dari PT. Maju Jaya & Co.',
'receipt_key' => 'cash-transaction/deposit.jpg',
]);
$response->assertSessionHasNoErrors();
@ -1612,6 +1801,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 50000,
'description' => 'Pembayaran gaji karyawan',
'receipt_key' => 'cash-transaction/withdrawal.jpg',
]);
$response->assertSessionHasNoErrors();
@ -1628,6 +1818,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => 50000,
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasErrors('description');
@ -1641,6 +1832,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => 50000,
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasErrors('description');
@ -1655,6 +1847,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => '',
'description' => 'Test',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasErrors('amount');
@ -1669,6 +1862,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => '',
'description' => 'Test',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasErrors('amount');
@ -1683,6 +1877,7 @@
$response = $this->post(route('admin.finance.cash-accounts.deposit'), [
'amount' => '100.500',
'description' => 'Float amount',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasNoErrors();
@ -1698,6 +1893,7 @@
$response = $this->post(route('admin.finance.cash-accounts.withdrawal'), [
'amount' => '250.000',
'description' => 'Float amount',
'receipt_key' => 'cash-transaction/receipt.jpg',
]);
$response->assertSessionHasNoErrors();

View File

@ -52,6 +52,7 @@
$response = $this->post(route('admin.finance.expenses.store'), [
'amount' => 50000,
'description' => 'Pembelian ATK',
'receipt_key' => 'expense/receipt-001.jpg',
]);
$response
@ -75,6 +76,7 @@
$response = $this->post(route('admin.finance.expenses.store'), [
'amount' => '',
'description' => 'Test',
'receipt_key' => 'expense/receipt.jpg',
]);
$response->assertSessionHasErrors('amount');
@ -89,6 +91,7 @@
$response = $this->post(route('admin.finance.expenses.store'), [
'amount' => 0,
'description' => 'Test',
'receipt_key' => 'expense/receipt.jpg',
]);
$response->assertSessionHasErrors('amount');
@ -103,11 +106,26 @@
$response = $this->post(route('admin.finance.expenses.store'), [
'amount' => 50000,
'description' => '',
'receipt_key' => 'expense/receipt.jpg',
]);
$response->assertSessionHasErrors('description');
});
test('expense receipt_key is required', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create(['balance' => 100000]);
$response = $this->post(route('admin.finance.expenses.store'), [
'amount' => 50000,
'description' => 'Test',
]);
$response->assertSessionHasErrors('receipt_key');
});
test('expense fails when balance is insufficient', function () {
$user = User::factory()->create();
$this->actingAs($user);
@ -117,9 +135,11 @@
$response = $this->post(route('admin.finance.expenses.store'), [
'amount' => 100000,
'description' => 'Test',
'receipt_key' => 'expense/receipt.jpg',
]);
$response->assertSessionHasErrors('amount');
$response->assertRedirect();
expect(CashAccount::first()->balance)->toBe(50000);
});
test('expense can be updated', function () {
@ -143,6 +163,7 @@
$response = $this->put(route('admin.finance.expenses.update', $expense), [
'amount' => 40000,
'description' => 'Pembelian ATK Updated',
'receipt_key' => 'expense/receipt-updated.jpg',
]);
$response
@ -154,6 +175,32 @@
expect($expense->description)->toBe('Pembelian ATK Updated');
});
test('expense update requires receipt_key', function () {
$user = User::factory()->create();
$this->actingAs($user);
$cashAccount = CashAccount::factory()->create(['balance' => 100000]);
$cashTransaction = CashTransaction::factory()->create([
'cash_account_id' => $cashAccount->id,
'created_by_id' => $user->id,
'type' => 'expense',
'amount' => 30000,
'balance_after' => 70000,
]);
$expense = Expense::factory()->create([
'cash_transaction_id' => $cashTransaction->id,
'created_by_id' => $user->id,
'amount' => 30000,
]);
$response = $this->put(route('admin.finance.expenses.update', $expense), [
'amount' => 40000,
'description' => 'Updated',
]);
$response->assertSessionHasErrors('receipt_key');
});
test('expense can be deleted', function () {
$user = User::factory()->create();
$this->actingAs($user);
@ -181,3 +228,33 @@
$this->assertSoftDeleted('expenses', ['id' => $expense->id]);
expect(CashAccount::first()->balance)->toBe(130000);
});
test('expense receipt_key max length is 500', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create(['balance' => 100000]);
$response = $this->post(route('admin.finance.expenses.store'), [
'amount' => 50000,
'description' => 'Test',
'receipt_key' => str_repeat('a', 501),
]);
$response->assertSessionHasErrors('receipt_key');
});
test('expense receipt_key exactly 500 characters is accepted', function () {
$user = User::factory()->create();
$this->actingAs($user);
CashAccount::factory()->create(['balance' => 100000]);
$response = $this->post(route('admin.finance.expenses.store'), [
'amount' => 50000,
'description' => 'Test',
'receipt_key' => str_repeat('a', 500),
]);
$response->assertSessionHasNoErrors();
});