test(billing): transfer tests
MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
/* eslint-disable max-len */
-import { BillingAccount, BillingAccountStatus, BillingChargeInvoiceAction, BillingInvoiceStatus } from '../../src/types/Billing';
+import { BillingAccount, BillingAccountStatus, BillingChargeInvoiceAction, BillingInvoiceStatus, BillingTransfer, BillingTransferStatus } from '../../src/types/Billing';
import { BillingSettings, BillingSettingsType } from '../../src/types/Setting';
import chai, { expect } from 'chai';
import { BillingPeriodicOperationTaskConfig } from '../../src/types/TaskConfig';
+import BillingStorage from '../../src/storage/mongodb/BillingStorage';
import BillingTestHelper from './BillingTestHelper';
+import { BillingTransferFactory } from '../factories/BillingFactory';
import CentralServerService from './client/CentralServerService';
import CompanyFactory from '../factories/CompanyFactory';
import Constants from '../../src/utils/Constants';
@@ -1231,6 +1233,29 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
expect(subAccountResponse.status).to.be.eq(StatusCodes.FORBIDDEN);
});
});
+
+ describe('Storage', () => {
+ it('should save a billing transfer', async () => {
+ const transfer = BillingTransferFactory.build();
+ const transferID = await BillingStorage.saveTransfer(billingTestHelper.tenantContext.getTenant(), transfer);
+ expect(transferID).to.not.be.null;
+
+ const retrievedTransfer = await BillingStorage.getTransferByID(billingTestHelper.tenantContext.getTenant(), transferID);
+ expect(retrievedTransfer).to.containSubset(transfer);
+ });
+
+ it('should list billing transfers', async () => {
+ const transfers = [
+ BillingTransferFactory.build(),
+ BillingTransferFactory.build(),
+ ];
+
+ const ids = await Promise.all(transfers.map(async (transfer) => BillingStorage.saveTransfer(billingTestHelper.tenantContext.getTenant(), transfer)));
+
+ const retrievedTransfers = await BillingStorage.getTransfers(billingTestHelper.tenantContext.getTenant(), {}, Constants.DB_PARAMS_MAX_LIMIT);
+ expect(retrievedTransfers.result.map((transfer) => transfer.id)).to.include.members(ids);
+ });
+ });
});
describe('Billing Test Data Cleanup (utbilling)', () => {

ADD
test/factories/BillingFactory.ts
+import { BillingTransferStatus } from '../../src/types/Billing';
+import { Factory } from 'rosie';
+import faker from 'faker';
+
+export const BillingTransferFactory = Factory.define('billingtransfer')
+ .attr('amount', () => faker.datatype.number())
+ .attr('accountID', () => faker.datatype.hexaDecimal(24).substring(2).toLowerCase())
+ .attr('status', () => faker.random.arrayElement([BillingTransferStatus.DRAFT, BillingTransferStatus.PENDING, BillingTransferStatus.TRANSFERRED]))
+ .attr('transferredAmount', () => faker.datatype.number())
+ .attr('transferExternalID', () => faker.datatype.uuid())
+ .attr('platformFeeData', () => ({
+ feeAmount: faker.datatype.number(),
+ feeTaxAmount: faker.datatype.number(),
+ taxExternalID: faker.datatype.uuid(),
+ invoiceExternalID: faker.datatype.uuid(),
+ }))
+ .attr('sessions', () =>
+ faker.random.arrayElements().map(() => ({
+ transactionID: faker.datatype.number(),
+ amount: faker.datatype.number(),
+ platformFee: {
+ flatFeePerSession: faker.datatype.number(),
+ percentage: faker.datatype.number(),
+ }
+ }))
+ );

test(billing): transfer tests