Validation for task rate

This commit is contained in:
David Bomba 2024-06-20 22:03:23 +10:00
parent 897d31f89a
commit 957556b8d0
2 changed files with 56 additions and 4 deletions

View File

@ -55,7 +55,8 @@ class StoreTaskRequest extends Request
}
$rules['hash'] = 'bail|sometimes|string|nullable';
$rules['rate'] = 'bail|numeric';
$rules['time_log'] = ['bail',function ($attribute, $values, $fail) {
if(is_string($values)) {
@ -123,6 +124,8 @@ class StoreTaskRequest extends Request
}
}
$input['rate'] = isset($input['rate']) ? $input['rate'] : 0;
if(!isset($input['time_log']) || empty($input['time_log']) || $input['time_log'] == '{}') {
$input['time_log'] = json_encode([]);
}

View File

@ -12,13 +12,14 @@
namespace Tests\Feature\Bank;
use Tests\TestCase;
use Tests\MockAccountData;
use App\Models\BankIntegration;
use App\Models\BankTransaction;
use App\Models\BankTransactionRule;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Validation\ValidationException;
use Tests\MockAccountData;
use Tests\TestCase;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class BankTransactionRuleTest extends TestCase
{
@ -38,6 +39,54 @@ class BankTransactionRuleTest extends TestCase
$this->withoutExceptionHandling();
}
public function testMatchCreditOnInvoiceNumber()
{
$bi = BankIntegration::factory()->create([
'company_id' => $this->company->id,
'user_id' => $this->user->id,
'account_id' => $this->account->id,
]);
$hash = md5(time());
$bt = BankTransaction::factory()->create([
'bank_integration_id' => $bi->id,
'company_id' => $this->company->id,
'user_id' => $this->user->id,
'description' => $hash,
'base_type' => 'CREDIT',
'amount' => 100
]);
$br = BankTransactionRule::factory()->create([
'company_id' => $this->company->id,
'user_id' => $this->user->id,
'matches_on_all' => false,
'auto_convert' => true,
'applies_to' => 'CREDIT',
'rules' => [
[
'search_key' => '$invoice.number',
'operator' => 'is',
]
]
]);
$bt = $bt->refresh();
$debit_rules = $bt->company->debit_rules();
$bt->service()->processRules();
$bt = $bt->fresh();
}
public function testMatchingWithStripos()
{
$bt_value = strtolower(str_replace(" ", "", 'hello soldier'));