From be441b8868a337d24c2e7f1773d2a44d20d3a119 Mon Sep 17 00:00:00 2001 From: moassaad Date: Sat, 1 Feb 2025 17:03:02 +0200 Subject: [PATCH 1/4] create: gitignore file and add ignore files and directories. --- .gitignore | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .gitignore 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/ From 8bc0f9d2626d3bc3541a0489eb454e6bf3200e95 Mon Sep 17 00:00:00 2001 From: moassaad Date: Sat, 1 Feb 2025 17:05:06 +0200 Subject: [PATCH 2/4] create: basic qwen test. --- tests/QwenTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/QwenTest.php 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 @@ + Date: Sat, 1 Feb 2025 17:07:25 +0200 Subject: [PATCH 3/4] update: add bad request code & forbidden code. --- src/Enums/Requests/HTTPState.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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; + } From f633570480db35e8b1d668d95d610e3b035fd858 Mon Sep 17 00:00:00 2001 From: moassaad Date: Sat, 1 Feb 2025 17:08:25 +0200 Subject: [PATCH 4/4] create: handel result qwen test. --- tests/HandelResultQwenTest.php | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/HandelResultQwenTest.php 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()); + } +}