PHP 8.2.30
Preview: test-otp-dev.js Size: 6.32 KB
/home/byroehnu/easepay.easetack.com/test-otp-dev.js

/**
 * OTP.dev API Testing Script
 * Tests the real OTP.dev integration with your API key
 */

const fetch = require('node-fetch');

const BASE_URL = 'http://localhost:5004';
const API_KEY = '22d4d23b0ff4a8bd5b9835c2d0ab66da';

// Test configuration
const TEST_PHONE = '2348143640561'; // Your phone number
const OTP_DEV_BASE_URL = 'https://api.otp.dev/v1';

console.log('🧪 === OTP.dev API TESTING ===');
console.log(`📱 Test Phone: ${TEST_PHONE}`);
console.log(`🔑 API Key: ${API_KEY.substring(0, 8)}...`);
console.log('');

/**
 * Test OTP.dev API directly
 */
async function testOTPDevDirect() {
  try {
    console.log('📡 Testing OTP.dev API directly...');
    
    const payload = {
      data: {
        channel: "sms",
        sender: "8d0e3f03-d880-423a-9fdf-89b21235cddd",
        phone: TEST_PHONE,
        template: "b9acb7c4-74f5-45e3-9628-240c763cf9b9",
        code_length: 6
      }
    };

    const response = await fetch(`${OTP_DEV_BASE_URL}/verifications`, {
      method: 'POST',
      headers: {
        'X-OTP-Key': API_KEY,
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(payload)
    });

    const result = await response.json();
    
    if (response.ok) {
      console.log('✅ Direct OTP.dev API SUCCESS');
      console.log(`📋 Response:`, JSON.stringify(result, null, 2));
      return result;
    } else {
      console.log('❌ Direct OTP.dev API FAILED');
      console.log(`📋 Error:`, JSON.stringify(result, null, 2));
      return null;
    }

  } catch (error) {
    console.error('❌ Direct API Error:', error.message);
    return null;
  }
}

/**
 * Test sending OTP through your backend
 */
async function testSendOTP() {
  try {
    console.log('📤 Testing OTP send via backend...');
    
    const response = await fetch(`${BASE_URL}/api/auth/send-otp`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        phone: TEST_PHONE,
        method: 'sms'
      })
    });

    const result = await response.json();
    
    if (response.ok && result.success) {
      console.log('✅ Backend OTP Send SUCCESS');
      console.log(`📋 Response:`, JSON.stringify(result, null, 2));
      return result.verificationId;
    } else {
      console.log('❌ Backend OTP Send FAILED');
      console.log(`📋 Error:`, JSON.stringify(result, null, 2));
      return null;
    }

  } catch (error) {
    console.error('❌ Backend OTP Send Error:', error.message);
    return null;
  }
}

/**
 * Test OTP verification
 */
async function testVerifyOTP(verificationId) {
  try {
    console.log('🔐 Testing OTP verification...');
    
    // Get OTP from user input
    const readline = require('readline').createInterface({
      input: process.stdin,
      output: process.stdout
    });

    const otp = await new Promise((resolve) => {
      readline.question('📱 Enter the OTP you received: ', (answer) => {
        readline.close();
        resolve(answer.trim());
      });
    });

    if (!otp || otp.length !== 6) {
      console.log('❌ Invalid OTP format. Must be 6 digits.');
      return false;
    }

    const response = await fetch(`${BASE_URL}/api/auth/verify-otp`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        phone: TEST_PHONE,
        otp: otp,
        verificationId: verificationId
      })
    });

    const result = await response.json();
    
    if (response.ok && result.success) {
      console.log('✅ OTP Verification SUCCESS');
      console.log(`📋 Response:`, JSON.stringify(result, null, 2));
      return true;
    } else {
      console.log('❌ OTP Verification FAILED');
      console.log(`📋 Error:`, JSON.stringify(result, null, 2));
      return false;
    }

  } catch (error) {
    console.error('❌ OTP Verification Error:', error.message);
    return false;
  }
}

/**
 * Test account info (if supported)
 */
async function testAccountInfo() {
  try {
    console.log('💰 Testing account info...');
    
    const response = await fetch(`${OTP_DEV_BASE_URL}/account`, {
      method: 'GET',
      headers: {
        'X-OTP-Key': API_KEY,
        'Accept': 'application/json',
      }
    });

    const result = await response.json();
    
    if (response.ok) {
      console.log('✅ Account Info SUCCESS');
      console.log(`📋 Account:`, JSON.stringify(result, null, 2));
    } else {
      console.log('ℹ️ Account info not available or not supported');
      console.log(`📋 Response:`, JSON.stringify(result, null, 2));
    }

  } catch (error) {
    console.error('ℹ️ Account info error (may not be supported):', error.message);
  }
}

