fix: quantity validation should not count current transaction
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Models\Holding;
|
||||
use App\Models\Portfolio;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use App\Rules\QuantityValidationRule;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class TransactionsTest extends TestCase
|
||||
@@ -69,4 +70,22 @@ class TransactionsTest extends TestCase
|
||||
0.01
|
||||
);
|
||||
}
|
||||
|
||||
public function test_cannot_sell_more_than_owned(): void
|
||||
{
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
$portfolio = Portfolio::factory()->create();
|
||||
|
||||
Transaction::factory(5)->buy()->lastYear()->portfolio($portfolio->id)->symbol('AAPL')->create();
|
||||
$sale_transaction = Transaction::factory()->sell(6)->lastMonth()->portfolio($portfolio->id)->symbol('AAPL')->make();
|
||||
|
||||
$rule = new QuantityValidationRule($portfolio, $sale_transaction->symbol, 'SELL', $sale_transaction->date, $sale_transaction);
|
||||
|
||||
$rule->validate('quantity', $sale_transaction->quantity, function () {
|
||||
$this->assertFalse(false, 'Not permitted to sell more than owned.');
|
||||
});
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user