-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com>
- Loading branch information
Showing
26 changed files
with
795 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Igniter\Api\Database\Factories; | ||
|
||
use Igniter\Flame\Database\Factories\Factory; | ||
|
||
class ResourceFactory extends Factory | ||
{ | ||
protected $model = \Igniter\Api\Models\Resource::class; | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'name' => $this->faker->sentence(2), | ||
'endpoint' => $this->faker->word(), | ||
'description' => $this->faker->paragraph(), | ||
'meta' => [ | ||
'actions' => ['index', 'show', 'store', 'update', 'destroy'], | ||
'authorization' => [ | ||
'index' => 'all', | ||
'show' => 'admin', | ||
'store' => 'admin', | ||
'update' => 'admin', | ||
'destroy' => 'admin', | ||
], | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Igniter\Api\Database\Factories; | ||
|
||
use Igniter\Flame\Database\Factories\Factory; | ||
|
||
class TokenFactory extends Factory | ||
{ | ||
protected $model = \Igniter\Api\Models\Token::class; | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'tokenable_type' => 'users', | ||
'tokenable_id' => 1, | ||
'name' => $this->faker->sentence(2), | ||
'token' => $this->faker->sha256, | ||
'abilities' => ['*'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Igniter\Api\Tests\ApiResources\Requests; | ||
|
||
use Igniter\Api\ApiResources\Requests\MenuItemOptionRequest; | ||
|
||
it('returns correct attribute labels', function() { | ||
$request = new MenuItemOptionRequest(); | ||
|
||
$attributes = $request->attributes(); | ||
|
||
expect($attributes)->toHaveKey('menu_id', lang('igniter.cart::default.menus.label_option')) | ||
->and($attributes)->toHaveKey('option_id', lang('igniter.cart::default.menus.label_option_id')) | ||
->and($attributes)->toHaveKey('priority', lang('igniter.cart::default.menus.label_option')) | ||
->and($attributes)->toHaveKey('required', lang('igniter.cart::default.menus.label_option_required')) | ||
->and($attributes)->toHaveKey('min_selected', lang('igniter.cart::default.menus.label_min_selected')) | ||
->and($attributes)->toHaveKey('max_selected', lang('igniter.cart::default.menus.label_max_selected')) | ||
->and($attributes)->toHaveKey('menu_option_values.*', lang('admin::lang.label_option_value_id')); | ||
}); | ||
|
||
it('returns correct validation rules', function() { | ||
$request = new MenuItemOptionRequest(); | ||
|
||
$rules = $request->rules(); | ||
|
||
expect($rules)->toHaveKey('menu_id') | ||
->and($rules)->toHaveKey('option_id') | ||
->and($rules)->toHaveKey('priority') | ||
->and($rules)->toHaveKey('required') | ||
->and($rules)->toHaveKey('min_selected') | ||
->and($rules)->toHaveKey('max_selected') | ||
->and($rules)->toHaveKey('menu_option_values.*') | ||
->and($rules['menu_id'])->toContain('nullable', 'integer') | ||
->and($rules['option_id'])->toContain('required', 'integer') | ||
->and($rules['priority'])->toContain('integer') | ||
->and($rules['required'])->toContain('boolean') | ||
->and($rules['min_selected'])->toContain('integer', 'lte:max_selected') | ||
->and($rules['max_selected'])->toContain('integer', 'gte:min_selected') | ||
->and($rules['menu_option_values.*'])->toContain('array'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Igniter\Api\Tests\ApiResources\Requests; | ||
|
||
use Igniter\Api\ApiResources\Requests\MenuOptionRequest; | ||
|
||
it('returns correct attribute labels', function() { | ||
$request = new MenuOptionRequest(); | ||
|
||
$attributes = $request->attributes(); | ||
|
||
expect($attributes)->toHaveKey('option_name', lang('admin::lang.menu_options.label_option_group_name')) | ||
->and($attributes)->toHaveKey('display_type', lang('admin::lang.menu_options.label_display_type')) | ||
->and($attributes)->toHaveKey('priority', lang('admin::lang.menu_options.label_priority')) | ||
->and($attributes)->toHaveKey('locations.*', lang('admin::lang.label_location')) | ||
->and($attributes)->toHaveKey('option_values.*.option_value_id', lang('admin::lang.label_option_value_id')) | ||
->and($attributes)->toHaveKey('option_values.*.option_id', lang('admin::lang.label_option_id')) | ||
->and($attributes)->toHaveKey('option_values.*.value', lang('admin::lang.menu_options.label_option_value')) | ||
->and($attributes)->toHaveKey('option_values.*.price', lang('admin::lang.menu_options.label_option_price')) | ||
->and($attributes)->toHaveKey('option_values.*.priority', lang('admin::lang.menu_options.label_option_price')) | ||
->and($attributes)->toHaveKey('option_values.*.allergens.*', lang('igniter.cart::default.menus.label_allergens')); | ||
}); | ||
|
||
it('returns correct validation rules', function() { | ||
$request = new MenuOptionRequest(); | ||
|
||
$rules = $request->rules(); | ||
|
||
expect($rules)->toHaveKey('option_name') | ||
->and($rules)->toHaveKey('display_type') | ||
->and($rules)->toHaveKey('priority') | ||
->and($rules)->toHaveKey('locations.*') | ||
->and($rules)->toHaveKey('option_values.*.option_value_id') | ||
->and($rules)->toHaveKey('option_values.*.option_id') | ||
->and($rules)->toHaveKey('option_values.*.value') | ||
->and($rules)->toHaveKey('option_values.*.price') | ||
->and($rules)->toHaveKey('option_values.*.priority') | ||
->and($rules)->toHaveKey('option_values.*.allergens.*') | ||
->and($rules['option_name'])->toContain('required', 'min:2', 'max:32') | ||
->and($rules['display_type'])->toContain('required', 'alpha') | ||
->and($rules['priority'])->toContain('integer') | ||
->and($rules['locations.*'])->toContain('integer') | ||
->and($rules['option_values.*.option_value_id'])->toContain('integer') | ||
->and($rules['option_values.*.option_id'])->toContain('integer') | ||
->and($rules['option_values.*.value'])->toContain('min:2', 'max:128') | ||
->and($rules['option_values.*.price'])->toContain('numeric', 'min:0') | ||
->and($rules['option_values.*.priority'])->toContain('integer') | ||
->and($rules['option_values.*.allergens.*'])->toContain('integer'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Igniter\Api\Tests\ApiResources\Requests; | ||
|
||
use Igniter\Api\ApiResources\Requests\OrderRequest; | ||
|
||
it('returns correct attribute labels', function() { | ||
$request = new OrderRequest(); | ||
|
||
$attributes = $request->attributes(); | ||
|
||
expect($attributes)->toHaveKey('first_name', lang('igniter.cart::default.checkout.label_first_name')) | ||
->and($attributes)->toHaveKey('last_name', lang('igniter.cart::default.checkout.label_last_name')) | ||
->and($attributes)->toHaveKey('email', lang('igniter.cart::default.checkout.label_email')) | ||
->and($attributes)->toHaveKey('telephone', lang('igniter.cart::default.checkout.label_telephone')) | ||
->and($attributes)->toHaveKey('comment', lang('igniter.cart::default.checkout.label_comment')) | ||
->and($attributes)->toHaveKey('payment', lang('igniter.cart::default.checkout.label_payment_method')) | ||
->and($attributes)->toHaveKey('order_type', lang('igniter.cart::default.checkout.label_order_type')) | ||
->and($attributes)->toHaveKey('address_id', lang('igniter.cart::default.checkout.label_address')) | ||
->and($attributes)->toHaveKey('address.address_1', lang('igniter.cart::default.checkout.label_address_1')) | ||
->and($attributes)->toHaveKey('address.address_2', lang('igniter.cart::default.checkout.label_address_2')) | ||
->and($attributes)->toHaveKey('address.city', lang('igniter.cart::default.checkout.label_city')) | ||
->and($attributes)->toHaveKey('address.state', lang('igniter.cart::default.checkout.label_state')) | ||
->and($attributes)->toHaveKey('address.postcode', lang('igniter.cart::default.checkout.label_postcode')) | ||
->and($attributes)->toHaveKey('address.country_id', lang('igniter.cart::default.checkout.label_country')); | ||
}); | ||
|
||
it('returns correct validation rules', function() { | ||
$request = new OrderRequest(); | ||
$request->setMethod('post'); | ||
$request->merge([ | ||
'order_type' => 'delivery', | ||
]); | ||
|
||
$rules = $request->rules(); | ||
|
||
expect($rules)->toHaveKey('first_name') | ||
->and($rules)->toHaveKey('last_name') | ||
->and($rules)->toHaveKey('email') | ||
->and($rules)->toHaveKey('telephone') | ||
->and($rules)->toHaveKey('comment') | ||
->and($rules)->toHaveKey('payment') | ||
->and($rules)->toHaveKey('order_type') | ||
->and($rules)->toHaveKey('address_id') | ||
->and($rules)->toHaveKey('address.address_1') | ||
->and($rules)->toHaveKey('address.address_2') | ||
->and($rules)->toHaveKey('address.city') | ||
->and($rules)->toHaveKey('address.state') | ||
->and($rules)->toHaveKey('address.postcode') | ||
->and($rules)->toHaveKey('address.country_id') | ||
->and($rules)->toHaveKey('customer_id') | ||
->and($rules)->toHaveKey('order_menus') | ||
->and($rules)->toHaveKey('order_totals') | ||
->and($rules)->toHaveKey('status_id') | ||
->and($rules)->toHaveKey('is_processed') | ||
->and($rules['first_name'])->toContain('between:1,48') | ||
->and($rules['last_name'])->toContain('between:1,48') | ||
->and($rules['email'])->toContain('sometimes', 'required', 'email:filter', 'max:96') | ||
->and($rules['telephone'])->toContain('string') | ||
->and($rules['comment'])->toContain('max:500') | ||
->and($rules['order_type'])->toContain('alpha_dash') | ||
->and($rules['payment'])->toContain('sometimes', 'required', 'alpha_dash') | ||
->and($rules['customer_id'])->toContain('integer') | ||
->and($rules['order_menus'])->toContain('array') | ||
->and($rules['order_totals'])->toContain('array') | ||
->and($rules['status_id'])->toContain('integer') | ||
->and($rules['is_processed'])->toContain('integer'); | ||
}); |
Oops, something went wrong.