1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

Fixes for validation tests

This commit is contained in:
David Bomba 2024-11-02 13:37:15 +11:00
parent 2ec9d31212
commit 6d93b98016
6 changed files with 803 additions and 62 deletions

View File

@ -38,40 +38,48 @@ class UpdateEInvoiceConfiguration extends Request
public function rules()
{
/** @var \App\Models\User $user */
$user = auth()->user();
return [
'entity' => 'required|bail|in:invoice,client,company',
'payment_means' => 'sometimes|bail|array',
'payment_means.code' => ['required_with:payment_means', 'bail', Rule::in(PaymentMeans::getPaymentMeansCodelist())],
'payment_means.bic' => ['bail',
'payment_means.bic_swift' => ['bail',
Rule::requiredIf(function () {
return in_array($this->input('payment_means.code'), ['58', '59', '49', '42', '30']);
$code = $this->input('payment_means.code');
$requirements = PaymentMeans::$payment_means_requirements_codes[$code] ?? [];
return in_array('bic_swift', $requirements);
}),
],
'payment_means.iban' => ['bail', 'string', 'min:8', 'max:11',
Rule::requiredIf(function () {
return in_array($this->input('payment_means.code'), ['58', '59', '49', '42', '30']);
$code = $this->input('payment_means.code');
$requirements = PaymentMeans::$payment_means_requirements_codes[$code] ?? [];
return in_array('iban', $requirements);
}),
],
'payment_means.account_name' => ['bail', 'string', 'min:15', 'max:34',
'payment_means.account_holder' => ['bail', 'string', 'min:15', 'max:34',
Rule::requiredIf(function () {
return in_array($this->input('payment_means.code'), ['58', '59', '49', '42', '30']);
$code = $this->input('payment_means.code');
$requirements = PaymentMeans::$payment_means_requirements_codes[$code] ?? [];
return in_array('account_holder', $requirements);
}),
],
'payment_means.information' => ['bail', 'sometimes', 'string'],
'payment_means.card_type' => ['bail', 'string', 'min:4',
Rule::requiredIf(function () {
return in_array($this->input('payment_means.code'), ['48']);
$code = $this->input('payment_means.code');
$requirements = PaymentMeans::$payment_means_requirements_codes[$code] ?? [];
return in_array('card_type', $requirements);
}),
],
'payment_means.cardholder_name' => ['bail','string', 'min:4',
'payment_means.card_holder' => ['bail','string', 'min:4',
Rule::requiredIf(function () {
return in_array($this->input('payment_means.code'), ['48']);
$code = $this->input('payment_means.code');
$requirements = PaymentMeans::$payment_means_requirements_codes[$code] ?? [];
return in_array('card_holder', $requirements);
}),
],
];
}
public function prepareForValidation()

View File

@ -102,6 +102,538 @@ class PaymentMeans implements PaymentMeansInterface
'ZZZ' => 'Mutually defined',
];
public static array $payment_means_requirements = [
'1' => [], // Instrument not defined
'2' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH credit
'3' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH debit
'4' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH demand debit reversal
'5' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH demand credit reversal
'6' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH demand credit
'7' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH demand debit
'8' => [], // Hold
'9' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // National or regional clearing
'10' => [], // In cash
'11' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH savings credit reversal
'12' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH savings debit reversal
'13' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH savings credit
'14' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH savings debit
'15' => [
'PayeeFinancialAccount.Name',
'PayeeFinancialAccount.ProprietaryID'
], // Bookentry credit
'16' => [
'PayeeFinancialAccount.Name',
'PayeeFinancialAccount.ProprietaryID'
], // Bookentry debit
'17' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH demand CCD credit
'18' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH demand CCD debit
'19' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH demand CTP credit
'20' => [], // Cheque
'21' => [], // Banker's draft
'22' => [], // Certified banker's draft
'23' => [], // Bank cheque
'24' => [], // Bill of exchange awaiting acceptance
'25' => [], // Certified cheque
'26' => [], // Local cheque
'27' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH demand CTP debit
'28' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH demand CTX credit
'29' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH demand CTX debit
'30' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Credit transfer
'31' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Debit transfer
'32' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH demand CCD+ credit
'33' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH demand CCD+ debit
'34' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH PPD
'35' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH savings CCD credit
'36' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH savings CCD debit
'37' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH savings CTP credit
'38' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH savings CTP debit
'39' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH savings CTX credit
'40' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH savings CTX debit
'41' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH savings CCD+ credit
'42' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Payment to bank account
'43' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // ACH savings CCD+ debit
'44' => [], // Accepted bill of exchange
'45' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Referenced home-banking credit transfer
'46' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Interbank debit transfer
'47' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Home-banking debit transfer
'48' => [
'PayeeFinancialAccount.NetworkID',
'PayeeFinancialAccount.ID'
], // Bank card
'49' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Direct debit
'50' => [
'PayeeFinancialAccount.Name'
], // Payment by postgiro
'51' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // FR, norme 6 97-Telereglement CFONB
'52' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Urgent commercial payment
'53' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Urgent Treasury Payment
'54' => [
'CardAccount.NetworkID',
'CardAccount.PrimaryAccountNumberID',
'CardAccount.HolderName'
], // Credit card
'55' => [
'CardAccount.NetworkID',
'CardAccount.PrimaryAccountNumberID',
'CardAccount.HolderName'
], // Debit card
'56' => [
'PayeeFinancialAccount.Name'
], // Bankgiro
'57' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Standing agreement
'58' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // SEPA credit transfer
'59' => [
'PaymentMandate.PayerFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // SEPA direct debit
'60' => [], // Promissory note
'61' => [], // Promissory note signed by debtor
'62' => [
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Promissory note signed by debtor and endorsed by bank
'63' => [], // Promissory note signed by debtor and endorsed
'64' => [
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Promissory note signed by bank
'65' => [
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Promissory note signed by bank and endorsed by another
'66' => [], // Promissory note signed by third party
'67' => [
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Promissory note signed by third party and endorsed by bank
'68' => [
'PayeeFinancialAccount.ID'
], // Online payment service
'69' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Transfer Advice
'70' => [], // Bill drawn by creditor on debtor
'74' => [
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Bill drawn by creditor on bank
'75' => [
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Bill drawn by creditor, endorsed by bank
'76' => [
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Bill drawn by creditor on bank and endorsed
'77' => [], // Bill drawn by creditor on third party
'78' => [], // Bill drawn by creditor on third party, accepted
'91' => [], // Not transferable banker's draft
'92' => [], // Not transferable local cheque
'93' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Reference giro
'94' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Urgent giro
'95' => [
'PayeeFinancialAccount.ID',
'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID'
], // Free format giro
'96' => [], // Requested method not used
'97' => [
'PayeeFinancialAccount.Name'
], // Clearing between partners
'ZZZ' => [], // Mutually defined
];
public static array $payment_means_requirements_codes = [
'1' => [], // Instrument not defined
'2' => [
'iban',
'bic_swift'
], // ACH credit
'3' => [
'payer_bank_account',
'bic_swift'
], // ACH debit
'4' => [
'payer_bank_account',
'bic_swift'
], // ACH demand debit reversal
'5' => [
'iban',
'bic_swift'
], // ACH demand credit reversal
'6' => [
'iban',
'bic_swift'
], // ACH demand credit
'7' => [
'payer_bank_account',
'bic_swift'
], // ACH demand debit
'8' => [], // Hold
'9' => [
'iban',
'bic_swift'
], // National or regional clearing
'10' => [], // In cash
'11' => [
'iban',
'bic_swift'
], // ACH savings credit reversal
'12' => [
'payer_bank_account',
'bic_swift'
], // ACH savings debit reversal
'13' => [
'iban',
'bic_swift'
], // ACH savings credit
'14' => [
'payer_bank_account',
'bic_swift'
], // ACH savings debit
'15' => [
'account_holder',
'bsb_sort'
], // Bookentry credit
'16' => [
'account_holder',
'bsb_sort'
], // Bookentry debit
'17' => [
'iban',
'bic_swift'
], // ACH demand CCD credit
'18' => [
'payer_bank_account',
'bic_swift'
], // ACH demand CCD debit
'19' => [
'iban',
'bic_swift'
], // ACH demand CTP credit
'20' => [], // Cheque
'21' => [], // Banker's draft
'22' => [], // Certified banker's draft
'23' => [], // Bank cheque
'24' => [], // Bill of exchange awaiting acceptance
'25' => [], // Certified cheque
'26' => [], // Local cheque
'27' => [
'payer_bank_account',
'bic_swift'
], // ACH demand CTP debit
'28' => [
'iban',
'bic_swift'
], // ACH demand CTX credit
'29' => [
'payer_bank_account',
'bic_swift'
], // ACH demand CTX debit
'30' => [
'iban',
'bic_swift'
], // Credit transfer
'31' => [
'iban',
'bic_swift'
], // Debit transfer
'32' => [
'iban',
'bic_swift'
], // ACH demand CCD+ credit
'33' => [
'payer_bank_account',
'bic_swift'
], // ACH demand CCD+ debit
'34' => [
'iban',
'bic_swift'
], // ACH PPD
'35' => [
'iban',
'bic_swift'
], // ACH savings CCD credit
'36' => [
'payer_bank_account',
'bic_swift'
], // ACH savings CCD debit
'37' => [
'iban',
'bic_swift'
], // ACH savings CTP credit
'38' => [
'payer_bank_account',
'bic_swift'
], // ACH savings CTP debit
'39' => [
'iban',
'bic_swift'
], // ACH savings CTX credit
'40' => [
'payer_bank_account',
'bic_swift'
], // ACH savings CTX debit
'41' => [
'iban',
'bic_swift'
], // ACH savings CCD+ credit
'42' => [
'iban',
'bic_swift'
], // Payment to bank account
'43' => [
'payer_bank_account',
'bic_swift'
], // ACH savings CCD+ debit
'44' => [], // Accepted bill of exchange
'45' => [
'iban',
'bic_swift'
], // Referenced home-banking credit transfer
'46' => [
'iban',
'bic_swift'
], // Interbank debit transfer
'47' => [
'iban',
'bic_swift'
], // Home-banking debit transfer
'48' => [
'card_type',
'iban'
], // Bank card
'49' => [
'payer_bank_account',
'bic_swift'
], // Direct debit
'50' => [
'account_holder'
], // Payment by postgiro
'51' => [
'iban',
'bic_swift'
], // FR, norme 6 97-Telereglement CFONB
'52' => [
'iban',
'bic_swift'
], // Urgent commercial payment
'53' => [
'iban',
'bic_swift'
], // Urgent Treasury Payment
'54' => [
'card_type',
'card_number',
'card_holder'
], // Credit card
'55' => [
'card_type',
'card_number',
'card_holder'
], // Debit card
'56' => [
'account_holder'
], // Bankgiro
'57' => [
'iban',
'bic_swift'
], // Standing agreement
'58' => [
'iban',
'bic_swift'
], // SEPA credit transfer
'59' => [
'payer_bank_account',
'bic_swift'
], // SEPA direct debit
'60' => [], // Promissory note
'61' => [], // Promissory note signed by debtor
'62' => [
'bic_swift'
], // Promissory note signed by debtor and endorsed by bank
'63' => [], // Promissory note signed by debtor and endorsed
'64' => [
'bic_swift'
], // Promissory note signed by bank
'65' => [
'bic_swift'
], // Promissory note signed by bank and endorsed by another
'66' => [], // Promissory note signed by third party
'67' => [
'bic_swift'
], // Promissory note signed by third party and endorsed by bank
'68' => [
'iban'
], // Online payment service
'69' => [
'iban',
'bic_swift'
], // Transfer Advice
'70' => [], // Bill drawn by creditor on debtor
'74' => [
'bic_swift'
], // Bill drawn by creditor on bank
'75' => [
'bic_swift'
], // Bill drawn by creditor, endorsed by bank
'76' => [
'bic_swift'
], // Bill drawn by creditor on bank and endorsed
'77' => [], // Bill drawn by creditor on third party
'78' => [], // Bill drawn by creditor on third party, accepted
'91' => [], // Not transferable banker's draft
'92' => [], // Not transferable local cheque
'93' => [
'iban',
'bic_swift'
], // Reference giro
'94' => [
'iban',
'bic_swift'
], // Urgent giro
'95' => [
'iban',
'bic_swift'
], // Free format giro
'96' => [], // Requested method not used
'97' => [
'account_holder'
], // Clearing between partners
'ZZZ' => [], // Mutually defined
];
public static array $payment_means_field_map = [
'iban' => 'PayeeFinancialAccount.ID',
'bic_swift' => 'PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID',
'payer_bank_account' => 'PaymentMandate.PayerFinancialAccount.ID',
'account_holder' => 'PayeeFinancialAccount.Name',
'bsb_sort' => 'PayeeFinancialAccount.ProprietaryID',
'card_type' => 'CardAccount.NetworkID',
'card_number' => 'CardAccount.PrimaryAccountNumberID',
'card_holder' => 'CardAccount.HolderName'
];
public string $code = '1';
public ?string $information = null;
@ -197,6 +729,6 @@ class PaymentMeans implements PaymentMeansInterface
public static function getPaymentMeansCodelist()
{
return array_keys(self::$payment_means_codelist);
return array_keys(self::$payment_means_requirements_codes);
}
}

View File

@ -5403,8 +5403,19 @@ $lang = array(
'payment_updated' => 'Payment Updated',
'search_placeholder' => 'Find invoices, clients, and more',
'invalid_vat_number' => "The VAT number is not valid for the selected country. Format should be Country Code followed by number only ie, DE123456789",
'acts_as_sender' => 'Acts as Sender',
'acts_as_receiver' => 'Acts as Receiver',
'acts_as_sender' => 'Send E Documents',
'acts_as_receiver' => 'Receive E Documents',
'iban_help' => 'The full IBAN number',
'bic_swift' => 'BIC/Swift code',
'bic_swift_help' => 'The Bank identifer',
'payer_bank_account' => 'Payer Bank Account Number',
'payer_bank_account_help' => 'The bank account number of the payer',
'bsb_sort' => 'BSB / Sort Code',
'bsb_sort_help' => 'Bank Branch Code',
'card_type' => 'Card Type',
'card_type_help' => 'ie. VISA, AMEX',
'card_number_help' => 'last 4 digits only',
'card_holder' => 'Card Holder Name',
);
return $lang;

View File

@ -0,0 +1,183 @@
<?php
namespace Tests\Feature\EInvoice\RequestValidation;
use App\Http\Requests\EInvoice\UpdateEInvoiceConfiguration;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Tests\TestCase;
use Illuminate\Support\Facades\Validator;
class UpdateEInvoiceConfigurationTest extends TestCase
{
protected UpdateEInvoiceConfiguration $request;
protected function setUp(): void
{
parent::setUp();
$this->withoutMiddleware(
ThrottleRequests::class
);
$this->request = new UpdateEInvoiceConfiguration();
}
public function testConfigValidationFails()
{
$data = [
'entddity' => 'invoice',
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertFalse($validator->passes());
}
public function testConfigValidation()
{
$data = [
'entity' => 'invoice',
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertTrue($validator->passes());
}
public function testConfigValidationInvalidcode()
{
$data = [
'entity' => 'invoice',
'payment_means' => [
'code' => 'invalidcodehere'
]
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertFalse($validator->passes());
}
public function testValidatesPaymentMeansForBankTransfer()
{
$data = [
'entity' => 'invoice',
'payment_means' => [
'code' => '30',
'iban' => '12345678',
'bic_swift' => 'DEUTDEFF',
'account_holder' => 'John Doe Company Limited'
]
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertTrue($validator->passes());
}
public function testValidatesPaymentMeansForCardPayment()
{
$data = [
'entity' => 'invoice',
'payment_means' => [
'code' => '48',
'card_type' => 'VISA',
'iban' => '12345678'
]
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertTrue($validator->passes());
}
public function testValidatesPaymentMeansForCreditCard()
{
$data = [
'entity' => 'invoice',
'payment_means' => [
'code' => '54',
'card_type' => 'VISA',
'card_number' => '************1234',
'card_holder' => 'John Doe'
]
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertTrue($validator->passes());
}
public function testFailsValidationWhenRequiredFieldsAreMissing()
{
$data = [
'entity' => 'invoice',
'payment_means' => [
'code' => '30',
]
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertFalse($validator->passes());
$this->assertTrue($validator->errors()->has('payment_means.iban'));
$this->assertTrue($validator->errors()->has('payment_means.bic_swift'));
}
public function testFailsValidationWithInvalidPaymentMeansCode()
{
$data = [
'entity' => 'invoice',
'payment_means' => [
'code' => '999',
]
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertFalse($validator->passes());
$this->assertTrue($validator->errors()->has('payment_means.code'));
}
public function testValidatesPaymentMeansForDirectDebit()
{
$data = [
'entity' => 'invoice',
'payment_means' => [
'code' => '49',
'payer_bank_account' => '12345678',
'bic_swift' => 'DEUTDEFF'
]
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertTrue($validator->passes());
}
public function testValidatesPaymentMeansForBookEntry()
{
$data = [
'entity' => 'invoice',
'payment_means' => [
'code' => '15',
'account_holder' => 'John Doe Company Limited',
'bsb_sort' => '123456'
]
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertTrue($validator->passes());
}
}

View File

@ -48,20 +48,26 @@ class AddTaxIdentifierRequestTest extends TestCase
public function testValidInput()
{
$validator = Validator::make([
$data = [
'country' => 'DE',
'vat_number' => 'DE123456789',
], $this->request->rules());
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertTrue($validator->passes());
}
public function testInvalidCountry()
{
$validator = Validator::make([
$data = [
'country' => 'US',
'vat_number' => 'DE123456789',
], $this->request->rules());
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertFalse($validator->passes());
$this->assertArrayHasKey('country', $validator->errors()->toArray());
@ -74,23 +80,8 @@ class AddTaxIdentifierRequestTest extends TestCase
'vat_number' => 'DE12345', // Too short
];
$rules = [
'country' => ['required', 'bail'],
'vat_number' => [
'required',
'string',
'bail',
function ($attribute, $value, $fail) use ($data){
if ( isset($this->vat_regex_patterns[$data['country']])) {
if (!preg_match($this->vat_regex_patterns[$data['country']], $value)) {
$fail(ctrans('texts.invalid_vat_number'));
}
}
},
]
];
$validator = Validator::make($data, $rules);
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertFalse($validator->passes());
$this->assertArrayHasKey('vat_number', $validator->errors()->toArray());
@ -98,9 +89,12 @@ class AddTaxIdentifierRequestTest extends TestCase
public function testMissingCountry()
{
$validator = Validator::make([
$data = [
'vat_number' => 'DE123456789',
], $this->request->rules());
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertFalse($validator->passes());
$this->assertArrayHasKey('country', $validator->errors()->toArray());
@ -108,9 +102,12 @@ class AddTaxIdentifierRequestTest extends TestCase
public function testMissingVatNumber()
{
$validator = Validator::make([
$data = [
'country' => 'DE',
], $this->request->rules());
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertFalse($validator->passes());
$this->assertArrayHasKey('vat_number', $validator->errors()->toArray());

View File

@ -5,8 +5,6 @@ namespace Tests\Feature\EInvoice\Validation;
use Tests\TestCase;
use Illuminate\Support\Facades\Validator;
use App\Http\Requests\EInvoice\Peppol\StoreEntityRequest;
use App\Models\Country;
use Illuminate\Support\Collection;
class CreateRequestTest extends TestCase
{
@ -20,36 +18,40 @@ class CreateRequestTest extends TestCase
public function testValidInput()
{
$validator = Validator::make([
$data = [
'party_name' => 'Test Company',
'line1' => '123 Test St',
'city' => 'Test City',
'country' => 'DE', // Assuming 1 is the ID for Germany
'country' => 'DE',
'zip' => '12345',
'county' => 'Test County',
'acts_as_sender' => true,
'acts_as_receiver' => true,
'tenant_id' => 'testcompanykey',
];
], $this->request->rules());
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertTrue($validator->passes());
}
public function testInvalidCountry()
{
$validator = Validator::make([
$data = [
'party_name' => 'Test Company',
'line1' => '123 Test St',
'city' => 'Test City',
'country' => 999, // Invalid country ID
'country' => 999,
'zip' => '12345',
'county' => 'Test County',
'acts_as_sender' => true,
'acts_as_receiver' => true,
'tenant_id' => 'testcompanykey',
], $this->request->rules());
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertFalse($validator->passes());
$this->assertArrayHasKey('country', $validator->errors()->toArray());
@ -57,9 +59,12 @@ class CreateRequestTest extends TestCase
public function testMissingRequiredFields()
{
$validator = Validator::make([
$data = [
'line2' => 'Optional line',
], $this->request->rules());
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertFalse($validator->passes());
$errors = $validator->errors()->toArray();
@ -73,7 +78,7 @@ class CreateRequestTest extends TestCase
public function testOptionalLine2()
{
$validator = Validator::make([
$data = [
'party_name' => 'Test Company',
'line1' => '123 Test St',
'line2' => 'Optional line',
@ -84,17 +89,22 @@ class CreateRequestTest extends TestCase
'tenant_id' => 'testcompanykey',
'acts_as_sender' => true,
'acts_as_receiver' => true,
], $this->request->rules());
];
$this->request->initialize($data);
$validator = Validator::make($data, $this->request->rules());
$this->assertTrue($validator->passes());
}
public function testCountryPreparation()
{
$request = new StoreEntityRequest([
'country' => '276', // Assuming 1 is the ID for Germany
]);
$data = [
'country' => '276', // Numeric code for Germany
];
$request = new StoreEntityRequest();
$request->initialize($data);
$request->prepareForValidation();
$this->assertEquals('DE', $request->input('country'));