Skip to content

Commit

Permalink
chore: add checks for error detail types on unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Orkuncakilkaya committed Aug 29, 2024
1 parent c2403cc commit 06c94c6
Showing 1 changed file with 60 additions and 8 deletions.
68 changes: 60 additions & 8 deletions test/FingerprintApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
namespace Fingerprint\ServerAPI;

use Fingerprint\ServerAPI\Api\FingerprintApi;
use Fingerprint\ServerAPI\Model\ErrorCommon403Response;
use Fingerprint\ServerAPI\Model\ErrorCommon429Response;
use Fingerprint\ServerAPI\Model\ErrorEvent404Response;
use Fingerprint\ServerAPI\Model\ErrorUpdateEvent400Response;
use Fingerprint\ServerAPI\Model\ErrorUpdateEvent409Response;
use Fingerprint\ServerAPI\Model\ErrorVisitor400Response;
use Fingerprint\ServerAPI\Model\ErrorVisitor404Response;
use Fingerprint\ServerAPI\Model\ErrorVisits403;
use Fingerprint\ServerAPI\Model\EventUpdateRequest;
use Fingerprint\ServerAPI\Model\IdentificationError;
use Fingerprint\ServerAPI\Model\ProductError;
use Fingerprint\ServerAPI\Model\TooManyRequestsResponse;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
Expand Down Expand Up @@ -361,7 +369,12 @@ public function testGetVisits403Error()
$this->expectException(ApiException::class);
$this->expectExceptionCode(403);

$this->fingerprint_api->getVisits(self::MOCK_VISITOR_ID_403_ERROR);
try {
$this->fingerprint_api->getVisits(self::MOCK_VISITOR_ID_403_ERROR);
} catch (ApiException $e) {
$this->assertEquals(ErrorVisits403::class, get_class($e->getErrorDetails()));
throw $e;
}
}

public function testGetVisits429Error()
Expand All @@ -372,7 +385,12 @@ public function testGetVisits429Error()
$this->expectException(ApiException::class);
$this->expectExceptionCode(429);

$this->fingerprint_api->getVisits(self::MOCK_VISITOR_ID_429_ERROR);
try {
$this->fingerprint_api->getVisits(self::MOCK_VISITOR_ID_429_ERROR);
} catch (ApiException $e) {
$this->assertEquals(TooManyRequestsResponse::class, get_class($e->getErrorDetails()));
throw $e;
}
}

public function testGetEvent403Error()
Expand All @@ -383,7 +401,12 @@ public function testGetEvent403Error()
$this->expectException(ApiException::class);
$this->expectExceptionCode(403);

$this->fingerprint_api->getEvent(self::MOCK_EVENT_ID_403_ERROR);
try {
$this->fingerprint_api->getEvent(self::MOCK_EVENT_ID_403_ERROR);
} catch (ApiException $e) {
$this->assertEquals(ErrorCommon403Response::class, get_class($e->getErrorDetails()));
throw $e;
}
}

public function testGetEvent404Error()
Expand All @@ -394,7 +417,14 @@ public function testGetEvent404Error()
$this->expectException(ApiException::class);
$this->expectExceptionCode(404);

$this->fingerprint_api->getEvent(self::MOCK_EVENT_ID_404_ERROR);
try {
$this->fingerprint_api->getEvent(self::MOCK_EVENT_ID_404_ERROR);
} catch (ApiException $e) {
$this->assertEquals(ErrorEvent404Response::class, get_class($e->getErrorDetails()));
$this->assertEquals("request id is not found", $e->getErrorDetails()->getError()->getMessage());
$this->assertEquals("RequestNotFound", $e->getErrorDetails()->getError()->getCode());
throw $e;
}
}

public function testDeleteVisitorData400Error()
Expand All @@ -405,7 +435,15 @@ public function testDeleteVisitorData400Error()
$this->expectException(ApiException::class);
$this->expectExceptionCode(400);

