Skip to content

Commit

Permalink
Merge pull request #1288 from seatplus/refactor/assets
Browse files Browse the repository at this point in the history
Refactor/assets
  • Loading branch information
herpaderpaldent authored Oct 4, 2022
2 parents fcef3ed + 640eae7 commit 543a335
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 50 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"php": "^8.1",
"laravel/framework": "^9.0",
"laravel/socialite": "^5.0",
"seatplus/eveapi": "^1.0",
"seatplus/auth": "^1.1",
"seatplus/eveapi": "^2.0",
"seatplus/auth": "^2.0",
"inertiajs/inertia-laravel": "^0.5.4",
"tightenco/ziggy": "^1.0.4",
"spatie/laravel-permission": "^5.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default {
},
setup(props) {
return useInfinityScrolling('get.corporation.member_tracking', props.corporation.corporation_id)
return useInfinityScrolling('get.corporation.member_tracking', {corporation_id: props.corporation.corporation_id})
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Corporation/Recruitment/Tabs/LogTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
/>

<span class="absolute -bottom-0.5 -right-1 bg-white rounded-tl px-0.5 py-px">
<ChatAltIcon
<ChatBubbleBottomCenterTextIcon
class="h-5 w-5 text-gray-400"
aria-hidden="true"
/>
Expand Down
33 changes: 20 additions & 13 deletions src/Http/Controllers/Character/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,27 @@ public function getLocations(Request $request)
abort_unless($character_ids, 404);

$query = WebAssetAlias::query()
->with('location')
->whereIn('location_flag', ['Hangar', 'AssetSafety', 'Deliveries'])
->whereIn('assetable_id', $character_ids)
->where('assetable_type', CharacterInfo::class)
->when($request->has('search'), fn ($query) => $query->search($request->get('search')))
->handleWatchlist($request)
->withRecursiveContent()
->with('location')
->select('location_id', 'assetable_id')
->whereIn('location_flag', ['Hangar', 'AssetSafety', 'Deliveries'])
->groupBy('location_id', 'assetable_id')
->orderBy('location_id', 'asc');

$request->whenHas('search', fn ($term) => $query->search($term));

$this->handleWatchlist($query, $request);

if ($request->has('withUnknownLocations')) {
$query = $query->withUnknownLocations();
$query = WebAssetAlias::query()
->whereIn('assetable_id', $character_ids)
->where('assetable_type', CharacterInfo::class)
->withUnknownLocations()
->with('location')
->select('location_id', 'assetable_id')
->whereIn('location_flag', ['Hangar', 'AssetSafety', 'Deliveries'])
->groupBy('location_id', 'assetable_id')
->orderBy('location_id', 'asc');
}

return AssetResource::collection(
Expand All @@ -84,14 +91,14 @@ public function loadLocation(int $location_id, Request $request)

abort_unless($character_ids, 404);

$query = EveApiAsset::with(['assetable', 'type', 'type.group', 'content'])
$query = WebAssetAlias::query()
->whereIn('assetable_id', $character_ids)
->where('assetable_type', CharacterInfo::class)
->where('location_id', $location_id);

$request->whenHas('search', fn ($term) => $query->search($term));

$this->handleWatchlist($query, $request);
->when($request->has('search'), fn ($query) => $query->search($request->get('search')))
->handleWatchlist($request)
->withRecursiveContent()
->where('location_id', $location_id)
->with(['assetable', 'type', 'type.group', 'content', 'location']);

return AssetResource::collection(
$query->paginate()
Expand Down
3 changes: 3 additions & 0 deletions src/Models/Asset/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
use Illuminate\Database\Eloquent\Builder;
use Seatplus\Eveapi\Models\Assets\Asset as EveApiAsset;
use Seatplus\Web\Models\ManualLocation;
use Seatplus\Web\Traits\HasWatchlist;

class Asset extends EveApiAsset
{
use HasWatchlist;

protected $table = 'assets';

public function manual_location()
Expand Down
7 changes: 7 additions & 0 deletions src/Traits/HasWatchlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ private function handleWatchlist(Builder|QueryBuilder $query, Request $request)
});
});
}

public function scopeHandleWatchlist(Builder $query, Request $request)
{
$this->handleWatchlist($query, $request);

return $query;
}
}
57 changes: 24 additions & 33 deletions tests/Integration/AssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

use Inertia\Testing\AssertableInertia as Assert;
use Seatplus\Eveapi\Models\Character\CharacterInfo;
use Seatplus\Eveapi\Models\Universe\Category;
use Seatplus\Eveapi\Models\Universe\Group;
use Seatplus\Eveapi\Models\Universe\Location;
use Seatplus\Eveapi\Models\Universe\Station;
use Seatplus\Eveapi\Models\Universe\Type;
use Seatplus\Web\Models\Asset\Asset;

test('is protected by authentication', function () {
Expand Down Expand Up @@ -217,52 +214,46 @@
test('load asset on watchlist', function () {
// Prepare
$asset = Asset::factory()
->count(2)
->create([
'assetable_id' => test()->test_character->character_id,
'location_flag' => 'Hangar',
])->first();
]);

expect($asset->location)->toBeNull();

$content = Asset::factory()
$asset2 = Asset::factory()
->create([
'location_id' => $asset->item_id,
'location_flag' => 'Cargo',
'type_id' => Type::factory()->create([
'group_id' => Group::factory()->create(['category_id' => Category::factory()]),
]),
'assetable_id' => test()->test_character->character_id,
'location_id' => Location::factory()->for(Station::factory(), 'locatable'),
'location_flag' => 'Hangar',
]);

expect($asset2->location)->not()->toBeNull();

// Act
$response = test()->actingAs(test()->test_user)
->get(route('get.character.assets.locations', [
'character_ids' => [test()->test_character->character_id],
'withUnknownLocations' => true,
]));

// we expect a total of 3 assets
expect(Asset::all())->toHaveCount(3);
// only two should be in the result
expect($response->original)->toHaveCount(2);
expect(Asset::all())->toHaveCount(2);

$tests = [
['types' => [$content->type_id]],
['groups' => [$content->type->group_id]],
['categories' => [$content->type->group->category_id]],
];
// we execpt no location

foreach ($tests as $test) {
$payload = array_merge($test, [
'character_ids' => [test()->test_character->character_id],
]);

$watchlist_response = test()->actingAs(test()->test_user)
->get(route('get.character.assets.locations', $payload));

expect($watchlist_response->original)->toHaveCount(1);

$watchlist_location_response = test()->actingAs(test()->test_user)
->get(route('location.assets', ['location_id' => $asset->location_id, ...$payload]));
// only two should be in the result
expect($response->original)->toHaveCount(1);

expect($watchlist_location_response->original)->toHaveCount(1);
}
$response->assertJson(
fn (\Illuminate\Testing\Fluent\AssertableJson $json) => $json
->count('data', 1)
->has(
'data.0',
fn ($json) => $json
->where('location_id', $asset->location_id)
->etc()
)
->etc()
);
});

0 comments on commit 543a335

Please sign in to comment.