Skip to content

Commit

Permalink
Merge pull request #17 from innobraingmbh/feat/throw-on-stubs
Browse files Browse the repository at this point in the history
feat: add throw of on office exception to stub responses
  • Loading branch information
Katalam authored Oct 11, 2024
2 parents 310fa62 + 032dd09 commit f7feadf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog
## main
- Added a throw to stub responses

## v.1.2.7
- Added a query exception to filter repository
Expand Down
2 changes: 2 additions & 0 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ public function requestApi(OnOfficeRequest $request): Response
$request->identifier,
$request->parameters,
);
} else {
$this->getOnOfficeService()->throwIfResponseIsFailed($response);
}

$this->repository->recordRequestResponsePair($request, $response->json());
Expand Down
2 changes: 1 addition & 1 deletion src/Services/OnOfficeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public function requestAllChunked(
*
* @throws OnOfficeException
*/
private function throwIfResponseIsFailed(Response $response): void
public function throwIfResponseIsFailed(Response $response): void
{
$statusCode = $response->json('status.code', 500);
$statusErrorCode = $response->json('status.errorcode', 0);
Expand Down
20 changes: 20 additions & 0 deletions tests/Repositories/BaseRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Innobrain\OnOfficeAdapter\Dtos\OnOfficeRequest;
use Innobrain\OnOfficeAdapter\Dtos\OnOfficeResponse;
use Innobrain\OnOfficeAdapter\Enums\OnOfficeAction;
use Innobrain\OnOfficeAdapter\Enums\OnOfficeError;
use Innobrain\OnOfficeAdapter\Enums\OnOfficeResourceType;
use Innobrain\OnOfficeAdapter\Exceptions\OnOfficeException;
use Innobrain\OnOfficeAdapter\Facades\Testing\RecordFactories\BaseFactory;
use Innobrain\OnOfficeAdapter\Repositories\BaseRepository;

Expand Down Expand Up @@ -240,6 +242,24 @@

expect($result[2])->toBe(1);
});

it('can throw stub responses', function () {
$builder = new BaseRepository;

$builder->fake([
$builder->response([
$builder->page(
errorCodeResult: OnOfficeError::Unknown_Error_Occurred->value,
messageResult: OnOfficeError::Unknown_Error_Occurred->toString(),
),
]),
]);

$builder->query()->call(new OnOfficeRequest(
OnOfficeAction::Read,
OnOfficeResourceType::Estate,
));
})->throws(OnOfficeException::class, OnOfficeError::Unknown_Error_Occurred->toString());
});

describe('assert', function () {
Expand Down

0 comments on commit f7feadf

Please sign in to comment.