From 321cfefe2978cc96439f3656deb2cabe02b62467 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 8 Feb 2025 09:14:37 +0300 Subject: [PATCH] Replace PHP unit test with PEST test --- tests/Feature/DeepSeekClient.php | 52 +++++++++++++++++++++ tests/Feature/HandelResultDeepseekTest.php | 54 ---------------------- 2 files changed, 52 insertions(+), 54 deletions(-) create mode 100644 tests/Feature/DeepSeekClient.php delete mode 100644 tests/Feature/HandelResultDeepseekTest.php diff --git a/tests/Feature/DeepSeekClient.php b/tests/Feature/DeepSeekClient.php new file mode 100644 index 0000000..a0866e0 --- /dev/null +++ b/tests/Feature/DeepSeekClient.php @@ -0,0 +1,52 @@ +query('Hello DeepSeek, how are you today?') + ->setTemperature(1.5); + + // Act + $response = $client->run(); + $result = $client->getResult(); + + // Assert + expect($response)->not->toBeEmpty($response) + ->and($result->getStatusCode())->toEqual(HTTPState::OK->value); +}); + +test('Run query with valid API Key & insufficient balance should return 402', function () { + // Arrange + $apiKey = "insufficient-balance-api-key"; + $client = DeepSeekClient::build($apiKey) + ->query('Hello DeepSeek, how are you today?') + ->setTemperature(1.5); + + // Act + $response = $client->run(); + $result = $client->getResult(); + + // Assert + expect($response)->not->toBeEmpty($response) + ->and($result->getStatusCode())->toEqual(HTTPState::PAYMENT_REQUIRED->value); +}); + +test('Run query with invalid API key should return 401', function () { + // Arrange + $apiKey = "insufficient-balance-api-key"; + $client = DeepSeekClient::build($apiKey) + ->query('Hello DeepSeek, how are you today?') + ->setTemperature(1.5); + + // Act + $response = $client->run(); + $result = $client->getResult(); + + // Assert + expect($response)->not->toBeEmpty($response) + ->and($result->getStatusCode())->toEqual(HTTPState::UNAUTHORIZED->value); +}); diff --git a/tests/Feature/HandelResultDeepseekTest.php b/tests/Feature/HandelResultDeepseekTest.php deleted file mode 100644 index 9b2ab44..0000000 --- a/tests/Feature/HandelResultDeepseekTest.php +++ /dev/null @@ -1,54 +0,0 @@ -apiKey = "valid-api-key"; - $this->expiredApiKey = "expired-api-key"; - } - public function test_ok_response() - { - $deepseek = DeepSeekClient::build($this->apiKey) - ->query('Hello Deepseek, how are you today?') - ->setTemperature(1.5); - $response = $deepseek->run(); - $result = $deepseek->getResult(); - - $this->assertNotEmpty($response); - $this->assertEquals(HTTPState::OK->value, $result->getStatusCode()); - } - public function test_can_not_access_with_api_expired_payment() - { - $deepseek = DeepSeekClient::build($this->expiredApiKey) - ->query('Hello Deepseek, how are you today?') - ->setTemperature(1.5); - $response = $deepseek->run(); - $result = $deepseek->getResult(); - - $this->assertNotEmpty($response); - if(!$result->isSuccess()) - { - $this->assertEquals(HTTPState::PAYMENT_REQUIRED->value, $result->getStatusCode()); - } - } - public function test_access_with_wrong_api_key() - { - $deepseek = DeepSeekClient::build($this->apiKey."wrong-api-key") - ->query('Hello Deepseek, how are you today?') - ->setTemperature(1.5); - $response = $deepseek->run(); - $result = $deepseek->getResult(); - - $this->assertNotEmpty($response); - $this->assertEquals(HTTPState::UNAUTHORIZED->value, $result->getStatusCode()); - } -}