Skip to content

Commit

Permalink
Merge pull request #51 from tailflow/next
Browse files Browse the repository at this point in the history
Release v1.2.4
  • Loading branch information
alexzarbn authored Feb 4, 2021
2 parents 8cb6ec1 + 43eb296 commit d374253
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Drivers/Standard/ParamsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function validateFilters(Request $request): void
'filters.*.type' => ['sometimes', 'in:and,or'],
'filters.*.field' => ['required_with:filters', 'regex:/^[\w.]+$/', new WhitelistedField($this->filterableBy)],
'filters.*.operator' => ['required_with:filters', 'in:<,<=,>,>=,=,!=,like,not like,in,not in'],
'filters.*.value' => ['required_with:filters', 'nullable']
'filters.*.value' => ['present', 'nullable']
])->validate();
}

Expand Down
21 changes: 21 additions & 0 deletions tests/Feature/StandardIndexFilteringOperationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Orion\Tests\Feature;

use Carbon\Carbon;
use Illuminate\Support\Facades\Gate;
use Orion\Tests\Fixtures\App\Models\Company;
use Orion\Tests\Fixtures\App\Models\Post;
Expand Down Expand Up @@ -319,4 +320,24 @@ public function getting_a_list_of_resources_filtered_by_relation_field_with_wild
$this->makePaginator([$matchingTeam], 'teams/search')
);
}

/** @test */
public function getting_a_list_of_resources_filtered_by_model_field_using_nullable_value(): void
{
$matchingPost = factory(Post::class)->create(['publish_at' => null])->fresh();
factory(Post::class)->create(['publish_at' => Carbon::now()])->fresh();

Gate::policy(Post::class, GreenPolicy::class);

$response = $this->post('/api/posts/search', [
'filters' => [
['field' => 'publish_at', 'operator' => '=', 'value' => null]
]
]);

$this->assertResourcesPaginated(
$response,
$this->makePaginator([$matchingPost], 'posts/search')
);
}
}
2 changes: 1 addition & 1 deletion tests/Fixtures/app/Http/Controllers/PostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function sortableBy() : array

protected function filterableBy() : array
{
return ['title', 'position', 'user.name'];
return ['title', 'position', 'publish_at', 'user.name'];
}

protected function searchableBy() : array
Expand Down

0 comments on commit d374253

Please sign in to comment.