// integration/payment-api.test.js
const API_URL = 'https://api-sandbox.y.uno';
describe('Payment API Integration', () => {
let checkoutSession;
beforeAll(async () => {
const response = await fetch(`${API_URL}/v1/checkout/sessions`, {
method: 'POST',
headers: {
'public-api-key': process.env.YUNO_PUBLIC_KEY,
'private-secret-key': process.env.YUNO_PRIVATE_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
amount: { currency: 'USD', value: 50.00 },
country: 'CO',
merchant_order_id: `test-${Date.now()}`,
}),
});
const data = await response.json();
checkoutSession = data.checkout_session;
});
it('creates a payment with valid data', async () => {
const response = await fetch(`${API_URL}/v1/payments`, {
method: 'POST',
headers: {
'public-api-key': process.env.YUNO_PUBLIC_KEY,
'private-secret-key': process.env.YUNO_PRIVATE_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
checkout_session: checkoutSession,
payment_method: { type: 'CARD', token: 'test-token' },
amount: { currency: 'USD', value: 50.00 },
country: 'CO',
customer: { email: 'test@example.com' },
}),
});
expect(response.status).toBe(200);
const payment = await response.json();
expect(payment.status).toBe('SUCCEEDED');
});
it('returns 400 for missing required fields', async () => {
const response = await fetch(`${API_URL}/v1/payments`, {
method: 'POST',
headers: {
'public-api-key': process.env.YUNO_PUBLIC_KEY,
'private-secret-key': process.env.YUNO_PRIVATE_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
checkout_session: checkoutSession,
// Missing payment_method, amount, country
}),
});
expect(response.status).toBe(400);
});
});