Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the following menu fields to requests: mealtimes, ingredients #86

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Requests/MenuRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public function attributes()
'menu_description' => lang('igniter::admin.label_description'),
'menu_price' => lang('igniter.cart::default.menus.label_price'),
'categories.*' => lang('igniter.cart::default.menus.label_category'),
'ingredients.*' => lang('igniter.cart::default.menus.label_ingredients'),
'mealtimes.*' => lang('igniter.cart::default.menus.label_mealtime'),
'locations.*' => lang('igniter::admin.column_location'),
'minimum_qty' => lang('igniter.cart::default.menus.label_minimum_qty'),
'order_restriction.*' => lang('igniter.cart::default.menus.label_order_restriction'),
Expand All @@ -30,6 +32,8 @@ public function rules()
'menu_description' => ['string', 'between:2,1028'],
'menu_price' => ['required', 'numeric', 'min:0'],
'categories.*' => ['sometimes', 'required', 'integer'],
'ingredients.*' => ['sometimes', 'required', 'integer'],
'mealtimes.*' => ['sometimes', 'required', 'integer'],
'locations.*' => ['integer'],
'minimum_qty' => ['sometimes', 'required', 'integer', 'min:1'],
'order_restriction.*' => ['nullable', 'string'],
Expand Down
118 changes: 110 additions & 8 deletions tests/Requests/MenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,118 @@

use Igniter\Cart\Requests\MenuRequest;

it('has rules for menu_name', function () {
expect('required')->toBeIn(array_get((new MenuRequest)->rules(), 'menu_name'))
->and('between:2,255')->toBeIn(array_get((new MenuRequest)->rules(), 'menu_name'));
it('has required rule for inputs:
menu_name, menu_price, categories.*, ingredients.*, mealtimes.*, minimum_qty',
function () {
$rules = (new MenuRequest)->rules();
$inputNames = ['menu_name', 'menu_price', 'categories.*', 'ingredients.*', 'mealtimes.*', 'minimum_qty'];
$testExpectation = null;

foreach ($inputNames as $key => $inputName) {
if ($key == 0) {
$testExpectation = expect('required')->toBeIn(array_get($rules, $inputName));
}
$testExpectation = $testExpectation->and('required')->toBeIn(array_get($rules, $inputName));
}
}
);

it('has string rule for inputs:
menu_name, menu_description, order_restriction.*',
function () {
$rules = (new MenuRequest)->rules();
$inputNames = ['menu_name', 'menu_description', 'order_restriction.*'];
$testExpectation = null;

foreach ($inputNames as $key => $inputName) {
if ($key == 0) {
$testExpectation = expect('string')->toBeIn(array_get($rules, $inputName));
}
$testExpectation = $testExpectation->and('string')->toBeIn(array_get($rules, $inputName));
}
}
);

it('has between:2,255 rule for menu_name input', function () {
$rules = (new MenuRequest)->rules();

expect('between:2,255')->toBeIn(array_get($rules, 'menu_name'));
});

it('has between:2,1028 rule for menu_description input', function () {
$rules = (new MenuRequest)->rules();

expect('between:2,1028')->toBeIn(array_get($rules, 'menu_description'));
});

it('has numeric rule for menu_price input', function () {
$rules = (new MenuRequest)->rules();

expect('numeric')->toBeIn(array_get($rules, 'menu_price'));
});

it('has rules for menu_price', function () {
expect('required')->toBeIn(array_get((new MenuRequest)->rules(), 'menu_price'))
->and('min:0')->toBeIn(array_get((new MenuRequest)->rules(), 'menu_price'));
it('has min:0 rule for menu_price input', function () {
$rules = (new MenuRequest)->rules();

expect('min:0')->toBeIn(array_get($rules, 'menu_price'));
});

it('has min:1 rule for minimum_qty input', function () {
$rules = (new MenuRequest)->rules();

expect('min:1')->toBeIn(array_get($rules, 'minimum_qty'));
});

it('has rules for menu_description', function () {
expect('between:2,1028')->toBeIn(array_get((new MenuRequest)->rules(), 'menu_description'));
it('has boolean rule for menu_status input', function () {
$rules = (new MenuRequest)->rules();

expect('boolean')->toBeIn(array_get($rules, 'menu_status'));
});

it('has sometimes rule for inputs:
categories.*, ingredients.*, mealtimes.*, minimum_qty',
function () {
$rules = (new MenuRequest)->rules();
$inputNames = ['categories.*', 'ingredients.*', 'mealtimes.*', 'minimum_qty'];
$testExpectation = null;

foreach ($inputNames as $key => $inputName) {
if ($key == 0) {
$testExpectation = expect('sometimes')->toBeIn(array_get($rules, $inputName));
}
$testExpectation = $testExpectation->and('sometimes')->toBeIn(array_get($rules, $inputName));
}
}
);

it('has integer rule for inputs:
categories.*, ingredients.*, mealtimes.*, locations.*, minimum_qty, mealtime_id, menu_priority',
function () {
$rules = (new MenuRequest)->rules();
$inputNames = ['categories.*', 'ingredients.*', 'mealtimes.*', 'locations.*', 'minimum_qty', 'mealtime_id', 'menu_priority'];
$testExpectation = null;

foreach ($inputNames as $key => $inputName) {
if ($key == 0) {
$testExpectation = expect('integer')->toBeIn(array_get($rules, $inputName));
}
$testExpectation = $testExpectation->and('integer')->toBeIn(array_get($rules, $inputName));
}
}
);

it('has nullable rule for inputs:
order_restriction.*, mealtime_id, menu_priority',
function () {
$rules = (new MenuRequest)->rules();
$inputNames = ['order_restriction.*', 'mealtime_id', 'menu_priority'];
$testExpectation = null;

foreach ($inputNames as $key => $inputName) {
if ($key == 0) {
$testExpectation = expect('nullable')->toBeIn(array_get($rules, $inputName));
}
$testExpectation = $testExpectation->and('nullable')->toBeIn(array_get($rules, $inputName));
}
}
);
Loading