Skip to content

Commit

Permalink
Fix tests and api perfs
Browse files Browse the repository at this point in the history
  • Loading branch information
ilestis committed Dec 2, 2023
1 parent aee6811 commit ba91172
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/Http/Resources/EntityAssetResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function toArray($request)
/** @var EntityAsset $asset */
$asset = $this->resource;

$data = $this->entity([
$data = $this->onEntity([
'type_id' => $asset->type_id,
'_file' => $asset->isFile(),
'_link' => $asset->isLink(),
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/EntityResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function entity(array $prepared = [])

if ($misc->ancestors) {
$ancestors = [];
foreach ($misc->getAncestors(['id']) as $ancestor) {
foreach ($misc->ancestors as $ancestor) {
$ancestors[] = $ancestor->id;
}
$merged['parents'] = $ancestors;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/InventoryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function toArray($request)
{
/** @var Inventory $model */
$model = $this->resource;
return $this->entity([
return $this->onEntity([
'item_id' => $model->item_id,
'name' => $model->name,
'position' => $model->position,
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/PostResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function toArray($request)
{
/** @var Post $model */
$model = $this->resource;
return $this->entity([
return $this->onEntity([
'name' => $model->name,
'visibility_id' => (int) $model->visibility_id->value,
'entry' => $model->entry,
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships;

/**
* Class Calendar
Expand Down Expand Up @@ -40,6 +41,7 @@ class Calendar extends MiscModel
use CalendarRelations;
use CampaignTrait;
use ExportableTrait;
use HasRecursiveRelationships;
use HasFactory;
use SoftDeletes;

Expand Down
8 changes: 0 additions & 8 deletions app/Models/Relations/CalendarRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,4 @@ public function calendars()
{
return $this->hasMany(Calendar::class);
}

/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function children()
{
return $this->hasMany(Calendar::class);
}
}
12 changes: 8 additions & 4 deletions app/Models/Scopes/SubEntityScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,18 @@ public function scopeWithApi(Builder $query): Builder
{
$relations = [
'entity',
'entity.tags', 'entity.posts', 'entity.events',
'entity.relationships', 'entity.attributes', 'entity.inventories',
'entity.tags',
'entity.posts', 'entity.posts.permissions',
'entity.events',
'entity.relationships', 'entity.attributes', 'entity.inventories', 'entity.inventories',
'entity.assets',
'entity.abilities',
'ancestors',
'children',
];

if (method_exists($this, 'ancestors')) {
$relations[] = 'ancestors';
$relations[] = 'children';
}
$with = !empty($this->apiWith) ? $this->apiWith : [];
foreach ($with as $relation) {
$relations[] = $relation;
Expand Down
23 changes: 15 additions & 8 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Models\Attribute;
use App\Models\Bookmark;
use App\Models\Campaign;
use App\Services\Permissions\RolePermissionService;
use Illuminate\Support\Facades\Storage;
use App\Models\CampaignRoleUser;
use App\Models\CampaignUser;
Expand Down Expand Up @@ -120,10 +121,12 @@ public function asPlayer(): self
'user_id' => $user2->id,
]);
Permissions::reset();
CampaignRole::where('id', 3)->first()->toggle(1, 1);
CampaignRole::where('id', 3)->first()->toggle(10, 1);
CampaignRole::where('id', 3)->first()->toggle(11, 1);
CampaignRole::where('id', 3)->first()->toggle(7, 1);
/** @var RolePermissionService $service */
$service = app()->make(RolePermissionService::class);
$service->role(CampaignRole::where('id', 3)->first())->toggle(1, 1);
$service->role(CampaignRole::where('id', 3)->first())->toggle(10, 1);
$service->role(CampaignRole::where('id', 3)->first())->toggle(11, 1);
$service->role(CampaignRole::where('id', 3)->first())->toggle(7, 1);

return $this;
}
Expand All @@ -142,7 +145,9 @@ public function withMember(): self
'user_id' => $user3->id,
]);

CampaignRole::where('id', 3)->first()->toggle(1, 1);
/** @var RolePermissionService $service */
$service = app()->make(RolePermissionService::class);
$service->role(CampaignRole::where('id', 3)->first())->toggle(1, 1);

return $this;
}
Expand Down Expand Up @@ -176,9 +181,11 @@ public function withCampaigns(array $extra = []): self

public function withPermissions(array $extra = []): self
{
CampaignRole::where('id', 3)->first()->toggle(1, 1);
CampaignRole::where('id', 3)->first()->toggle(1, 2);
CampaignRole::where('id', 3)->first()->toggle(1, 3);
/** @var RolePermissionService $service */
$service = app()->make(RolePermissionService::class);
$service->role(CampaignRole::where('id', 3)->first())->toggle(1, 1);
$service->role(CampaignRole::where('id', 3)->first())->toggle(1, 2);
$service->role(CampaignRole::where('id', 3)->first())->toggle(1, 3);

return $this;
}
Expand Down

0 comments on commit ba91172

Please sign in to comment.