Files
Pay2Gateway/test_e2e.js

44 lines
1.9 KiB
JavaScript

const { Client } = require('pg');
const { CryptoEngine } = require('./lib/crypto-engine');
async function testE2E() {
const fetch = require('node-fetch');
// 1. Create a mock merchant if none
const client = new Client({ connectionString: process.env.DATABASE_URL });
await client.connect();
let res = await client.query('SELECT * FROM merchants LIMIT 1');
let merchantId = res.rows[0]?.id;
if(!merchantId) {
res = await client.query(`INSERT INTO merchants (name, payment_provider) VALUES ('Test', 'stripe') RETURNING id`);
merchantId = res.rows[0].id;
}
// 2. Call create-payment-intent API
const createRes = await fetch('http://localhost:3000/api/create-payment-intent', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ amount: 5, currency: 'TRY', merchant_id: merchantId })
});
const createData = await createRes.json();
console.log("Create Data:", createData);
const txId = createData.id;
const solAddress = createData.wallets.SOLANA;
console.log("SOL Adresi:", solAddress);
// 3. Fund it! (I don't have SOL right now in memory, but I will simulate it by querying the DB to get the privatekey and sweeping? No, wait, I can just mock the balance in the CryptoEngine but it's Devnet so I can just fund it via Solana faucet or direct transfer from my gas tank).
// Let's actually just call /api/crypto-sweep with a wait, but we know it will fail because 0 balance. Let's see if 0 balance returns 200 with waiting!
const sweepRes = await fetch('http://localhost:3000/api/crypto-sweep', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ txId, network: 'SOLANA', token: 'SOL' })
});
const sweepData = await sweepRes.json();
console.log("Sweep Data:", sweepData);
await client.end();
}
testE2E().catch(console.error);