bp - test fix
MODIFY
test/api/BillingPlatformTest.ts
test/api/BillingPlatformTest.ts
@@ -41,9 +41,10 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
describe('Billing Service (utbillingplatform)', () => {
beforeAll(async () => {
+ await stripeTestHelper.initialize(ContextDefinition.TENANT_CONTEXTS.TENANT_BILLING_PLATFORM);
await billingTestHelper.initialize(ContextDefinition.TENANT_CONTEXTS.TENANT_BILLING_PLATFORM);
- // Initialize the Billing module
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials();
+ const immediateBilling = false;
+ await stripeTestHelper.forceBillingSettings(immediateBilling);
});
describe('Where admin user', () => {
@@ -343,10 +344,10 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
it('should send a transfer', async () => {
const billingAccount = await billingTestHelper.createActivatedAccount();
const transfer: BillingTransfer = { ...BillingTransferFactory.build(), status: BillingTransferStatus.DRAFT, accountID: billingAccount.id };
+ await stripeTestHelper.addFundsToBalance(transfer.totalAmount);
transfer.id = await BillingStorage.saveTransfer(billingTestHelper.tenantContext.getTenant(), transfer);
const finalizeResponse = await billingTestHelper.userService.billingApi.finalizeTransfer(transfer.id);
expect(finalizeResponse.status).to.be.eq(StatusCodes.OK);
-
const sendResponse = await billingTestHelper.userService.billingApi.sendTransfer(transfer.id);
expect(sendResponse.status).to.be.eq(StatusCodes.OK);
});

MODIFY
test/api/BillingTestHelper.ts
test/api/BillingTestHelper.ts
@@ -59,8 +59,8 @@ export default class BillingTestHelper {
public billingUser: BillingUser; // DO NOT CONFUSE - BillingUser is not a User!
public billingAccount: BillingAccount;
- public async initialize(tenant: string) : Promise<void> {
- this.tenantContext = await ContextProvider.defaultInstance.getTenantContext(tenant);
+ public async initialize(tenantContext = ContextDefinition.TENANT_CONTEXTS.TENANT_BILLING) : Promise<void> {
+ this.tenantContext = await ContextProvider.defaultInstance.getTenantContext(tenantContext);
this.adminUserContext = this.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
this.adminUserService = new CentralServerService(
this.tenantContext.getTenant().subdomain,

MODIFY
test/api/StripeTestHelper.ts
test/api/StripeTestHelper.ts
@@ -38,9 +38,9 @@ export default class StripeTestHelper {
public billingImpl: StripeBillingIntegration;
public billingUser: BillingUser; // DO NOT CONFUSE - BillingUser is not a User!
- public async initialize(): Promise<void> {
+ public async initialize(tenantContext = ContextDefinition.TENANT_CONTEXTS.TENANT_BILLING): Promise<void> {
- this.tenantContext = await ContextProvider.defaultInstance.getTenantContext(ContextDefinition.TENANT_CONTEXTS.TENANT_BILLING);
+ this.tenantContext = await ContextProvider.defaultInstance.getTenantContext(tenantContext);
this.adminUserContext = this.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
this.adminUserService = new CentralServerService(
this.tenantContext.getTenant().subdomain,
@@ -141,8 +141,7 @@ export default class StripeTestHelper {
public async assignPaymentMethod(stripe_test_token: string) : Promise<Stripe.CustomerSource> {
// Assign a source using test tokens (instead of test card numbers)
// c.f.: https://stripe.com/docs/testing#cards
- const concreteImplementation : StripeBillingIntegration = this.billingImpl ;
- const stripeInstance = await concreteImplementation.getStripeInstance();
+ const stripeInstance = await this.billingImpl.getStripeInstance();
const source = await stripeInstance.customers.createSource(this.getCustomerID(), {
source: stripe_test_token // e.g.: tok_visa, tok_amex, tok_fr
});
@@ -150,6 +149,20 @@ export default class StripeTestHelper {
return source;
}
+ public async addFundsToBalance(amount: number, stripe_test_token = 'btok_us_verified') : 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',
+ description: 'test-addFundsToBalance',
+ source:stripe_test_token,
+ });
+ expect(topup).to.not.be.null;
+ return topup;
+ }
+
// Detach the latest assigned source
public async checkDetachPaymentMethod(newSourceId: string) : Promise<void> {
const concreteImplementation : StripeBillingIntegration = this.billingImpl;

bp - test fix