dcb-orange-mock/test/test-integration.ts
Mamadou Khoussa [028918 DSI/DAC/DIF/DS] 2e2724c7a6 fix it
2025-09-21 22:47:06 +00:00

122 lines
3.1 KiB
TypeScript

// test-integration.ts
import axios from 'axios';
const BASE_URL = 'http://localhost:3000';
let accessToken = '';
async function testOAuth() {
console.log('1. Test OAuth Token Generation...');
const response = await axios.post(`${BASE_URL}/oauth/v3/token`,
'grant_type=client_credentials',
{
headers: {
'Authorization': 'Basic ' + Buffer.from('clientId:clientSecret').toString('base64'),
'Content-Type': 'application/x-www-form-urlencoded'
}
}
);
accessToken = response.data.access_token;
console.log('✅ Token obtenu:', accessToken);
return accessToken;
}
async function testSubscription() {
console.log('\n2. Test Subscription...');
const response = await axios.post(
`${BASE_URL}/payment/mea/v1/digipay_sub/productOrder`,
{
note: { text: 'test data' },
relatedPublicKey: {
id: 'PDKSUB-200-test123',
name: 'ISE2',
},
relatedParty: [
{
id: 'TESTPARTNER',
name: 'Test Partner',
role: 'partner'
},
{
id: 'TESTRETAILER',
name: 'Test Retailer',
role: 'retailer'
}
],
orderItem: {
action: 'add',
state: 'Completed',
product: {
id: 'TEST_PRODUCT',
productCharacteristic: [
{ name: 'amount', value: '100.0' },
{ name: 'currency', value: 'XOF' },
{ name: 'periodicity', value: '86400' }
]
}
}
},
{
headers: {
'Authorization': `Bearer ${accessToken}`,
'X-Orange-ISE2': 'PDKSUB-200-test123',
'X-Orange-MCO': 'OCI',
'Content-Type': 'application/json'
}
}
);
console.log('✅ Subscription créée:', response.data.id);
return response.data.id;
}
async function testCharge() {
console.log('\n3. Test Charge...');
const response = await axios.post(
`${BASE_URL}/payment/mea/v1/acr:X-Orange-ISE2/transactions/amount`,
{
amountTransaction: {
endUserId: 'acr:X-Orange-ISE2',
paymentAmount: {
chargingInformation: {
amount: '10.0',
currency: 'XOF',
description: 'Test charge'
},
chargingMetaData: {
onBehalfOf: 'TESTRETAILER',
purchaseCategoryCode: 'VOD',
serviceId: 'TEST_SERVICE'
}
},
transactionOperationStatus: 'Charged',
referenceCode: 'ref123',
clientCorrelator: 'corr123'
}
},
{
headers: {
'Authorization': `Bearer ${accessToken}`,
'X-Orange-ISE2': 'PDKSUB-200-Q82vHq0+F1WozTeNS/1wBfuULco05YBaeL4yPtJ8ktU=',
'X-Orange-MCO': 'OCI',
'Content-Type': 'application/json'
}
}
);
console.log('✅ Charge effectuée:', response.data.amountTransaction.serverReferenceCode);
}
// Exécuter les tests
async function runTests() {
try {
await testOAuth();
const subscriptionId = await testSubscription();
await testCharge();
console.log('\n✅ Tous les tests sont passés!');
} catch (error) {
console.error('❌ Erreur:', error.response?.data || error.message);
}
}
runTests();