5.3 KiB
5.3 KiB
Panduan Testing & Verifikasi API
Cara Testing API
1. Test dengan cURL (Command Line)
Test Health Check
curl http://localhost:8000/health
Test Login
curl -X POST http://localhost:8000/timo/login \
-H "Content-Type: application/json" \
-d '{"username":"testuser","password":"testpass","fcm_token":"test_token"}'
Test Cek SL
curl -X POST http://localhost:8000/timo/cek_sl \
-H "Content-Type: application/json" \
-d '{"token":"1","no_sl":"123456"}'
Test Request Pembayaran
curl -X POST http://localhost:8000/timo/request_pembayaran \
-H "Content-Type: application/json" \
-d '{"token":"1","no_sl":"123456","nama_bank":"BCA","no_rek":"1234567890"}'
2. Test dengan Postman
- Import collection (jika ada)
- Atau buat request manual:
- Method: POST
- URL:
http://localhost:8000/timo/login - Headers:
Content-Type: application/json - Body (raw JSON):
{ "username": "testuser", "password": "testpass" }
3. Test dengan Browser (untuk GET request)
Buka browser dan akses:
http://localhost:8000/healthhttp://localhost:8000/timo/tagihan/123456
4. Bandingkan Response dengan API Lama
Cara Manual:
- Test endpoint di API lama:
http://timo.wipay.id/timo/login - Test endpoint di API baru:
http://localhost:8000/timo/login - Bandingkan response JSON-nya
Format Response yang Harus Sama:
{
"status": 200,
"pesan": "...",
"data": {...}
}
Checklist Verifikasi
✅ Format Response
- Status code sama (200, 300, 404)
- Field
statusada dan sama - Field
pesanada dan sama - Field
dataada (jika ada di API lama) - Field khusus (seperti
user,data_sl,wipay) ada di root level
✅ Data Response
- Struktur data sama
- Nama field sama
- Tipe data sama (string, number, array, object)
- Urutan field (jika penting)
✅ Error Handling
- Error message sama
- Status code error sama
- Format error response sama
Endpoint yang Perlu Di-test
Authentication
POST /timo/daftarPOST /timo/loginPOST /timo/login_tokenPOST /timo/update_akunPOST /timo/update_password
SL Management
POST /timo/cek_slPOST /timo/confirm_slPOST /timo/hapus_sl
Tagihan
GET /timo/history/{sl}/{periode}GET /timo/tagihan/{sl}
Pembayaran
POST /timo/request_pembayaranPOST /timo/cek_pembayaranPOST /timo/cek_transferPOST /timo/batal_pembayaranPOST /timo/confirm_pembayaranPOST /timo/history_bayar
Laporan
POST /timo/jenis_laporanPOST /timo/history_gangguan
WIPAY
POST /timo/cek_wipay
Reset Password
POST /timo/buat_kodePOST /timo/cek_kodePOST /timo/reset_kode
Upload
POST /timo/upload_catat_meterPOST /timo/upload_ppPOST /timo/hapus_ppPOST /timo/upload_gangguanPOST /timo/upload_pasang_baruPOST /timo/upload_bukti_transferPOST /timo/upload_baca_mandiri
Lainnya
POST /timo/promoPOST /timo/riwayat_pasangPOST /timo/jadwal_catat_meterPOST /timo/request_order_baca_mandiri
Tips Testing
- Gunakan Data Real: Test dengan data yang sama di API lama dan baru
- Test Error Cases: Test dengan data invalid, token salah, dll
- Test Success Cases: Test dengan data valid
- Bandingkan Side-by-Side: Buka 2 terminal/window untuk bandingkan response
- Gunakan JSON Formatter: Format JSON response untuk mudah dibaca
- Test dengan Aplikasi Mobile: Jika memungkinkan, test langsung dengan aplikasi mobile
Tools yang Bisa Digunakan
- cURL - Command line tool
- Postman - GUI tool untuk testing API
- Insomnia - Alternative untuk Postman
- HTTPie - User-friendly command line HTTP client
- Browser DevTools - Untuk test GET request
- jq - Untuk format JSON di terminal:
curl ... | jq
Contoh Test Script (Bash)
#!/bin/bash
BASE_URL="http://localhost:8000"
TOKEN="your_token_here"
echo "Testing Health Check..."
curl -s "$BASE_URL/health"
echo -e "\n\n"
echo "Testing Login..."
curl -s -X POST "$BASE_URL/timo/login" \
-H "Content-Type: application/json" \
-d '{"username":"test","password":"test"}' | jq
echo -e "\n\n"
echo "Testing Cek WIPAY..."
curl -s -X POST "$BASE_URL/timo/cek_wipay" \
-H "Content-Type: application/json" \
-d "{\"token\":\"$TOKEN\"}" | jq
echo -e "\n\n"
Catatan Penting
- Database: Pastikan database yang digunakan sama dengan API lama
- Environment: Pastikan environment variables sudah benar (.env)
- File Upload: Test upload dengan file real (base64 encoded)
- External API: Pastikan koneksi ke external API (timo.tirtaintan.co.id) berfungsi
- CORS: Pastikan CORS sudah di-enable jika test dari browser
Troubleshooting
Response berbeda dengan API lama?
- Cek format response di
RESPONSE_COMPARISON.md - Cek kode di controller yang sesuai
- Cek query database apakah sama
- Cek logic bisnis apakah sama
Error 500?
- Cek error log di
logs/atau PHP error log - Cek database connection
- Cek apakah semua dependency sudah terinstall
Response kosong?
- Cek apakah data ada di database
- Cek query database
- Cek apakah ada error di log