Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dvlpp committed Jan 3, 2025
1 parent 92eb695 commit 97aeb6c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Http/Controllers/Api/ApiFormAutocompleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private function checkEndpoint(string $requestEndpoint, string $fieldEndpoint):
{
collect(Route::getRoutes()->getRoutes())
->map(fn ($route) => url($route->uri))
->filter(fn ($routeUrl) => $routeUrl == $requestEndpoint)
->filter(fn ($routeUrl) => $routeUrl == str($requestEndpoint)->before('?'))
->count() > 0 ?: throw new SharpInvalidConfigException('The endpoint is not a valid internal route.');

preg_match(
Expand Down
28 changes: 28 additions & 0 deletions tests/Http/Api/ApiFormAutocompleteControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,34 @@ public function buildFormFields(FieldsContainer $formFields): void
]);
})->throws(\Code16\Sharp\Exceptions\SharpInvalidConfigException::class);

it('allows internal remote endpoint with a querystring', function () {
$this->withoutExceptionHandling();

fakeFormFor('person', new class() extends PersonForm
{
public function buildFormFields(FieldsContainer $formFields): void
{
$formFields->addField(
SharpFormAutocompleteRemoteField::make('autocomplete_field')
->setRemoteMethodPOST()
->setRemoteEndpoint('/my/endpoint')
);
}
});

Route::post('/my/endpoint', fn () => []);

$this
->postJson(route('code16.sharp.api.form.autocomplete.index', [
'entityKey' => 'person',
'autocompleteFieldKey' => 'autocomplete_field',
]), [
'endpoint' => url('my/endpoint?param1=one'),
'search' => 'my search',
])
->assertOk();
});

it('allows to call an functional endpoint for a remote autocomplete field in an embed of an Editor field', function () {
fakeFormFor('person', new class() extends PersonForm
{
Expand Down

0 comments on commit 97aeb6c

Please sign in to comment.