Skip to content

Commit

Permalink
Update test scripts for improved coverage.
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com>
  • Loading branch information
sampoyigi committed Dec 20, 2024
1 parent 4dd9506 commit 6badf58
Show file tree
Hide file tree
Showing 62 changed files with 1,316 additions and 235 deletions.
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/AddressTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\User\Models\Address;
use League\Fractal\TransformerAbstract;

class AddressTransformer extends TransformerAbstract
{
use MergesIdAttribute;

public function transform(Address $address)
{
return $address->toArray();
return $this->mergesIdAttribute($address);
}
}
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/CategoryTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\Cart\Models\Category;
use League\Fractal\TransformerAbstract;

class CategoryTransformer extends TransformerAbstract
{
use MergesIdAttribute;

protected array $availableIncludes = [
'media',
'menus',
Expand All @@ -15,7 +18,7 @@ class CategoryTransformer extends TransformerAbstract

public function transform(Category $category)
{
return $category->toArray();
return $this->mergesIdAttribute($category);
}

public function includeMedia(Category $category)
Expand Down
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/CurrencyTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\System\Models\Currency;
use League\Fractal\TransformerAbstract;

class CurrencyTransformer extends TransformerAbstract
{
use MergesIdAttribute;

public function transform(Currency $currency)
{
return $currency->toArray();
return $this->mergesIdAttribute($currency);
}
}
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/CustomerTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\User\Models\Customer;
use League\Fractal\TransformerAbstract;

class CustomerTransformer extends TransformerAbstract
{
use MergesIdAttribute;

protected array $availableIncludes = [
'addresses',
'orders',
Expand All @@ -15,7 +18,7 @@ class CustomerTransformer extends TransformerAbstract

public function transform(Customer $customer)
{
return $customer->toArray();
return $this->mergesIdAttribute($customer);
}

public function includeAddresses(Customer $customer)
Expand Down
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/DeliveryAreaTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\Local\Models\LocationArea;
use League\Fractal\TransformerAbstract;

class DeliveryAreaTransformer extends TransformerAbstract
{
use MergesIdAttribute;

public function transform(LocationArea $deliveryArea)
{
return $deliveryArea->toArray();
return $this->mergesIdAttribute($deliveryArea);
}
}
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/IngredientTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\Cart\Models\Ingredient;
use League\Fractal\TransformerAbstract;

class IngredientTransformer extends TransformerAbstract
{
use MergesIdAttribute;

public function transform(Ingredient $ingredient)
{
return $ingredient->toArray();
return $this->mergesIdAttribute($ingredient);
}
}
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/LocationTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\Local\Models\Location;
use League\Fractal\TransformerAbstract;

class LocationTransformer extends TransformerAbstract
{
use MergesIdAttribute;

protected array $availableIncludes = [
'media',
'working_hours',
Expand All @@ -16,7 +19,7 @@ class LocationTransformer extends TransformerAbstract

public function transform(Location $location)
{
return $location->toArray();
return $this->mergesIdAttribute($location);
}

public function includeMedia(Location $location)
Expand Down
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/MealtimeTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\Cart\Models\Mealtime;
use League\Fractal\TransformerAbstract;

class MealtimeTransformer extends TransformerAbstract
{
use MergesIdAttribute;

public function transform(Mealtime $mealTime)
{
return array_merge($mealTime->toArray(), []);
return $this->mergesIdAttribute($mealTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function transform(array|MenuItemOptionValue $menuItemOptionValue)
}

return array_merge($menuItemOptionValue, [
'id' => $menuItemOptionValue['menu_option_value_id'],
'currency' => app('currency')->getDefault()->currency_code,
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function transform(array|MenuOptionValue $menuOptionValue)
}

return array_merge($menuOptionValue, [
'id' => $menuOptionValue['option_value_id'],
'currency' => app('currency')->getDefault()->currency_code,
]);
}
Expand Down
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/MenuTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\Cart\Models\Menu;
use League\Fractal\TransformerAbstract;

class MenuTransformer extends TransformerAbstract
{
use MergesIdAttribute;

protected array $availableIncludes = [
'media',
'categories',
Expand All @@ -18,7 +21,7 @@ class MenuTransformer extends TransformerAbstract

public function transform(Menu $menuItem)
{
return array_merge($menuItem->toArray(), [
return $this->mergesIdAttribute($menuItem, [
'currency' => app('currency')->getDefault()->currency_code,
]);
}
Expand Down
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/OrderTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\Cart\Models\Order;
use League\Fractal\TransformerAbstract;

class OrderTransformer extends TransformerAbstract
{
use MergesIdAttribute;

protected array $availableIncludes = [
'customer',
'location',
Expand All @@ -20,7 +23,7 @@ class OrderTransformer extends TransformerAbstract

public function transform(Order $order)
{
return array_merge($order->toArray(), [
return $this->mergesIdAttribute($order, [
'currency' => app('currency')->getDefault()->currency_code,
'order_totals' => $order->getOrderTotals(),
'order_menus' => $order->getOrderMenusWithOptions(),
Expand Down
4 changes: 4 additions & 0 deletions src/ApiResources/Transformers/PaymentMethodTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\PayRegister\Models\Payment;
use League\Fractal\TransformerAbstract;

class PaymentMethodTransformer extends TransformerAbstract
{
use MergesIdAttribute;

public function transform(Payment $payment)
{
return [
'id' => $payment->getKey(),
'payment_id' => $payment->getKey(),
'code' => $payment->code,
'name' => $payment->name,
Expand Down
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/ReservationTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\Reservation\Models\Reservation;
use League\Fractal\TransformerAbstract;

class ReservationTransformer extends TransformerAbstract
{
use MergesIdAttribute;

protected array $availableIncludes = [
'location',
'tables',
Expand All @@ -18,7 +21,7 @@ class ReservationTransformer extends TransformerAbstract

public function transform(Reservation $reservation)
{
return $reservation->toArray();
return $this->mergesIdAttribute($reservation);
}

public function includeLocation(Reservation $reservation)
Expand Down
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/ReviewTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\Local\Models\Review;
use League\Fractal\TransformerAbstract;

class ReviewTransformer extends TransformerAbstract
{
use MergesIdAttribute;

protected array $availableIncludes = [
'location',
'customer',
];

public function transform(Review $review)
{
return $review->toArray();
return $this->mergesIdAttribute($review);
}

public function includeCustomer(Review $review)
Expand Down
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/StatusHistoryTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Admin\Models\StatusHistory;
use Igniter\Api\Traits\MergesIdAttribute;
use League\Fractal\TransformerAbstract;

class StatusHistoryTransformer extends TransformerAbstract
{
use MergesIdAttribute;

public function transform(StatusHistory $statusHistory)
{
return $statusHistory->toArray();
return $this->mergesIdAttribute($statusHistory);
}
}
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/StatusTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Admin\Models\Status;
use Igniter\Api\Traits\MergesIdAttribute;
use League\Fractal\TransformerAbstract;

class StatusTransformer extends TransformerAbstract
{
use MergesIdAttribute;

public function transform(Status $status)
{
return $status->toArray();
return $this->mergesIdAttribute($status);
}
}
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/UserGroupTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\User\Models\UserGroup;
use League\Fractal\TransformerAbstract;

class UserGroupTransformer extends TransformerAbstract
{
use MergesIdAttribute;

public function transform(UserGroup $userGroup)
{
return $userGroup->toArray();
return $this->mergesIdAttribute($userGroup);
}
}
5 changes: 4 additions & 1 deletion src/ApiResources/Transformers/UserTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
use Igniter\User\Models\User;
use League\Fractal\TransformerAbstract;

class UserTransformer extends TransformerAbstract
{
use MergesIdAttribute;

public function transform(User $user)
{
return $user->toArray();
return $this->mergesIdAttribute($user);
}
}
19 changes: 6 additions & 13 deletions src/Classes/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function callAction(string $action, array $parameters = []): mixed
$this->action = $action;

if (!$this->checkAction($action)) {
$this->response()->errorNotFound();
return response()->json()->setStatusCode(404);
}

if ($this->token()) {
Expand All @@ -65,22 +65,15 @@ public function checkAction(string $action): bool
return false;
}

if (!$this->methodExists($action)) {
return false;
if (!method_exists($this, $action) && $this->methodExists($action)) {
return true;
}

if (method_exists($this, $action)) {
$methodInfo = new \ReflectionMethod($this, $action);

return $methodInfo->isPublic();
if (!method_exists($this, $action)) {
return false;
}

return true;
}

public function setStatusCode(int $code)
{
$this->statusCode = $code;
return (new \ReflectionMethod($this, $action))->isPublic();
}

protected function authorizeToken()
Expand Down
Loading

0 comments on commit 6badf58

Please sign in to comment.