major refactor
- add request status to search instance API - use JSend-type response in elixForms clients - readjust namespaces - add more unit tests (manual HTTP requests too)
This commit is contained in:
@@ -2,8 +2,7 @@
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Api\Core\HttpClient;
|
||||
use ElixForms\Auth\ElixFormsApiClient;
|
||||
use ElixForms\Auth\ElixFormsRequestStatus;
|
||||
use ElixForms\Clients\ElixFormsApiClient;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ElixFormsApiClientTest extends TestCase
|
||||
@@ -32,16 +31,17 @@ final class ElixFormsApiClientTest extends TestCase
|
||||
};
|
||||
$client = new ElixFormsApiClient('https://example.test', $httpClient);
|
||||
|
||||
$requests = $client->lookupByStatus('MODULO TEST', 'token', 'user');
|
||||
$response = $client->lookupByStatus('MODULO TEST', 'token', 'user');
|
||||
|
||||
self::assertSame([['requestId' => 123]], $requests);
|
||||
self::assertSame('success', $response['status']);
|
||||
self::assertSame([['requestId' => 123]], $response['data']);
|
||||
self::assertStringNotContainsString('requestStatus=', $httpClient->url);
|
||||
self::assertStringContainsString('moduleTag=MODULO%20TEST', $httpClient->url);
|
||||
self::assertSame('Bearer token', $httpClient->headers['Authorization']);
|
||||
self::assertSame('user', $httpClient->headers['x-api-username']);
|
||||
}
|
||||
|
||||
public function testLookupByStatusExpandsCombinedFlags(): void
|
||||
public function testLookupByStatusExpandsCommaSeparatedStatuses(): void
|
||||
{
|
||||
$httpClient = new class extends HttpClient {
|
||||
public string $url = '';
|
||||
@@ -67,7 +67,7 @@ final class ElixFormsApiClientTest extends TestCase
|
||||
'MODULO',
|
||||
'token',
|
||||
'user',
|
||||
ElixFormsRequestStatus::IN_PROGRESS | ElixFormsRequestStatus::PROCESSED
|
||||
'IN_PROGRESS, PROCESSED'
|
||||
);
|
||||
|
||||
self::assertStringContainsString('requestStatus=IN_PROGRESS', $httpClient->url);
|
||||
@@ -75,11 +75,39 @@ final class ElixFormsApiClientTest extends TestCase
|
||||
self::assertStringContainsString('requestStatus=PROCESSED', $httpClient->url);
|
||||
}
|
||||
|
||||
public function testRequestStatusRejectsUnknownFlags(): void
|
||||
public function testLookupByStatusOmitsStatusesWhenTheValueIsEmpty(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$httpClient = new class extends HttpClient {
|
||||
public string $url = '';
|
||||
|
||||
ElixFormsRequestStatus::toApiValues(8);
|
||||
public function get(string $url, array $headers = [])
|
||||
{
|
||||
$this->url = $url;
|
||||
|
||||
return [
|
||||
'status' => 200,
|
||||
'json' => ['value' => ['globalStatus' => 'OK', 'requests' => []]],
|
||||
];
|
||||
}
|
||||
};
|
||||
$client = new ElixFormsApiClient('https://example.test', $httpClient);
|
||||
|
||||
$client->lookupByStatus('MODULO', 'token', 'user', ' ');
|
||||
|
||||
self::assertStringNotContainsString('requestStatus=', $httpClient->url);
|
||||
}
|
||||
|
||||
public function testLookupByStatusReturnsFailForAnUnknownStatus(): void
|
||||
{
|
||||
$httpClient = new HttpClient();
|
||||
$client = new ElixFormsApiClient('https://example.test', $httpClient);
|
||||
|
||||
$response = $client->lookupByStatus('MODULO', 'token', 'user', 'UNKNOWN');
|
||||
|
||||
self::assertSame([
|
||||
'status' => 'fail',
|
||||
'data' => ['requestStatuses' => 'Lo stato elixForms richiesto non è valido.'],
|
||||
], $response);
|
||||
}
|
||||
|
||||
public function testGetExportTagsSupportsVendorJsonContentTypeResponses(): void
|
||||
@@ -107,14 +135,15 @@ final class ElixFormsApiClientTest extends TestCase
|
||||
};
|
||||
$client = new ElixFormsApiClient('https://example.test/', $httpClient);
|
||||
|
||||
$tags = $client->getExportTags(42, 'MODULO', 'token', 'user');
|
||||
$response = $client->getExportTags(42, 'MODULO', 'token', 'user');
|
||||
|
||||
self::assertSame('success', $response['status']);
|
||||
self::assertSame(
|
||||
[['name' => 'contratto.id', 'value' => 'ABC-123']],
|
||||
$tags
|
||||
$response['data']
|
||||
);
|
||||
self::assertSame(
|
||||
'https://example.test/eF/services/api/request/42/view/_DEFAULT/exportTags/get/v1?moduleTag=MODULO&exportGroup=API',
|
||||
'https://example.test/services/api/request/42/view/_DEFAULT/exportTags/get/v1?moduleTag=MODULO&exportGroup=API',
|
||||
$httpClient->url
|
||||
);
|
||||
}
|
||||
@@ -146,12 +175,34 @@ final class ElixFormsApiClientTest extends TestCase
|
||||
self::assertStringContainsString('exportGroup=REPORT%20ORE', $httpClient->url);
|
||||
}
|
||||
|
||||
public function testGetExportTagsRejectsAnEmptyExportGroup(): void
|
||||
public function testGetExportTagsReturnsFailForAnEmptyExportGroup(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
$httpClient = new HttpClient();
|
||||
$client = new ElixFormsApiClient('https://example.test', $httpClient);
|
||||
$client->getExportTags(42, 'MODULO', 'token', 'user', ' ');
|
||||
$response = $client->getExportTags(42, 'MODULO', 'token', 'user', ' ');
|
||||
|
||||
self::assertSame([
|
||||
'status' => 'fail',
|
||||
'data' => ['exportGroup' => 'deve essere una stringa non vuota.'],
|
||||
], $response);
|
||||
}
|
||||
|
||||
public function testLookupByStatusReturnsErrorForAnUnsuccessfulHttpResponse(): void
|
||||
{
|
||||
$httpClient = new class extends HttpClient {
|
||||
public function get(string $url, array $headers = [])
|
||||
{
|
||||
return ['status' => 503];
|
||||
}
|
||||
};
|
||||
$client = new ElixFormsApiClient('https://example.test', $httpClient);
|
||||
|
||||
$response = $client->lookupByStatus('MODULO', 'token', 'user');
|
||||
|
||||
self::assertSame([
|
||||
'status' => 'error',
|
||||
'message' => 'Errore durante LookupByStatus.',
|
||||
'code' => 503,
|
||||
], $response);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user