$this->fingerprint_api->deleteVisitorData(self::MOCK_VISITOR_ID_400_ERROR);
try {

$this->fingerprint_api->deleteVisitorData(self::MOCK_VISITOR_ID_400_ERROR);
} catch (ApiException $e) {
$this->assertEquals(ErrorVisitor400Response::class, get_class($e->getErrorDetails()));
$this->assertEquals("invalid visitor id", $e->getErrorDetails()->getError()->getMessage());
$this->assertEquals("RequestCannotBeParsed", $e->getErrorDetails()->getError()->getCode());
throw $e;
}
}

public function testDeleteVisitorData403Error()
Expand All @@ -416,7 +454,12 @@ public function testDeleteVisitorData403Error()
$this->expectException(ApiException::class);
$this->expectExceptionCode(403);

$this->fingerprint_api->deleteVisitorData(self::MOCK_VISITOR_ID_403_ERROR);
try {
$this->fingerprint_api->deleteVisitorData(self::MOCK_VISITOR_ID_403_ERROR);
} catch (ApiException $e) {
$this->assertEquals(ErrorCommon403Response::class, get_class($e->getErrorDetails()));
throw $e;
}
}

public function testDeleteVisitorData404Error()
Expand All @@ -430,6 +473,7 @@ public function testDeleteVisitorData404Error()
try {
$this->fingerprint_api->deleteVisitorData(self::MOCK_VISITOR_ID_404_ERROR);
} catch (ApiException $e) {
$this->assertEquals(ErrorVisitor404Response::class, get_class($e->getErrorDetails()));
$this->assertEquals("VisitorNotFound", $e->getErrorDetails()->getError()->getCode());

throw $e;
Expand All @@ -444,7 +488,12 @@ public function testDeleteVisitorData429Error()
$this->expectException(ApiException::class);
$this->expectExceptionCode(429);

$this->fingerprint_api->deleteVisitorData(self::MOCK_VISITOR_ID_429_ERROR);
try {
$this->fingerprint_api->deleteVisitorData(self::MOCK_VISITOR_ID_429_ERROR);
} catch (ApiException $e) {
$this->assertEquals(ErrorCommon429Response::class, get_class($e->getErrorDetails()));
throw $e;
}
}

public function testUpdateEvent400Error()
Expand All @@ -458,6 +507,7 @@ public function testUpdateEvent400Error()
try {
$this->fingerprint_api->updateEvent(new EventUpdateRequest([]), self::MOCK_EVENT_ID_400_ERROR);
} catch (ApiException $e) {
$this->assertEquals(ErrorUpdateEvent400Response::class, get_class($e->getErrorDetails()));
$this->assertEquals("RequestCannotBeParsed", $e->getErrorDetails()->getError()->getCode());
throw $e;
}
Expand All @@ -475,6 +525,7 @@ public function testUpdateEvent403Error()
try {
$this->fingerprint_api->updateEvent(new EventUpdateRequest([]), self::MOCK_EVENT_ID_403_ERROR);
} catch (ApiException $e) {
$this->assertEquals(ErrorCommon403Response::class, get_class($e->getErrorDetails()));
$this->assertEquals("TokenRequired", $e->getErrorDetails()->getError()->getCode());
throw $e;
}
Expand All @@ -491,7 +542,7 @@ public function testUpdateEvent404Error()
try {
$this->fingerprint_api->updateEvent(new EventUpdateRequest([]), self::MOCK_EVENT_ID_404_ERROR);
} catch (ApiException $e) {

$this->assertEquals(ErrorEvent404Response::class, get_class($e->getErrorDetails()));
$this->assertEquals("RequestNotFound", $e->getErrorDetails()->getError()->getCode());
throw $e;
}
Expand All @@ -508,6 +559,7 @@ public function testUpdateEvent409Error()
try {
$this->fingerprint_api->updateEvent(new EventUpdateRequest([]), self::MOCK_EVENT_ID_409_ERROR);
} catch (ApiException $e) {
$this->assertEquals(ErrorUpdateEvent409Response::class, get_class($e->getErrorDetails()));
$this->assertEquals("StateNotReady", $e->getErrorDetails()->getError()->getCode());
throw $e;
}
Expand Down

0 comments on commit 06c94c6

Please sign in to comment.