bp - transfer test with top-up in USD
MODIFY
test/api/BillingPlatformTest.ts
test/api/BillingPlatformTest.ts
@@ -25,7 +25,7 @@ const billingTestHelper = new BillingTestHelper();
// Conditional test execution function
const describeif = (condition) => condition ? describe : describe.skip;
// ACHTUNG - STRIPE Limitation - We cannot test transfer capabilities with accounts in Europe
-const isBillingProperlyConfigured = BillingTestConfigHelper.isBillingProperlyConfigured('USD');
+const isBillingProperlyConfigured = BillingTestConfigHelper.isBillingProperlyConfigured();
describeif(isBillingProperlyConfigured)('Billing Platform (utbillingplatform)', () => {
jest.setTimeout(60000);
@@ -207,7 +207,7 @@ describeif(isBillingProperlyConfigured)('Billing Platform (utbillingplatform)',
const billingAccount = await billingTestHelper.getActivatedAccount();
const transfer: BillingTransfer = {
...BillingTransferFactory.build(),
- currency: billingTestHelper.getCurrentCurrency(),
+ currency: 'USD',
accountID: billingAccount.id,
status: BillingTransferStatus.DRAFT
};
@@ -222,7 +222,7 @@ describeif(isBillingProperlyConfigured)('Billing Platform (utbillingplatform)',
it('should not finalize a draft transfer', async () => {
const transfer = {
...BillingTransferFactory.build(),
- currency: billingTestHelper.getCurrentCurrency(),
+ currency: 'USD',
};
transfer.status = BillingTransferStatus.FINALIZED;
const transferID = await BillingStorage.saveTransfer(billingTestHelper.getTenant(), transfer);
@@ -235,7 +235,7 @@ describeif(isBillingProperlyConfigured)('Billing Platform (utbillingplatform)',
const billingAccount = await billingTestHelper.createActivatedAccount();
const transfer: BillingTransfer = {
...BillingTransferFactory.build(),
- currency: billingTestHelper.getCurrentCurrency(),
+ currency: 'USD',
status: BillingTransferStatus.DRAFT,
accountID: billingAccount.id
};

MODIFY
test/api/BillingTestHelper.ts
test/api/BillingTestHelper.ts
@@ -36,7 +36,6 @@ import User from '../../src/types/User';
import Utils from '../../src/utils/Utils';
import assert from 'assert';
import chaiSubset from 'chai-subset';
-import config from '../config';
import moment from 'moment-timezone';
import responseHelper from '../helpers/responseHelper';
@@ -46,7 +45,6 @@ chai.use(responseHelper);
export default class BillingTestHelper {
// Tenant: utbilling
private tenantContext: TenantContext;
- private tenantCurrency = 'EUR';
// Context with Admin permissions
private adminUserContext: User;
private adminUserService: CentralServerService;
@@ -69,9 +67,6 @@ export default class BillingTestHelper {
public async initialize(tenantContext = ContextDefinition.TENANT_CONTEXTS.TENANT_BILLING) : Promise<void> {
this.tenantContext = await ContextProvider.defaultInstance.getTenantContext(tenantContext);
- if (tenantContext === ContextDefinition.TENANT_CONTEXTS.TENANT_BILLING_PLATFORM) {
- this.tenantCurrency = 'USD';
- }
this.adminUserContext = this.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
this.adminUserService = new CentralServerService(
this.tenantContext.getTenant().subdomain,
@@ -92,10 +87,6 @@ export default class BillingTestHelper {
return this.tenantContext.getTenant().id;
}
- public getCurrentCurrency(): string {
- return this.tenantCurrency;
- }
-
public getAdminUserService(): CentralServerService {
return this.adminUserService;
}
@@ -505,7 +496,7 @@ export default class BillingTestHelper {
}
public async setBillingSystemValidCredentials(activateTransactionBilling = true, immediateBillingAllowed = false) : Promise<void> {
- const billingSettings = BillingTestConfigHelper.getLocalSettings(this.tenantCurrency, immediateBillingAllowed);
+ const billingSettings = BillingTestConfigHelper.getLocalSettings(immediateBillingAllowed);
// Here we switch ON or OFF the billing of charging sessions
billingSettings.billing.isTransactionBillingActivated = activateTransactionBilling;
// Invoke the generic setting service API to properly persist this information
@@ -519,7 +510,7 @@ export default class BillingTestHelper {
}
public async setBillingSystemInvalidCredentials() : Promise<void> {
- const billingSettings = BillingTestConfigHelper.getLocalSettings(this.tenantCurrency, false);
+ const billingSettings = BillingTestConfigHelper.getLocalSettings(false);
const tenant = this.tenantContext?.getTenant();
assert(!!tenant, 'Tenant cannot be null');
billingSettings.stripe.secretKey = await Cypher.encrypt(tenant, 'sk_test_' + 'invalid_credentials');
@@ -1002,13 +993,13 @@ export default class BillingTestHelper {
expect(response.data.status).to.eq(BillingTransferStatus.FINALIZED);
}
- public async addFundsToBalance(amount: number, stripe_test_token = 'btok_us_verified') : Promise<Stripe.Topup> {
+ public async addFundsToBalance(amount: number, stripe_test_token = 'btok_us_verified', currency = 'usd') : Promise<Stripe.Topup> {
// Assign funds to the stripe balance is a prerequisite for testing transfers
// c.f.: https://stripe.com/docs/connect/testing#testing-top-ups
const stripeInstance = await this.billingImpl.getStripeInstance();
const topup = await stripeInstance.topups.create({
amount,
- currency: 'eur',
+ currency,
description: 'test-addFundsToBalance',
source:stripe_test_token,
});

MODIFY
test/api/StripeTestHelper.ts
test/api/StripeTestHelper.ts
@@ -27,15 +27,15 @@ chai.use(chaiSubset);
chai.use(responseHelper);
export class BillingTestConfigHelper {
- public static isBillingProperlyConfigured(tenantCurrency: string): boolean {
- const billingSettings = BillingTestConfigHelper.getLocalSettings(tenantCurrency, false);
+ public static isBillingProperlyConfigured(): boolean {
+ const billingSettings = BillingTestConfigHelper.getLocalSettings(false);
// Check that the mandatory settings are properly provided
return (!!billingSettings.stripe.publicKey
&& !!billingSettings.stripe.secretKey
&& !!billingSettings.stripe.url);
}
- public static getLocalSettings(tenantCurrency: string, immediateBillingAllowed: boolean): BillingSettings {
+ public static getLocalSettings(immediateBillingAllowed: boolean): BillingSettings {
// ----------------------------------
// CONFIGURATION EXAMPLE - in test/local.json
// ----------------------------------
@@ -50,12 +50,6 @@ export class BillingTestConfigHelper {
// "publicKey": "pk_test_511FFFFFFFFFFF",
// "secretKey": "sk_test_51K1FFFFFFFFFF"
// },
- // "stripeUSD": {
- // "url": "https://dashboard.stripe.com/b/acct_1AAAAAAAAAAA",
- // "publicKey": "pk_test_51AAAAAAAAAAA",
- // "secretKey": "sk_test_52AAAAAAAAAAA"
- // },
- const propertySuffix = (tenantCurrency !== 'EUR') ? tenantCurrency : '';
const billingProperties = {
isTransactionBillingActivated: config.get('billing.isTransactionBillingActivated'),
immediateBillingAllowed: immediateBillingAllowed, // config.get('billing.immediateBillingAllowed'),
@@ -63,9 +57,9 @@ export class BillingTestConfigHelper {
taxID: config.get('billing.taxID')
};
const stripeProperties = {
- url: config.get(`stripe${propertySuffix}.url`),
- publicKey: config.get(`stripe${propertySuffix}.publicKey`),
- secretKey: config.get(`stripe${propertySuffix}.secretKey`),
+ url: config.get('stripe.url'),
+ publicKey: config.get('stripe.publicKey'),
+ secretKey: config.get('stripe.secretKey'),
};
const settings: BillingSettings = {
identifier: TenantComponents.BILLING,
@@ -86,7 +80,6 @@ export class BillingTestConfigHelper {
export default class StripeTestHelper {
// Tenant: utbilling
private tenantContext: TenantContext;
- private tenantCurrency = 'EUR';
// User Service for action requiring admin permissions (e.g.: set/reset stripe settings)
private adminUserContext: User;
private adminUserService: CentralServerService;
@@ -99,9 +92,6 @@ export default class StripeTestHelper {
public async initialize(tenantContext = ContextDefinition.TENANT_CONTEXTS.TENANT_BILLING): Promise<void> {
this.tenantContext = await ContextProvider.defaultInstance.getTenantContext(tenantContext);
- if (tenantContext === ContextDefinition.TENANT_CONTEXTS.TENANT_BILLING_PLATFORM) {
- this.tenantCurrency = 'USD';
- }
this.adminUserContext = this.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
this.adminUserService = new CentralServerService(
this.tenantContext.getTenant().subdomain,
@@ -134,7 +124,7 @@ export default class StripeTestHelper {
}
public async setBillingSystemValidCredentials(immediateBilling: boolean) : Promise<void> {
- const billingSettings = BillingTestConfigHelper.getLocalSettings(this.tenantCurrency, immediateBilling);
+ const billingSettings = BillingTestConfigHelper.getLocalSettings(immediateBilling);
await this.saveBillingSettings(billingSettings);
billingSettings.stripe.secretKey = await Cypher.encrypt(this.getTenant(), billingSettings.stripe.secretKey);
this.billingImpl = StripeBillingIntegration.getInstance(this.getTenant(), billingSettings);
@@ -142,7 +132,7 @@ export default class StripeTestHelper {
}
public async fakeLiveBillingSettings() : Promise<StripeBillingIntegration> {
- const billingSettings = BillingTestConfigHelper.getLocalSettings(this.tenantCurrency, true);
+ const billingSettings = BillingTestConfigHelper.getLocalSettings(true);
const mode = 'live';
billingSettings.stripe.secretKey = `sk_${mode}_0234567890`;
billingSettings.stripe.publicKey = `pk_${mode}_0234567890`;

MODIFY
test/config.js
test/config.js
@@ -290,23 +290,6 @@ const config = convict({
default: ''
},
},
- stripeUSD: {
- url: {
- doc: 'Billing provider dashboard',
- format: String,
- default: ''
- },
- publicKey: {
- doc: 'Public key',
- format: String,
- default: ''
- },
- secretKey: {
- doc: 'Secret Key',
- format: String,
- default: ''
- },
- },
smartCharging: {
optimizerUrl: {
doc: 'Smart charging url',

MODIFY
test/factories/BillingFactory.ts
test/factories/BillingFactory.ts
@@ -14,8 +14,7 @@ export const BillingTransferFactory = Factory.define<BillingTransfer>('billingtr
feeTaxAmount: 0
}))
.attr('sessions', () =>
- [BillingTransferSessionFactory.build()])
- .attr('currency', () => 'EUR');
+ [BillingTransferSessionFactory.build()]);
export const BillingTransferSessionFactory = Factory.define<BillingTransferSession>('billingtransfersession')
.attr('transactionID', () => faker.datatype.number())

bp - transfer test with top-up in USD