Fixes for tests
This commit is contained in:
parent
535ce66339
commit
de1c7fdc0e
|
|
@ -38,48 +38,54 @@ class UpdateEInvoiceConfiguration extends Request
|
|||
public function rules()
|
||||
{
|
||||
|
||||
|
||||
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_swift' => ['bail',
|
||||
Rule::requiredIf(function () {
|
||||
$code = $this->input('payment_means.code');
|
||||
'payment_means.*.bic_swift' => Rule::forEach(function (string|null $value, string $attribute) {
|
||||
$index = explode('.', $attribute)[1];
|
||||
$code = $this->input("payment_means.{$index}.code");
|
||||
$requirements = PaymentMeans::$payment_means_requirements_codes[$code] ?? [];
|
||||
return in_array('bic_swift', $requirements);
|
||||
|
||||
return ['bail', Rule::requiredIf(in_array('bic_swift', $requirements))];
|
||||
}),
|
||||
],
|
||||
'payment_means.*.iban' => ['bail', 'sometimes', 'string', 'min:15', 'max:34',
|
||||
Rule::requiredIf(function () {
|
||||
$code = $this->input('payment_means.code');
|
||||
'payment_means.*.iban' => Rule::forEach(function (string|null $value, string $attribute) {
|
||||
$index = explode('.', $attribute)[1];
|
||||
$code = $this->input("payment_means.{$index}.code");
|
||||
$requirements = PaymentMeans::$payment_means_requirements_codes[$code] ?? [];
|
||||
return in_array('iban', $requirements);
|
||||
|
||||
return ['bail', 'sometimes', 'string', 'min:15', 'max:34',
|
||||
Rule::requiredIf(in_array('iban', $requirements))];
|
||||
}),
|
||||
],
|
||||
'payment_means.*.account_holder' => ['bail', 'sometimes', 'string', 'max:255',
|
||||
Rule::requiredIf(function () {
|
||||
$code = $this->input('payment_means.code');
|
||||
'payment_means.*.account_holder' => Rule::forEach(function (string|null $value, string $attribute) {
|
||||
$index = explode('.', $attribute)[1];
|
||||
$code = $this->input("payment_means.{$index}.code");
|
||||
$requirements = PaymentMeans::$payment_means_requirements_codes[$code] ?? [];
|
||||
return in_array('account_holder', $requirements);
|
||||
|
||||
return ['bail', 'sometimes', 'string', 'max:255',
|
||||
Rule::requiredIf(in_array('account_holder', $requirements))];
|
||||
}),
|
||||
],
|
||||
'payment_means.*.information' => ['bail', 'sometimes', 'nullable', 'string'],
|
||||
'payment_means.*.card_type' => ['bail', 'sometimes', 'nullable', 'string', 'min:4',
|
||||
Rule::requiredIf(function () {
|
||||
$code = $this->input('payment_means.code');
|
||||
'payment_means.*.card_type' => Rule::forEach(function (string|null $value, string $attribute) {
|
||||
$index = explode('.', $attribute)[1];
|
||||
$code = $this->input("payment_means.{$index}.code");
|
||||
$requirements = PaymentMeans::$payment_means_requirements_codes[$code] ?? [];
|
||||
return in_array('card_type', $requirements);
|
||||
|
||||
return ['bail', 'sometimes', 'nullable', 'string', 'min:4',
|
||||
Rule::requiredIf(in_array('card_type', $requirements))];
|
||||
}),
|
||||
],
|
||||
'payment_means.*.card_holder' => ['bail', 'sometimes', 'nullable', 'string', 'min:4',
|
||||
Rule::requiredIf(function () {
|
||||
$code = $this->input('payment_means.code');
|
||||
'payment_means.*.card_holder' => Rule::forEach(function (string|null $value, string $attribute) {
|
||||
$index = explode('.', $attribute)[1];
|
||||
$code = $this->input("payment_means.{$index}.code");
|
||||
$requirements = PaymentMeans::$payment_means_requirements_codes[$code] ?? [];
|
||||
return in_array('card_holder', $requirements);
|
||||
|
||||
return ['bail', 'sometimes', 'nullable', 'string', 'min:4',
|
||||
Rule::requiredIf(in_array('card_holder', $requirements))];
|
||||
}),
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function prepareForValidation()
|
||||
|
|
|
|||
|
|
@ -50,9 +50,9 @@ class UpdateEInvoiceConfigurationTest extends TestCase
|
|||
{
|
||||
$data = [
|
||||
'entity' => 'invoice',
|
||||
'payment_means' => [
|
||||
'payment_means' => [[
|
||||
'code' => 'invalidcodehere'
|
||||
]
|
||||
]]
|
||||
];
|
||||
|
||||
$this->request->initialize($data);
|
||||
|
|
@ -65,12 +65,12 @@ class UpdateEInvoiceConfigurationTest extends TestCase
|
|||
{
|
||||
$data = [
|
||||
'entity' => 'invoice',
|
||||
'payment_means' => [
|
||||
'payment_means' => [[
|
||||
'code' => '30',
|
||||
'iban' => '12345678',
|
||||
'iban' => '123456789101112254',
|
||||
'bic_swift' => 'DEUTDEFF',
|
||||
'account_holder' => 'John Doe Company Limited'
|
||||
]
|
||||
]]
|
||||
];
|
||||
|
||||
$this->request->initialize($data);
|
||||
|
|
@ -83,29 +83,29 @@ class UpdateEInvoiceConfigurationTest extends TestCase
|
|||
{
|
||||
$data = [
|
||||
'entity' => 'invoice',
|
||||
'payment_means' => [
|
||||
'payment_means' => [[
|
||||
'code' => '48',
|
||||
'card_type' => 'VISA',
|
||||
'iban' => '12345678'
|
||||
]
|
||||
]]
|
||||
];
|
||||
|
||||
$this->request->initialize($data);
|
||||
$validator = Validator::make($data, $this->request->rules());
|
||||
|
||||
$this->assertTrue($validator->passes());
|
||||
$this->assertFalse($validator->passes());
|
||||
}
|
||||
|
||||
public function testValidatesPaymentMeansForCreditCard()
|
||||
{
|
||||
$data = [
|
||||
'entity' => 'invoice',
|
||||
'payment_means' => [
|
||||
'payment_means' => [[
|
||||
'code' => '54',
|
||||
'card_type' => 'VISA',
|
||||
'card_number' => '************1234',
|
||||
'card_holder' => 'John Doe'
|
||||
]
|
||||
]]
|
||||
];
|
||||
|
||||
$this->request->initialize($data);
|
||||
|
|
@ -118,44 +118,44 @@ class UpdateEInvoiceConfigurationTest extends TestCase
|
|||
{
|
||||
$data = [
|
||||
'entity' => 'invoice',
|
||||
'payment_means' => [
|
||||
'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'));
|
||||
|
||||
$this->assertTrue($validator->errors()->has('payment_means.0.bic_swift'));
|
||||
|
||||
}
|
||||
|
||||
public function testFailsValidationWithInvalidPaymentMeansCode()
|
||||
{
|
||||
$data = [
|
||||
'entity' => 'invoice',
|
||||
'payment_means' => [
|
||||
'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'));
|
||||
$this->assertTrue($validator->errors()->has('payment_means.0.code'));
|
||||
}
|
||||
|
||||
public function testValidatesPaymentMeansForDirectDebit()
|
||||
{
|
||||
$data = [
|
||||
'entity' => 'invoice',
|
||||
'payment_means' => [
|
||||
'payment_means' => [[
|
||||
'code' => '49',
|
||||
'payer_bank_account' => '12345678',
|
||||
'bic_swift' => 'DEUTDEFF'
|
||||
]
|
||||
]]
|
||||
];
|
||||
|
||||
$this->request->initialize($data);
|
||||
|
|
@ -168,11 +168,11 @@ class UpdateEInvoiceConfigurationTest extends TestCase
|
|||
{
|
||||
$data = [
|
||||
'entity' => 'invoice',
|
||||
'payment_means' => [
|
||||
'payment_means' => [[
|
||||
'code' => '15',
|
||||
'account_holder' => 'John Doe Company Limited',
|
||||
'bsb_sort' => '123456'
|
||||
]
|
||||
]]
|
||||
];
|
||||
|
||||
$this->request->initialize($data);
|
||||
|
|
|
|||
Loading…
Reference in New Issue