mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 15:14:35 -04:00
Match Bank Transactions validation
This commit is contained in:
parent
0f3893a6ab
commit
7e7f5395f8
@ -547,7 +547,7 @@ class BankTransactionController extends BaseController
|
|||||||
public function match(MatchBankTransactionRequest $request)
|
public function match(MatchBankTransactionRequest $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
return response()->json(['message' => 'Processing....'], 200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,4 +25,25 @@ class MatchBankTransactionRequest extends Request
|
|||||||
{
|
{
|
||||||
return auth()->user()->isAdmin();
|
return auth()->user()->isAdmin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
|
||||||
|
return [
|
||||||
|
'*.id' => 'required|bail',
|
||||||
|
'*.invoice_id' => 'nullable|sometimes',
|
||||||
|
'*.expense_id' => 'nullable|sometimes'
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepareForValidation()
|
||||||
|
{
|
||||||
|
$input = $this->all();
|
||||||
|
|
||||||
|
$input = $this->decodePrimaryKeys($input);
|
||||||
|
|
||||||
|
$this->replace($input);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,10 @@ class Request extends FormRequest
|
|||||||
$input['invoice_id'] = $this->decodePrimaryKey($input['invoice_id']);
|
$input['invoice_id'] = $this->decodePrimaryKey($input['invoice_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('expense_id', $input) && is_string($input['expense_id'])) {
|
||||||
|
$input['expense_id'] = $this->decodePrimaryKey($input['expense_id']);
|
||||||
|
}
|
||||||
|
|
||||||
if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
|
if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
|
||||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||||
}
|
}
|
||||||
|
67
tests/Feature/Bank/BankTransactionTest.php
Normal file
67
tests/Feature/Bank/BankTransactionTest.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\Feature\Bank;
|
||||||
|
|
||||||
|
use App\Models\BankTransaction;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Tests\MockAccountData;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class BankTransactionTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
use DatabaseTransactions;
|
||||||
|
use MockAccountData;
|
||||||
|
|
||||||
|
protected function setUp() :void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->makeTestData();
|
||||||
|
|
||||||
|
$this->withoutMiddleware(
|
||||||
|
ThrottleRequests::class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMatchBankTransactionsValidationShouldFail()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
['bad_key' => 10],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/bank_transactions/match', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(422);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testMatchBankTransactionValidationShouldPass()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
['id' => 'Wpmbk5ezJn'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/bank_transactions/match', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user