adapt biling and UT
MODIFY
src/integration/billing/BillingIntegration.ts
src/integration/billing/BillingIntegration.ts
@@ -331,6 +331,14 @@ export default abstract class BillingIntegration {
}
}
+ protected isTransactionUserInternal(transaction: Transaction): boolean {
+ return this.isUserInternal(transaction?.user);
+ }
+
+ protected isUserInternal(user: User): boolean {
+ return !user.billable;
+ }
+
private async _getUsersWithNoBillingData(): Promise<User[]> {
const newUsers = await UserStorage.getUsers(this.tenant,
{

MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -748,14 +748,6 @@ export default class StripeBillingIntegration extends BillingIntegration {
}
}
- private isTransactionUserInternal(transaction: Transaction): boolean {
- return this.isUserInternal(transaction?.user);
- }
-
- private isUserInternal(user: User): boolean {
- return !user.billable;
- }
-
public async startTransaction(transaction: Transaction): Promise<BillingDataTransactionStart> {
if (!this.settings.billing.isTransactionBillingActivated) {

MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
@@ -977,7 +977,7 @@ describe('Billing Service', function() {
});
- describe('Where non-billable basic user', () => {
+ describe('Where billable basic user', () => {
// eslint-disable-next-line @typescript-eslint/require-await
before(async () => {
testData.userContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);
@@ -989,21 +989,23 @@ describe('Billing Service', function() {
assert(!!testData.userService, 'User service cannot be null');
});
- it('should NOT create bill after a transaction', async () => {
+ it('should NOT start a transaction without payment method', async () => {
+ let transactionID = await testData.generateTransaction(testData.userContext, 'Invalid');
+ expect(transactionID).eq(0);
+ // Add payment method
await testData.userService.billingApi.forceSynchronizeUser({ id: testData.userContext.id });
const userWithBillingData = await testData.billingImpl.getUser(testData.userContext);
await testData.assignPaymentMethod(userWithBillingData, 'tok_fr');
- const transactionID = await testData.generateTransaction(testData.userContext);
- assert(transactionID, 'transactionID should not be null');
- // Check that we have a new invoice with an invoiceID and an invoiceNumber
- await testData.checkTransactionBillingData(transactionID, BillingInvoiceStatus.NOT_BILLED);
+ transactionID = await testData.generateTransaction(testData.userContext);
+ expect(transactionID).gt(0);
+ // TODO: Should generate immediately a paid invoice?
});
});
- describe('Where billable basic user', () => {
+ describe('Where NON-billable basic user', () => {
// eslint-disable-next-line @typescript-eslint/require-await
before(async () => {
- testData.userContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);
+ testData.userContext = testData.tenantContext.getUserContext({ id: ContextDefinition.USER_CONTEXTS.BASIC_NON_BILLABLE_USER.id });
assert(testData.userContext, 'User context cannot be null');
testData.userService = new CentralServerService(
testData.tenantContext.getTenant().subdomain,
@@ -1012,9 +1014,9 @@ describe('Billing Service', function() {
assert(!!testData.userService, 'User service cannot be null');
});
- it('should NOT start a transaction', async () => {
+ it('should start a transaction', async () => {
const transactionID = await testData.generateTransaction(testData.userContext, 'Invalid');
- expect(transactionID).eq(0);
+ expect(transactionID).gt(0);
});
});
});

MODIFY
test/api/context/ContextDefinition.ts
test/api/context/ContextDefinition.ts
@@ -75,7 +75,10 @@ export default class ContextDefinition {
role: 'A', status: 'A', assignedToSite: false, withTags: true, issuer: true
},
BASIC_USER: {
- role: 'B', status: 'A', assignedToSite: true, withTags: true, issuer: true
+ role: 'B', status: 'A', assignedToSite: true, withTags: true, issuer: true, id: '5ce249a1a39ae1c056c123ab'
+ },
+ BASIC_NON_BILLABLE_USER: {
+ role: 'B', status: 'A', assignedToSite: true, withTags: true, issuer: true, id: '5ce249a1a39ae1c056c123ff'
},
BASIC_USER_UNASSIGNED: {
role: 'B', status: 'A', assignedToSite: false, withTags: true, issuer: true
@@ -449,7 +452,8 @@ export default class ContextDefinition {
visualID: new ObjectId().toString(),
issuer: false,
active: true
- }] : null)
+ }] : null),
+ billable: false
},
{ // Demo user
id: '5ce249a1a39ae1c056c123cd',

adapt biling and UT