diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c5a6b38 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +build +vendor +tests/TestSupport/temp +tests/temp +composer.lock +phpunit.xml +.env +.phpunit.cache/ +.phpunit.result.cache +.phpunit.cache/test-results +.php-cs-fixer.cache +phpstan.neon +tests/Support/temp/ +.idea/ diff --git a/src/Enums/Requests/HTTPState.php b/src/Enums/Requests/HTTPState.php index 5e8171d..950e749 100644 --- a/src/Enums/Requests/HTTPState.php +++ b/src/Enums/Requests/HTTPState.php @@ -10,6 +10,12 @@ enum HTTPState: int */ case OK = 200; + /** + * HTTP client error response + * status is bad request + */ + case BAD_REQUEST = 400; + /** * HTTP client error response * status is unauthorized @@ -22,4 +28,10 @@ enum HTTPState: int */ case PAYMENT_REQUIRED = 402; + /** + * HTTP client error response + * status is forbidden + */ + case FORBIDDEN = 403; + } diff --git a/tests/HandelResultQwenTest.php b/tests/HandelResultQwenTest.php new file mode 100644 index 0000000..51797d9 --- /dev/null +++ b/tests/HandelResultQwenTest.php @@ -0,0 +1,55 @@ +apiKey = "valid-api-key"; + $this->expiredApiKey = "expired-api-key"; + } + + public function test_ok_response() + { + $qwen = QwenClient::build($this->apiKey) + ->query('Hello Qwen, how are you today?'); + $response = $qwen->run(); + $result = $qwen->getResult(); + + $this->assertNotEmpty($response); + $this->assertTrue($result->isSuccess()); + $this->assertEquals(HTTPState::OK->value, $result->getStatusCode()); + } + + public function test_can_not_access_with_api_expired_payment() + { + $qwen = QwenClient::build($this->expiredApiKey) + ->query('Hello Qwen, how are you today?'); + $response = $qwen->run(); + $result = $qwen->getResult(); + + $this->assertNotEmpty($response); + if(!$result->isSuccess()) + { + $this->assertEquals(HTTPState::BAD_REQUEST->value, $result->getStatusCode()); + } + } + + public function test_access_with_wrong_api_key() + { + $qwen = QwenClient::build($this->apiKey."wrong-api-key") + ->query('Hello Qwen, how are you today?'); + $response = $qwen->run(); + $result = $qwen->getResult(); + + $this->assertNotEmpty($response); + $this->assertEquals(HTTPState::UNAUTHORIZED->value, $result->getStatusCode()); + } +} diff --git a/tests/QwenTest.php b/tests/QwenTest.php new file mode 100644 index 0000000..a756750 --- /dev/null +++ b/tests/QwenTest.php @@ -0,0 +1,11 @@ +