/**
 * Main testing function
 */
async function runTests() {
  console.log('🚀 Starting comprehensive OTP.dev tests...\n');

  // Test 1: Direct API call
  console.log('=== TEST 1: Direct OTP.dev API ===');
  const directResult = await testOTPDevDirect();
  console.log('');

  if (!directResult) {
    console.log('❌ Direct API failed, skipping backend tests');
    return;
  }

  // Test 2: Account info
  console.log('=== TEST 2: Account Information ===');
  await testAccountInfo();
  console.log('');

  // Test 3: Backend OTP send
  console.log('=== TEST 3: Backend OTP Send ===');
  const verificationId = await testSendOTP();
  console.log('');

  if (!verificationId) {
    console.log('❌ Backend OTP send failed, skipping verification test');
    return;
  }

  // Test 4: OTP verification
  console.log('=== TEST 4: OTP Verification ===');
  await testVerifyOTP(verificationId);
  console.log('');

  console.log('🎉 Testing completed!');
}

// Handle command line arguments
const args = process.argv.slice(2);

if (args.includes('--direct-only')) {
  console.log('Running direct API test only...\n');
  testOTPDevDirect();
} else if (args.includes('--account-only')) {
  console.log('Running account info test only...\n');
  testAccountInfo();
} else {
  // Run all tests
  runTests();
}

// Export for use in other scripts
module.exports = {
  testOTPDevDirect,
  testSendOTP,
  testVerifyOTP,
  testAccountInfo
};

Directory Contents

Dirs: 15 × Files: 17

Name Size Perms Modified Actions
.adminjs DIR
- drwxr-xr-x 2026-03-14 01:49:04
Edit Download
.git DIR
- drwxr-xr-x 2026-03-14 01:49:04
Edit Download
.vscode DIR
- drwxr-xr-x 2026-03-14 01:49:04
Edit Download
config DIR
- drwxr-xr-x 2026-03-23 22:02:13
Edit Download
- drwxr-xr-x 2026-03-20 23:25:48
Edit Download
- drwxr-xr-x 2026-03-14 01:49:04
Edit Download
images DIR
- drwxr-xr-x 2026-03-21 05:33:00
Edit Download
- drwxr-xr-x 2026-03-14 01:49:04
Edit Download
my files DIR
- drwxr-xr-x 2026-03-14 00:49:51
Edit Download
- drwxr-xr-x 2026-03-14 01:49:04
Edit Download
prisma DIR
- drwxr-xr-x 2026-03-14 01:49:04
Edit Download
routes DIR
- drwxr-xr-x 2026-03-20 00:05:44
Edit Download
scripts DIR
- drwxr-xr-x 2026-03-14 01:49:04
Edit Download
services DIR
- drwxr-xr-x 2026-03-14 01:49:04
Edit Download
utils DIR
- drwxr-xr-x 2026-03-20 17:22:33
Edit Download
1.87 KB lrw-r--r-- 2026-03-02 01:22:59
Edit Download
3.02 KB lrw-r--r-- 2026-02-26 10:27:44
Edit Download
54 B lrw-r--r-- 2026-03-02 23:21:50
Edit Download
10 B lrw------- 2026-03-05 08:01:17
Edit Download
1.99 KB lrw-r--r-- 2026-03-01 22:00:44
Edit Download
1.99 KB lr--r--r-- 2026-03-14 01:40:10
Edit Download
21.77 KB lrw-r--r-- 2026-03-04 17:41:20
Edit Download
20.61 KB lr--r--r-- 2026-03-14 00:49:43
Edit Download
5.12 KB lrw-r--r-- 2026-03-02 02:04:36
Edit Download
360.34 KB lrw-r--r-- 2026-02-28 07:42:19
Edit Download
33.05 KB lrw-r--r-- 2026-02-28 06:52:53
Edit Download
374 B lrw-r--r-- 2026-01-26 16:49:38
Edit Download
37.08 KB lrw-r--r-- 2026-02-26 10:27:44
Edit Download
85 B lrw-r--r-- 2026-03-14 00:49:44
Edit Download
7.04 KB lrw-r--r-- 2026-03-04 17:57:23
Edit Download
6.32 KB lrw-r--r-- 2026-02-26 10:27:44
Edit Download
6.11 KB lr--r--r-- 2026-03-14 01:40:10
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).