Skip to main content

Testing Guide: Customer SAV Status API

Prerequisites​

  1. API Token: Ensure you have a valid API token configured in the system
  2. Test Data: Have test customer emails and product SKUs available
  3. API Client: Use curl, Postman, or any HTTP client

Quick Start Testing​

1. Basic Health Check​

First, verify the endpoint is accessible (should return 401 without token):

curl -X GET 'http://your-domain.com/api/customer/sav-status?email=test@example.com'

Expected Response:

{
"success": false,
"error": "Non autorisΓ©",
"message": "Token d'API manquant ou invalide"
}

2. Test with Valid Token​

Replace YOUR_API_TOKEN with your actual API token:

curl -X GET \
'http://your-domain.com/api/customer/sav-status?email=test@example.com' \
-H 'X-API-Token: YOUR_API_TOKEN'

Expected Response (customer without SAV):

{
"success": true,
"customerEmail": "test@example.com",
"productSku": null,
"hasSav": false,
"totalSav": 0,
"savRecords": []
}

Expected Response (customer with SAV):

{
"success": true,
"customerEmail": "test@example.com",
"productSku": null,
"hasSav": true,
"totalSav": 2,
"savRecords": [
{
"savId": 123,
"status": 1,
"statusLabel": "ValidΓ©",
"saleRef": "ORDER123",
...
}
]
}

3. Test with Product Filter​

Filter SAV records by specific product:

curl -X GET \
'http://your-domain.com/api/customer/sav-status?email=test@example.com&product_sku=SKU123' \
-H 'X-API-Token: YOUR_API_TOKEN'

Test Scenarios​

Scenario 1: Customer with Multiple SAV Records​

Test Case: Retrieve all SAV records for a customer

curl -X GET \
'http://your-domain.com/api/customer/sav-status?email=customer-with-sav@example.com' \
-H 'X-API-Token: YOUR_API_TOKEN' \
-H 'Accept: application/json'

Validation Points:

  • βœ… HTTP status code is 200
  • βœ… success is true
  • βœ… hasSav is true
  • βœ… totalSav matches the count of savRecords array
  • βœ… Each SAV record contains expected fields
  • βœ… Products array is populated for each SAV

Scenario 2: Customer with SAV for Specific Product​

Test Case: Filter SAV records by product SKU

curl -X GET \
'http://your-domain.com/api/customer/sav-status?email=customer@example.com&product_sku=PRODUCT123' \
-H 'X-API-Token: YOUR_API_TOKEN'

Validation Points:

  • βœ… Only SAV records containing the specified product are returned
  • βœ… Each returned SAV has the product in its products array
  • βœ… Other products in the same SAV are also included

Scenario 3: Customer with No SAV​

Test Case: Customer with no SAV history

curl -X GET \
'http://your-domain.com/api/customer/sav-status?email=new-customer@example.com' \
-H 'X-API-Token: YOUR_API_TOKEN'

Validation Points:

  • βœ… HTTP status code is 200
  • βœ… success is true
  • βœ… hasSav is false
  • βœ… totalSav is 0
  • βœ… savRecords is an empty array

Scenario 4: Invalid Email Format​

Test Case: Missing email parameter

curl -X GET \
'http://your-domain.com/api/customer/sav-status' \
-H 'X-API-Token: YOUR_API_TOKEN'

Validation Points:

  • βœ… HTTP status code is 400
  • βœ… success is false
  • βœ… Error message indicates missing email parameter

Scenario 5: Invalid API Token​

Test Case: Request without or with invalid token

curl -X GET \
'http://your-domain.com/api/customer/sav-status?email=test@example.com' \
-H 'X-API-Token: INVALID_TOKEN'

Validation Points:

  • βœ… HTTP status code is 401
  • βœ… success is false
  • βœ… Error indicates authentication failure

Scenario 6: Non-existent Product SKU​

Test Case: Filter by product that doesn't exist or has no SAV

curl -X GET \
'http://your-domain.com/api/customer/sav-status?email=test@example.com&product_sku=NONEXISTENT' \
-H 'X-API-Token: YOUR_API_TOKEN'

Validation Points:

  • βœ… HTTP status code is 200
  • βœ… success is true
  • βœ… hasSav is false (if no SAV for this product)
  • βœ… savRecords is empty or doesn't include this product

Automated Testing Script​

Save this as test_sav_api.sh:

#!/bin/bash

# Configuration
API_URL="http://your-domain.com/api/customer/sav-status"
API_TOKEN="YOUR_API_TOKEN"
TEST_EMAIL="test@example.com"
TEST_SKU="SKU123"

echo "Testing Customer SAV Status API"
echo "================================"

# Test 1: Valid request
echo -e "\n1. Testing valid request..."
curl -s -X GET "${API_URL}?email=${TEST_EMAIL}" \
-H "X-API-Token: ${API_TOKEN}" | jq '.'

