Mock API Test Rehberi
Hedef Kitle: Geliştirici, Admin
Sayfa Türü: Nasıl Yapılır
Genel Bakış
COS, bir dış veri kaynağını simüle eden mock KPI API'siyle birlikte gelir (tools/mock-kpi-api/). Gerçek bir BI aracı, veri ambarı veya izleme sistemine ihtiyaç duymadan pull entegrasyonlarını test etmek için kullanın.
Mock API şunları sunar:
- 5 auth modunun tamamını destekler (NONE, BEARER_TOKEN, BASIC_AUTH, API_KEY_HEADER, API_KEY_QUERY)
- Gerçekçi KPI verileri döndürür (gelir, NPS, churn vb.)
- Çoklu yanıt formatları sağlar (düz, iç içe, zaman serisi, sayfalanmış, çoklu metrik)
- Hata senaryolarını simüle eder (timeout, 500, rate limit)
Hızlı Başlangıç
cd tools/mock-kpi-api
npm install
npm start
# → http://localhost:4444
Otomatik yeniden yükleme ile geliştirme:
npm run dev
Kimlik Doğrulama
Tüm /api/* uç noktaları kimlik doğrulama gerektirir. Aşağıdaki yöntemlerden birini kullanın:
Bearer Token
curl -H "Authorization: Bearer mock-token-2024" \
http://localhost:4444/api/metrics/revenue
Basic Auth
curl -u "cosuser:cospass123" \
http://localhost:4444/api/metrics/revenue
API Key (Header)
curl -H "X-API-Key: mock-api-key-xyz" \
http://localhost:4444/api/metrics/revenue
API Key (Query Parametresi)
curl "http://localhost:4444/api/metrics/revenue?api_key=mock-api-key-xyz"
Auth Olmadan
Sunucuyu başlatırken AUTH_REQUIRED=false ortam değişkenini ayarlayın:
AUTH_REQUIRED=false npm start
Varsayılan Kimlik Bilgileri
| Mod | Bilgi | Değer |
|---|---|---|
| Bearer Token | Token | mock-token-2024 |
| Basic Auth | Kullanıcı adı | cosuser |
| Basic Auth | Şifre | cospass123 |
| API Key | Anahtar | mock-api-key-xyz |
Ortam değişkenleriyle geçersiz kılın: BEARER_TOKEN, BASIC_USER, BASIC_PASS, API_KEY.
Uç Noktalar
Düz Format — GET /api/metrics/:name
En basit format. Tek bir metrik değeri döndürür.
curl -H "Authorization: Bearer mock-token-2024" \
http://localhost:4444/api/metrics/revenue
Yanıt:
{
"metric": "revenue",
"value": 1250000,
"target": 1100000,
"forecast": 1180000,
"unit": "USD",
"achievementRate": 113.6,
"period": "2026-03",
"timestamp": "2026-03-06T10:00:00.000Z"
}
COS Yanıt Eşleme:
{ "actual": "$.value", "target": "$.target", "forecast": "$.forecast" }
İç İçe Format — GET /api/metrics/:name/detailed
Değerler data.metrics nesnesi içinde yer alır.
curl -H "Authorization: Bearer mock-token-2024" \
http://localhost:4444/api/metrics/nps/detailed
Yanıt:
{
"status": "success",
"data": {
"kpiName": "Net Promoter Score",
"metrics": {
"current": 72.5,
"target": 75.0,
"forecast": 73.8,
"achievementRate": 96.7
},
"metadata": {
"unit": "score",
"period": "2026-03",
"source": "mock-kpi-api"
}
}
}
COS Yanıt Eşleme:
{ "actual": "$.data.metrics.current", "target": "$.data.metrics.target" }
Zaman Serisi — GET /api/metrics/:name/timeseries
Geçmiş veri noktalarından oluşan bir dizi döndürür.
curl -H "Authorization: Bearer mock-token-2024" \
"http://localhost:4444/api/metrics/revenue/timeseries?months=3"
Yanıt:
{
"metric": "revenue",
"count": 3,
"series": [
{ "period": "2026-01", "target": 1100000, "value": 980000, "unit": "USD" },
{ "period": "2026-02", "target": 1150000, "value": 1120000, "unit": "USD" },
{ "period": "2026-03", "target": 1200000, "value": 1250000, "unit": "USD" }
]
}
COS Yanıt Eşleme (son değer):
{ "actual": "$.series[-1:].value", "target": "$.series[-1:].target" }
Sayfalanmış Format — GET /api/metrics/:name/paginated
page ve per_page query parametreleriyle sayfalanmış API'yi simüle eder.
curl -H "X-API-Key: mock-api-key-xyz" \
"http://localhost:4444/api/metrics/revenue/paginated?page=1&per_page=3"
COS Yanıt Eşleme:
{ "actual": "$.results[0].measurement", "target": "$.results[0].target" }
Dashboard Özeti — GET /api/dashboard/summary
Tüm metrikleri tek yanıtta toplar.
curl -H "Authorization: Bearer mock-token-2024" \
http://localhost:4444/api/dashboard/summary
COS Yanıt Eşleme (gelir için):
{ "actual": "$.kpis.revenue.actual", "target": "$.kpis.revenue.target" }
Hata Senaryoları
COS'un çeşitli hata durumlarını nasıl işlediğini test edin:
| Uç Nokta | Davranış |
|---|---|
GET /api/error/timeout | 10 saniye sonra yanıt verir (timeout testi) |
GET /api/error/500 | HTTP 500 Internal Server Error döndürür |
GET /api/error/rate-limit | HTTP 429 Too Many Requests döndürür |
Kullanılabilir Metrikler
| Ad | Açıklama | Değer Aralığı |
|---|---|---|
revenue | Aylık gelir | 800K – 1.5M USD |
customer-count | Aktif müşteriler | 4.000 – 6.500 |
nps | Net Promoter Score | 35 – 85 |
churn-rate | Aylık churn oranı | %1 – %8 |
employee-satisfaction | Çalışan memnuniyeti | %55 – %95 |
uptime | Sistem çalışma süresi | %95 – %99,99 |
conversion-rate | Web sitesi dönüşümü | %1 – %12 |
response-time | API yanıt süresi | 50 – 500 ms |
Herhangi bir özel isim de kullanılabilir (ör. /api/metrics/ozel-kpi-adim) — rastgele değer üretir.
COS Entegrasyon Kurulum Örneği
Mock API ile COS'ta test yapmak için:
1. Entegrasyon Uç Noktası Oluştur
| Alan | Değer |
|---|---|
| Ad | Mock KPI API |
| Base URL | http://localhost:4444 |
| Auth Türü | BEARER_TOKEN |
| Kimlik Bilgileri | { "token": "mock-token-2024" } |
2. KPI Bağlantısı Oluştur
| Alan | Değer |
|---|---|
| Path Eki | /api/metrics/revenue |
| HTTP Metodu | GET |
| Yanıt Eşleme | { "actual": "$.value", "target": "$.target" } |
| Cron İfadesi | 0 */6 * * * (her 6 saatte) |
3. Test (Kuru Çalışma)
Entegrasyonu doğrulamak için Test düğmesine tıklayın. Şunları görmelisiniz:
- HTTP Durumu: 200
- Çıkarılan değerler:
{ actual: 1250000, target: 1100000 }
Ortam Değişkenleri
| Değişken | Varsayılan | Açıklama |
|---|---|---|
PORT | 4444 | Sunucu portu |
BEARER_TOKEN | mock-token-2024 | Beklenen Bearer token |
BASIC_USER | cosuser | Basic auth kullanıcı adı |
BASIC_PASS | cospass123 | Basic auth şifresi |
API_KEY | mock-api-key-xyz | Beklenen API anahtarı |
AUTH_REQUIRED | true | Auth'u devre dışı bırakmak için false yapın |