Skip to content

Commit

Permalink
fix: null response will throw an error in requestAll
Browse files Browse the repository at this point in the history
  • Loading branch information
Katalam committed May 24, 2024
1 parent 54a8fc8 commit f7f3b7b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
## main

## v0.5.2
- The request all method will now check the response for extract ability of the response

## v0.5.1
- Added missing address fake builder country iso code type setter

Expand Down
5 changes: 4 additions & 1 deletion src/Services/OnOfficeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ public function requestAll(
$countAbsolute = $response->json($countPath, 0);
$maxPage = ceil($countAbsolute / $pageSize);
}
$responseResult = $response->json($resultPath);

$data->push(...$response->json($resultPath));
if (is_array($responseResult)) {
$data->push(...$responseResult);
}

$offset += $pageSize;
$currentPage = $offset / $pageSize;
Expand Down
35 changes: 35 additions & 0 deletions tests/Services/OnOfficeServiceTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -70,6 +71,40 @@
);
});
})->with([300, 301, 400, 401, 500, 501]);

it('can handle null in result path', function () {
Http::preventStrayRequests();
Http::fake([
'*' => Http::response([
'status' => [
'code' => 200,
],
'response' => [
'results' => [
[
'data' => [
'meta' => [
'cntabsolute' => 0,
],
],
],
],
]
]),
]);

$onOfficeService = app(OnOfficeService::class);

$response = $onOfficeService->requestAll(function () {
return app(OnOfficeService::class)->requestApi(
OnOfficeAction::Get,
OnOfficeResourceType::Estate,
);
});

expect($response)->toBeInstanceOf(Collection::class)
->toBeEmpty();
});
});

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

0 comments on commit f7f3b7b

Please sign in to comment.