Skip to content

Commit

Permalink
T-004: Integrate and Test Product API Endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-ghenov committed Mar 4, 2024
1 parent 8c033bd commit caa2078
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ API_BASE_URL=your_api_base_url
API_USER=your_api_username
API_PASSWORD=your_api_password
API_SECRET=your_api_secret
API_PRODUCT_ID=your_api_product_id
API_DESTINATION_PHONE_NUMBER=your_api_destination_phone_number
2 changes: 2 additions & 0 deletions src/Service/ProductService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function __construct(ApiClient $apiClient) {
*
* @return array
* The products.
* @throws \Exception
*/
public function getAllProducts(): array {
$endpoint = 'WSGetTopUpProducts';
Expand All @@ -50,6 +51,7 @@ public function getAllProducts(): array {
*
* @return array
* The product.
* @throws \Exception
*/
public function getProductById(int $productID): mixed {
$endpoint = "WSGetSingleTopUpProduct";
Expand Down
4 changes: 0 additions & 4 deletions tests/Api/ApiClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ public function testWSLoginFailure() {
'Password' => 'incorrectPassword',
]);

// Debugging output (use sparingly).
echo "Response: ";
var_dump($response);

// Assert the response indicates a failed login.
$this->assertArrayHasKey(
'AccessCode', $response, "Response does not contain AccessCode"
Expand Down
63 changes: 63 additions & 0 deletions tests/Service/ProductServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
namespace QuickTopUpAPI\Tests\Service;

use PHPUnit\Framework\TestCase;
use QuickTopUpAPI\Api\ApiClient;
use QuickTopUpAPI\Service\ProductService;

/**
* Class ProductTest
*
* @package QuickTopUpAPI\Tests\Service
*
* A test case for the ProductService class.
*/
class ProductServiceTest extends TestCase {

/**
* @var ProductService
*
* The product service.
*/
private ProductService $productService;

/**
* @var string
*
* The API product ID.
*/
private $apiProductID;

/**
* Test the getProductById method.
*/
public function testGetProductById() {

// Attempt to fetch the product by ID.
$product = $this->productService->getProductById($this->apiProductID);

// Display the response for debugging purposes.
echo "Response: ";
var_dump($product);

// You might want to adjust these assertions based on
// the expected product structure.
$this->assertIsArray($product);
$this->assertArrayHasKey('Product', $product);
$this->assertEquals($this->apiProductID , $product['Product']);
}

/**
* Set up the test case.
*/
protected function setUp(): void {
$apiClient = new ApiClient();

// Instantiate ProductService with the real ApiClient.
$this->productService = new ProductService($apiClient);

// Set the API product ID.
$this->apiProductID = $_ENV['API_PRODUCT_ID'];
}

}

0 comments on commit caa2078

Please sign in to comment.