Skip to content

Commit 9721576

Browse files
committed
fix: array to string in mission controller
1 parent 24b070a commit 9721576

3 files changed

Lines changed: 94 additions & 4 deletions

File tree

app/Http/Controllers/Api/Game/MissionController.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,14 @@ private function allowedFilters(): array
517517
}
518518
}),
519519
AllowedFilter::callback('blueprint_name', static function (Builder $query, mixed $value): void {
520+
if (! is_string($value) || $value === '') {
521+
return;
522+
}
523+
520524
$query->whereHas('blueprints', static function (Builder $q) use ($value): void {
521525
$q->where('game_blueprint_data.output_name', $value);
522526
});
523-
}),
527+
})->delimiter(''),
524528
AllowedFilter::callback('min_enemies', static function (Builder $query, mixed $value): void {
525529
if (! is_numeric($value)) {
526530
return;
@@ -550,11 +554,19 @@ private function allowedFilters(): array
550554
$query->where('reward_max', '<=', (int) $value);
551555
}),
552556
AllowedFilter::callback('title', static function (Builder $query, mixed $value): void {
557+
if (! is_string($value) || $value === '') {
558+
return;
559+
}
560+
553561
$query->whereLike('game_mission_data.title', "%{$value}%");
554-
}),
562+
})->delimiter(''),
555563
AllowedFilter::callback('description', static function (Builder $query, mixed $value): void {
564+
if (! is_string($value) || $value === '') {
565+
return;
566+
}
567+
556568
$query->whereLike('game_mission_data.description', "%{$value}%");
557-
}),
569+
})->delimiter(''),
558570
AllowedFilter::callback('query', static function (Builder $query, mixed $value): void {
559571
if (! is_string($value) || $value === '') {
560572
return;
@@ -565,9 +577,13 @@ private function allowedFilters(): array
565577
->orWhereLike('game_mission_data.description', "%{$value}%")
566578
->orWhereLike('game_mission_data.debug_name', "%{$value}%");
567579
});
568-
}),
580+
})->delimiter(''),
569581
AllowedFilter::exact('reward_scope', 'game_mission_data.reward_scope'),
570582
AllowedFilter::callback('location', static function (Builder $query, mixed $value): void {
583+
if (! is_string($value) || ! Str::isUuid($value)) {
584+
return;
585+
}
586+
571587
$query->whereHas('starmapLocations', static function (Builder $q) use ($value): void {
572588
$q->where('game_starmap_location_data.location_uuid', $value);
573589
});

tests/Feature/Api/Game/MissionFiltersTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
declare(strict_types=1);
44

5+
use App\Models\Game\BlueprintData;
56
use App\Models\Game\Faction;
7+
use App\Models\Game\ItemData;
68
use App\Models\Game\Mission\Mission;
79
use App\Models\Game\Mission\MissionData;
810

@@ -58,6 +60,69 @@
5860
],
5961
]);
6062

63+
describe('text filter values containing commas', function (): void {
64+
it('filters missions by title containing a comma', function (): void {
65+
MissionData::factory()->forVersion($this->version)->create(['title' => 'No Proof, No Problem']);
66+
MissionData::factory()->forVersion($this->version)->create(['title' => 'Stakeout']);
67+
68+
$response = $this->getJson('/api/missions?filter[title]='.urlencode('No Proof, No Problem'));
69+
70+
$response->assertSuccessful();
71+
$titles = collect($response->json('data'))->pluck('title');
72+
expect($titles)->toContain('No Proof, No Problem')
73+
->and($titles)->not->toContain('Stakeout');
74+
});
75+
76+
it('filters missions by description containing a comma', function (): void {
77+
MissionData::factory()->forVersion($this->version)->create([
78+
'title' => 'Delivery',
79+
'description' => 'Pick up, put down, repeat.',
80+
]);
81+
MissionData::factory()->forVersion($this->version)->create([
82+
'title' => 'Stakeout',
83+
'description' => 'Watch the door.',
84+
]);
85+
86+
$response = $this->getJson('/api/missions?filter[description]='.urlencode('Pick up, put down'));
87+
88+
$response->assertSuccessful();
89+
$titles = collect($response->json('data'))->pluck('title');
90+
expect($titles)->toContain('Delivery')
91+
->and($titles)->not->toContain('Stakeout');
92+
});
93+
94+
it('filters missions by blueprint name containing a comma', function (): void {
95+
$blueprintData = BlueprintData::factory()->create(['output_name' => 'MedPen, Box of']);
96+
$itemData = ItemData::factory()->for($this->version, 'gameVersion')->create();
97+
$missionData = MissionData::factory()->forVersion($this->version)->create(['title' => 'Crafts MedPens']);
98+
$missionData->blueprints()->attach($blueprintData->id, [
99+
'pool_uuid' => fake()->uuid(),
100+
'item_data_id' => $itemData->id,
101+
'chance' => 1.0,
102+
]);
103+
MissionData::factory()->forVersion($this->version)->create(['title' => 'Unrelated']);
104+
105+
$response = $this->getJson('/api/missions?filter[blueprint_name]='.urlencode('MedPen, Box of'));
106+
107+
$response->assertSuccessful();
108+
$titles = collect($response->json('data'))->pluck('title');
109+
expect($titles)->toContain('Crafts MedPens')
110+
->and($titles)->not->toContain('Unrelated');
111+
});
112+
113+
it('searches with the query filter containing a comma', function (): void {
114+
MissionData::factory()->forVersion($this->version)->create(['title' => 'No Proof, No Problem']);
115+
MissionData::factory()->forVersion($this->version)->create(['title' => 'Stakeout']);
116+
117+
$response = $this->getJson('/api/missions?filter[query]='.urlencode('No Proof, No Problem'));
118+
119+
$response->assertSuccessful();
120+
$titles = collect($response->json('data'))->pluck('title');
121+
expect($titles)->toContain('No Proof, No Problem')
122+
->and($titles)->not->toContain('Stakeout');
123+
});
124+
});
125+
61126
it('returns filters using star_systems data and accepts system suffix input', function (): void {
62127
$stantonFaction = Faction::factory()->create(['name' => 'Stanton Contractors']);
63128
$pyroFaction = Faction::factory()->create(['name' => 'Pyro Contractors']);

tests/Feature/Api/Game/MissionLocationFilterTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
$this->version = createDefaultGameVersion();
1212
});
1313

14+
it('ignores a location filter value that is not a uuid', function (): void {
15+
MissionData::factory()->forVersion($this->version)->create(['title' => 'Anywhere']);
16+
17+
$response = $this->getJson('/api/missions?filter[location]=monox');
18+
19+
$response->assertSuccessful();
20+
expect($response->json('data'))->toHaveCount(1);
21+
});
22+
1423
it('filters missions by starmap location uuid', function (): void {
1524
$location = StarmapLocation::factory()->create();
1625
$locationData = StarmapLocationData::factory()

0 commit comments

Comments
 (0)