# Test 2: Missing email
echo -e "\n2. Testing missing email parameter..."
curl -s -X GET "${API_URL}" \
-H "X-API-Token: ${API_TOKEN}" | jq '.'

# Test 3: Invalid token
echo -e "\n3. Testing invalid token..."
curl -s -X GET "${API_URL}?email=${TEST_EMAIL}" \
-H "X-API-Token: INVALID" | jq '.'

# Test 4: With product filter
echo -e "\n4. Testing with product filter..."
curl -s -X GET "${API_URL}?email=${TEST_EMAIL}&product_sku=${TEST_SKU}" \
-H "X-API-Token: ${API_TOKEN}" | jq '.'

echo -e "\nTesting complete!"

Make executable and run:

chmod +x test_sav_api.sh
./test_sav_api.sh

Postman Collection​

Import this JSON into Postman for easy testing:

{
"info": {
"name": "Customer SAV Status API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Get Customer SAV Status - All",
"request": {
"method": "GET",
"header": [
{
"key": "X-API-Token",
"value": "{{api_token}}",
"type": "text"
}
],
"url": {
"raw": "{{base_url}}/api/customer/sav-status?email={{customer_email}}",
"host": ["{{base_url}}"],
"path": ["api", "customer", "sav-status"],
"query": [
{
"key": "email",
"value": "{{customer_email}}"
}
]
}
}
},
{
"name": "Get Customer SAV Status - By Product",
"request": {
"method": "GET",
"header": [
{
"key": "X-API-Token",
"value": "{{api_token}}",
"type": "text"
}
],
"url": {
"raw": "{{base_url}}/api/customer/sav-status?email={{customer_email}}&product_sku={{product_sku}}",
"host": ["{{base_url}}"],
"path": ["api", "customer", "sav-status"],
"query": [
{
"key": "email",
"value": "{{customer_email}}"
},
{
"key": "product_sku",
"value": "{{product_sku}}"
}
]
}
}
}
]
}

Performance Testing​

Load Testing with Apache Bench​

Test endpoint performance:

ab -n 100 -c 10 -H "X-API-Token: YOUR_API_TOKEN" \
"http://your-domain.com/api/customer/sav-status?email=test@example.com"

What to monitor:

  • Requests per second
  • Time per request
  • Failed requests (should be 0)
  • Response times (95th percentile)

Expected Performance:​

  • Response time: < 500ms for typical queries
  • Throughput: > 50 requests/second
  • Error rate: 0%

Integration Testing​

PHP Unit Test Example​

<?php

namespace Tests\AppBundle\Api;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class MenzzoChatbotWrapperApiControllerTest extends WebTestCase
{
public function testGetCustomerSavStatusWithValidEmail()
{
$client = static::createClient();

$client->request(
'GET',
'/api/customer/sav-status',
['email' => 'test@example.com'],
[],
['HTTP_X-API-Token' => 'valid_token']
);

$this->assertEquals(200, $client->getResponse()->getStatusCode());

$data = json_decode($client->getResponse()->getContent(), true);
$this->assertTrue($data['success']);
$this->assertArrayHasKey('savRecords', $data);
}

public function testGetCustomerSavStatusWithoutToken()
{
$client = static::createClient();

$client->request(
'GET',
'/api/customer/sav-status',
['email' => 'test@example.com']
);

$this->assertEquals(401, $client->getResponse()->getStatusCode());
}

public function testGetCustomerSavStatusWithoutEmail()
{
$client = static::createClient();

$client->request(
'GET',
'/api/customer/sav-status',
[],
[],
['HTTP_X-API-Token' => 'valid_token']
);

$this->assertEquals(400, $client->getResponse()->getStatusCode());
}
}

Troubleshooting​

Issue: 401 Unauthorized​

Cause: Invalid or missing API token Solution:

  1. Verify API token is configured correctly
  2. Check token is sent in X-API-Token header
  3. Ensure token matches the one configured in parameters.yml

Issue: 500 Internal Server Error​

Cause: Database connection or query issues Solution:

  1. Check application logs
  2. Verify database connection
  3. Check if SAV service is properly configured
  4. Review error message in response

Issue: Empty Results​

Cause: No SAV records for customer/product Solution:

  1. Verify customer email is correct
  2. Check if customer has any SAV in database
  3. If filtering by product, ensure product exists in SAV

Issue: Slow Response Times​

Cause: Database performance or large result sets Solution:

  1. Add database indexes on frequently queried columns
  2. Consider implementing pagination
  3. Check database query performance
  4. Review application server resources

Next Steps​

After successful testing:

  1. βœ… Document test results
  2. βœ… Create monitoring alerts
  3. βœ… Set up API usage analytics
  4. βœ… Train support team
  5. βœ… Update integration documentation
  6. βœ… Deploy to production