Testing Guide: Customer SAV Status API
Prerequisitesβ
- API Token: Ensure you have a valid API token configured in the system
- Test Data: Have test customer emails and product SKUs available
- 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
- β
successistrue - β
hasSavistrue - β
totalSavmatches the count ofsavRecordsarray - β 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
productsarray - β 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
- β
successistrue - β
hasSavisfalse - β
totalSavis 0 - β
savRecordsis 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
- β
successisfalse - β 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
- β
successisfalse - β 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
- β
successistrue - β
hasSavisfalse(if no SAV for this product) - β
savRecordsis 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:
- Verify API token is configured correctly
- Check token is sent in
X-API-Tokenheader - Ensure token matches the one configured in
parameters.yml
Issue: 500 Internal Server Errorβ
Cause: Database connection or query issues Solution:
- Check application logs
- Verify database connection
- Check if SAV service is properly configured
- Review error message in response
Issue: Empty Resultsβ
Cause: No SAV records for customer/product Solution:
- Verify customer email is correct
- Check if customer has any SAV in database
- If filtering by product, ensure product exists in SAV
Issue: Slow Response Timesβ
Cause: Database performance or large result sets Solution:
- Add database indexes on frequently queried columns
- Consider implementing pagination
- Check database query performance
- Review application server resources
Next Stepsβ
After successful testing:
- β Document test results
- β Create monitoring alerts
- β Set up API usage analytics
- β Train support team
- β Update integration documentation
- β Deploy to production