Merge pull request #2340 from sevannerse/CU-1xphe64_Negative-Item-quantity_Sevan-Nerse

negative quantity not allowed #1xphe64
This commit is contained in:
Denis Duliçi 2021-12-28 11:13:50 +02:00 committed by GitHub
commit faa8eef8c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 1 deletions

View File

@ -75,7 +75,7 @@ class Document extends FormRequest
$size = 7;
}
$rules['items.' . $key . '.quantity'] = 'required|max:' . $size;
$rules['items.' . $key . '.quantity'] = 'required|max:' . $size . '|numeric|gt:0';
$this->items_quantity_size[$key] = $size;
}
}
@ -108,6 +108,7 @@ class Document extends FormRequest
if ($this->items_quantity_size) {
foreach ($this->items_quantity_size as $key => $quantity_size) {
$messages['items.' . $key . '.quantity.max'] = trans('validation.size', ['attribute' => Str::lower(trans('invoices.quantity')), 'size' => $quantity_size]);
$messages['items.' . $key . '.quantity.gt'] = trans('validation.gt.numeric', ['attribute' => Str::lower(trans('invoices.quantity')), 'value' => 0]);
}
}

View File

@ -112,6 +112,24 @@ class BillsTest extends FeatureTestCase
]);
}
public function testItShouldNotCreateBillWithNegativeQuantity()
{
$request = $this->getRequest();
$request['items'][0]['quantity'] = '-1';
$this->handleValidationExceptions();
$this->loginAs()
->post(route('bills.store'), $request)
->assertRedirect()
->assertInvalid(['items.0.quantity']);
$this->assertDatabaseMissing('documents', [
'document_number' => $request['document_number'],
]);
}
public function testItShouldSeeBillUpdatePage()
{
$request = $this->getRequest();

View File

@ -123,6 +123,24 @@ class InvoicesTest extends FeatureTestCase
]);
}
public function testItShouldNotCreateInvoiceWithNegativeQuantity()
{
$request = $this->getRequest();
$request['items'][0]['quantity'] = '-1';
$this->handleValidationExceptions();
$this->loginAs()
->post(route('invoices.store'), $request)
->assertRedirect()
->assertInvalid(['items.0.quantity']);
$this->assertDatabaseMissing('documents', [
'document_number' => $request['document_number'],
]);
}
public function testItShouldSeeInvoiceUpdatePage()
{
$request = $this->getRequest();