Vai al contenuto

🧪 Testing e Sviluppo

Ambiente Staging

Base URL: https://staging.salabam.com

Credenziali Test:

Username: test-partner
Password: [fornita via email]

Dipendente Test:

{
  "employee": {
    "id": "TEST001",
    "name": "Test",
    "surname": "User",
    "email": "test@example.com",
    "fiscalCode": "RSSMRA85M01H501X",
    "availability": 1000.00
  }
}

Test Checklist

  • [ ] JWT generation con firma corretta
  • [ ] Gestione timeout 25 secondi
  • [ ] Validazione credito disponibile
  • [ ] Response HTTP 200 per successo
  • [ ] Response HTTP 402 per credito insufficiente
  • [ ] Idempotenza chiamate (doppia conferma)
  • [ ] Gestione beneficiari (3 scenari)
  • [ ] Redirect utente post-SSO
  • [ ] Logging transazioni
  • [ ] Rollback in caso di errore

Test dei 3 Scenari Beneficiari

Test Scenario 1: Campo Omesso (Libero)

$payload = [
    'data' => [
        'employee' => $employeeData
        // beneficiaries NON presente
    ]
];
// Risultato atteso: form libero per inserimento beneficiario

Test Scenario 2: Campo Vuoto (Solo Employee)

$payload = [
    'data' => [
        'employee' => $employeeData,
        'beneficiaries' => (object)[]  // oggetto vuoto
    ]
];
// Risultato atteso: solo employee selezionabile

Test Scenario 3: Array Beneficiari

$payload = [
    'data' => [
        'employee' => $employeeData,
        'beneficiaries' => [
            ['id' => 'B001', 'name' => 'Laura', 'surname' => 'Rossi'],
            ['id' => 'B002', 'name' => 'Marco', 'surname' => 'Verdi']
        ]
    ]
];
// Risultato atteso: employee + lista beneficiari

Testing Callback Autorizzazione

Test Credito Sufficiente

# Simula richiesta autorizzazione
curl -X POST https://yourdomain.com/api/authorize \
  -H "Content-Type: application/json" \
  -d '{
    "message": "order authorization request",
    "jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
  }'

# Response attesa: HTTP 200
{
  "status": "success",
  "message": "order authorized"
}

Test Credito Insufficiente

# Response attesa: HTTP 402
{
  "status": "error",
  "message": "insufficient credit",
  "available": 50.00,
  "required": 100.00
}

Test Doppia Conferma

1. Autorizzazione

// orderAuthUrl chiamato da Salabam
app.post('/api/authorize', (req, res) => {
    // Congela credito
    freezeCredit(userId, amount);
    res.status(200).json({status: 'success'});
});

2. Conferma (entro 6 ore)

// orderConfirmUrl chiamato da Salabam
app.post('/api/confirm', (req, res) => {
    // Addebita definitivamente
    deductCredit(userId, amount);
    res.status(200).json({status: 'success'});
});

3. Revoca (se necessario)

// orderRevokeUrl chiamato da Salabam
app.post('/api/revoke', (req, res) => {
    // Rilascia credito congelato
    unfreezeCredit(userId, amount);
    res.status(200).json({status: 'success'});
});

Test Performance

Verifica Timeout

function testTimeout() {
    $start = microtime(true);

    // Simula processamento
    handleAuthCallback();

    $duration = microtime(true) - $start;

    if ($duration > 25) {
        throw new Exception("Timeout: {$duration}s > 25s");
    }
}

Test con Cache

function testWithCache() {
    // Prima chiamata - popola cache
    $t1 = microtime(true);
    getUserCredit('TEST001');
    $time1 = microtime(true) - $t1;

    // Seconda chiamata - da cache
    $t2 = microtime(true);
    getUserCredit('TEST001');
    $time2 = microtime(true) - $t2;

    assert($time2 < $time1 / 10); // Cache 10x più veloce
}

Logging per Debug

function logAuthRequest($data) {
    error_log("=== AUTH REQUEST ===");
    error_log("Timestamp: " . date('Y-m-d H:i:s'));
    error_log("Employee ID: " . $data->id);
    error_log("Beneficiary ID: " . ($data->id === '0' ? 'FREE CHOICE' : $data->id));
    error_log("Relation: " . $data->relation);
    error_log("Product: " . $data->productName);
    error_log("Price: €" . $data->price);
    error_log("Reference: " . $data->salabamReferenceId);
    error_log("==================");
}

Checklist Pre-Produzione

  • [ ] JWT: Chiave segreta sicura (min 32 caratteri)
  • [ ] SSL: Certificato valido su tutti gli endpoint
  • [ ] Timeout: Handler per chiamate < 25 secondi
  • [ ] Idempotenza: Gestione chiamate duplicate
  • [ ] Logging: Tracciamento completo transazioni
  • [ ] Monitoring: Alert per errori ricorrenti
  • [ ] Backup: Piano di rollback crediti
  • [ ] Beneficiari: Test dei 3 scenari
  • [ ] Cache: Ottimizzazione query ricorrenti
  • [ ] Rate Limiting: Protezione DoS