Skip to content

Commit

Permalink
add: required field validation wip
Browse files Browse the repository at this point in the history
  • Loading branch information
matfire committed Oct 16, 2024
1 parent 7a93661 commit 1f4abe1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
19 changes: 19 additions & 0 deletions config/publishers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,23 @@
'input',
'select',
],
'field_validation' => [
'input' => [
'required_values' => [
'type',
'label'
],
'optional_values' => [
'placeholder'
]
],
'select' => [
'required_values' => [

],
'optional_values' => [

]
]
]
];
19 changes: 18 additions & 1 deletion tests/Feature/PublisherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,29 @@
$this->classes = Discover::in(app_path('Publishers'))->classes()->implementing(PublisherContract::class)->get();
});

it('publisher inputs are all valid', function () {
arch()
->expect('App\Publishers')
->toBeClasses()
->ignoring('App\Publishers\PublisherContract');

it('publisher inputs are allowed', function () {
foreach ($this->classes as $class) {
$instance = new $class;
$inputs = $instance->getInputs();
foreach ($inputs as $input) {
$validationRules = config('publishers.field_validation');
expect($input['input'])->toBeIn(config('publishers.allowed_fields'));
expect($input)->toHaveKeys($validationRules[$input['input']]['required_values']);
}
}
});
it('publisher inputs have all required options', function() {
foreach ($this->classes as $class) {
$instance = new $class;
$inputs = $instance->getInputs();
foreach ($inputs as $input) {
$validationRules = config('publishers.field_validation');
expect($input)->toHaveKeys($validationRules[$input['input']]['required_values']);
}
}
});
Expand Down

0 comments on commit 1f4abe1

Please sign in to comment.