diff --git a/src/Services/OnOfficeService.php b/src/Services/OnOfficeService.php index 34649f7..97314b8 100644 --- a/src/Services/OnOfficeService.php +++ b/src/Services/OnOfficeService.php @@ -91,7 +91,7 @@ public function retryOnlyOnConnectionError(): bool * * Read more: https://apidoc.onoffice.de/onoffice-api-request/request-elemente/action/#hmac */ - public function getHmac(OnOfficeAction $actionId, OnOfficeResourceType $resourceType): string + public function getHmac(OnOfficeAction $actionId, OnOfficeResourceType|string $resourceType): string { return base64_encode( hash_hmac( @@ -101,7 +101,9 @@ public function getHmac(OnOfficeAction $actionId, OnOfficeResourceType $resource [ 'timestamp' => Carbon::now()->timestamp, 'token' => $this->getToken(), - 'resourcetype' => $resourceType->value, + 'resourcetype' => $resourceType instanceof OnOfficeResourceType + ? $resourceType->value + : $resourceType, 'actionid' => $actionId->value, ] ), diff --git a/tests/Repositories/BaseRepositoryTest.php b/tests/Repositories/BaseRepositoryTest.php index e01c186..9da5b21 100644 --- a/tests/Repositories/BaseRepositoryTest.php +++ b/tests/Repositories/BaseRepositoryTest.php @@ -437,6 +437,25 @@ Http::assertSentCount(1); }); + + it('will call with string as resource type', function (){ + Http::preventStrayRequests(); + Http::fake([ + 'https://api.onoffice.de/api/stable/api.php/' => Http::response([ + 'status' => [ + 'code' => 200, + ], + ]), + ]); + + $builder = new BaseRepository; + + $request = new OnOfficeRequest(OnOfficeAction::Read, 'estate'); + + $builder->query()->call($request); + + Http::assertSentCount(1); + }); }); describe('middlewares', function () { diff --git a/tests/Services/OnOfficeServiceTest.php b/tests/Services/OnOfficeServiceTest.php index 35517d7..cc286f6 100644 --- a/tests/Services/OnOfficeServiceTest.php +++ b/tests/Services/OnOfficeServiceTest.php @@ -337,6 +337,30 @@ expect($response)->toBeInstanceOf(Collection::class) ->toHaveCount(1); }); + + it('can handle string resource type', function (){ + Http::preventStrayRequests(); + Http::fake([ + '*' => Http::response([ + 'status' => [ + 'code' => 200, + ], + ]), + ]); + + $onOfficeService = app(OnOfficeService::class); + + $request = new OnOfficeRequest( + OnOfficeAction::Get, + 'estate', + ); + + $onOfficeService->requestAll(function () use ($request) { + return app(OnOfficeService::class)->requestApi($request); + }, limit: 1); + + Http::assertSentCount(1); + }); }); describe('requestAllChunked', function () {