Added api.response.headers to be included in all api responses.

This commit is contained in:
Abdulmhsen B. A. A.
2024-06-16 14:17:29 +03:00
parent ca32278a52
commit 53d89713bd
4 changed files with 58 additions and 10 deletions

View File

@@ -319,6 +319,17 @@ class HelpersTest extends TestCase
public function test_api_response(): void
{
Config::append([
'api' => [
'response' => [
'headers' => [
'Content-Type' => 'application/json',
'X-Application-Version' => fn() => getAppVersion(),
'Access-Control-Allow-Origin' => '*',
],
],
]
]);
$data = ['foo' => 'bar'];
$response = api_response(HTTP_STATUS::HTTP_OK, $data);
$this->assertSame(HTTP_STATUS::HTTP_OK->value, $response->getStatusCode());
@@ -329,6 +340,18 @@ class HelpersTest extends TestCase
public function test_error_response(): void
{
Config::append([
'api' => [
'response' => [
'headers' => [
'Content-Type' => 'application/json',
'X-Application-Version' => fn() => getAppVersion(),
'Access-Control-Allow-Origin' => '*',
],
],
]
]);
$data = ['error' => ['code' => HTTP_STATUS::HTTP_BAD_REQUEST->value, 'message' => 'error message']];
$response = api_error('error message', HTTP_STATUS::HTTP_BAD_REQUEST);
$this->assertSame(HTTP_STATUS::HTTP_BAD_REQUEST->value, $response->getStatusCode());