some vibe tests
better than none
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\PersonTarget;
|
||||
use Tests\DatabaseTestCase;
|
||||
|
||||
class PersonTargetsTest extends DatabaseTestCase
|
||||
{
|
||||
/** @dataProvider paymentStates */
|
||||
public function test_payment_states_and_outstanding_balances($expense, $payment, $difference, $state)
|
||||
{
|
||||
$account = $expense ? $this->expenseAccount : $this->incomeAccount;
|
||||
$target = $this->target(100, $account);
|
||||
if ($payment > 0) {
|
||||
$this->booking('2020-01-15', $payment, $account, ['person_target_id' => $target->id]);
|
||||
}
|
||||
$this->assertEquals($difference, $target->difference());
|
||||
$this->assertSame($state === 'paid', $target->isPaid());
|
||||
$this->assertTrue(PersonTarget::$state()->contains('id', $target->id));
|
||||
$this->assertSame($state !== 'paid', PersonTarget::open()->contains('id', $target->id));
|
||||
$this->assertSame($difference > 0, PersonTarget::receivable()->contains('id', $target->id));
|
||||
$this->assertSame($difference < 0, PersonTarget::debt()->contains('id', $target->id));
|
||||
}
|
||||
|
||||
public function paymentStates()
|
||||
{
|
||||
return [
|
||||
'unpaid income' => [false, 0, 100, 'underpaid'],
|
||||
'partial income' => [false, 40, 60, 'underpaid'],
|
||||
'paid income' => [false, 100, 0, 'paid'],
|
||||
'overpaid income' => [false, 120, -20, 'overpaid'],
|
||||
'unpaid expense' => [true, 0, -100, 'underpaid'],
|
||||
'partial expense' => [true, 40, -60, 'underpaid'],
|
||||
'paid expense' => [true, 100, 0, 'paid'],
|
||||
'overpaid expense' => [true, 120, 20, 'overpaid'],
|
||||
];
|
||||
}
|
||||
|
||||
public function test_multiple_payments_accumulate_and_targets_page_displays_remaining_total()
|
||||
{
|
||||
$receivable = $this->target(100);
|
||||
$payable = $this->target(80, $this->expenseAccount);
|
||||
$paid = $this->target(25);
|
||||
$this->booking('2020-01-10', 30, null, ['person_target_id' => $receivable->id]);
|
||||
$this->booking('2020-01-20', 20, null, ['person_target_id' => $receivable->id]);
|
||||
$this->booking('2020-01-20', 15, $this->expenseAccount, ['person_target_id' => $payable->id]);
|
||||
$this->booking('2020-01-20', 25, null, ['person_target_id' => $paid->id]);
|
||||
$response = $this->actingAs($this->user)->get('/targets')->assertStatus(200);
|
||||
$data = $response->original->getData();
|
||||
$this->assertEquals(['receivables' => 50, 'debts' => -65], $data['sums']);
|
||||
$this->assertSame([$receivable->id], $data['personTargets']['receivables']->pluck('id')->all());
|
||||
$this->assertSame([$payable->id], $data['personTargets']['debts']->pluck('id')->all());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user