Skip to content

Commit e07f315

Browse files
committed
failing test on index allowed fields
1 parent 2860635 commit e07f315

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

tests/Controllers/ProductsController.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ protected function modifyQuery(\Spatie\QueryBuilder\QueryBuilder $query): \Spati
3131

3232
return $query;
3333
}
34+
35+
/**
36+
* Get the index allowed fields
37+
*/
38+
public function getIndexAllowedFields(): array
39+
{
40+
return [
41+
'id',
42+
'name',
43+
];
44+
}
45+
3446
/**
3547
* Get the allowed fields
3648
*

tests/Feature/ApiControllerTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,23 @@ public function it_cannot_include_dynamic_fields_if_required_params_are_missing(
301301
'rating' => $product_2->id + 10,
302302
]);
303303
}
304+
305+
#[Test]
306+
public function it_does_not_include_fields_that_are_not_allowed(): void
307+
{
308+
$this->withoutExceptionHandling();
309+
310+
$product_1 = Product::factory()->create([
311+
'name' => 'Apple',
312+
'slug' => 'apple'
313+
]);
314+
315+
$this->getJson('/products')
316+
->assertJsonMissing([
317+
'slug' => 'apple',
318+
])
319+
->assertJsonFragment([
320+
'name' => 'Apple',
321+
]);
322+
}
304323
}

0 commit comments

Comments
 (0)