Skip to content

Commit

Permalink
feat: enable search request in EstateBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
kauffinger committed Nov 6, 2024
1 parent 42b6de0 commit 9faed94
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Query/EstateBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
use Illuminate\Support\Collection;
use Innobrain\OnOfficeAdapter\Dtos\OnOfficeRequest;
use Innobrain\OnOfficeAdapter\Enums\OnOfficeAction;
use Innobrain\OnOfficeAdapter\Enums\OnOfficeResourceId;
use Innobrain\OnOfficeAdapter\Enums\OnOfficeResourceType;
use Innobrain\OnOfficeAdapter\Exceptions\OnOfficeException;
use Innobrain\OnOfficeAdapter\Query\Concerns\Input;
use Innobrain\OnOfficeAdapter\Services\OnOfficeService;
use Throwable;

class EstateBuilder extends Builder
{
use Input;

/**
* @throws OnOfficeException
*/
Expand Down Expand Up @@ -128,4 +132,24 @@ public function create(array $data): array
return $this->requestApi($request)
->json('response.results.0.data.records.0');
}

/**
* @throws OnOfficeException
*/
public function search(): Collection
{
$request = new OnOfficeRequest(
OnOfficeAction::Get,
OnOfficeResourceType::Search,
OnOfficeResourceId::Estate,
parameters: [
OnOfficeService::INPUT => $this->input,
OnOfficeService::SORTBY => data_get(array_keys($this->orderBy), 0),
OnOfficeService::SORTORDER => data_get($this->orderBy, 0),
...$this->customParameters,
],
);

return $this->requestAll($request);
}
}
30 changes: 30 additions & 0 deletions tests/Repositories/EstateRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
declare(strict_types=1);

use Illuminate\Support\Facades\Http;
use Innobrain\OnOfficeAdapter\Dtos\OnOfficeRequest;
use Innobrain\OnOfficeAdapter\Enums\OnOfficeAction;
use Innobrain\OnOfficeAdapter\Enums\OnOfficeResourceId;
use Innobrain\OnOfficeAdapter\Enums\OnOfficeResourceType;
use Innobrain\OnOfficeAdapter\Facades\EstateRepository;
use Innobrain\OnOfficeAdapter\Facades\Testing\RecordFactories\EstateFactory;
use Innobrain\OnOfficeAdapter\Tests\Stubs\ReadEstateResponse;
Expand Down Expand Up @@ -61,3 +65,29 @@
EstateRepository::assertSentCount(3);
});
});

describe('search', function () {
it('should be able to build a search request', function () {
Http::preventStrayRequests();
Http::fake([
'https://api.onoffice.de/api/stable/api.php/' => Http::sequence([
ReadEstateResponse::make(),
]),
]);

EstateRepository::record();

$builder = EstateRepository::query();
$builder
->setInput('testInput')
->search();

EstateRepository::assertSentCount(1);
EstateRepository::assertSent(function (OnOfficeRequest $request) {
return $request->resourceId === OnOfficeResourceId::Estate
&& $request->actionId === OnOfficeAction::Get
&& $request->resourceType === OnOfficeResourceType::Search
&& $request->parameters['input'] === 'testInput';
});
});
});

0 comments on commit 9faed94

Please sign in to comment.