billing platform - test stability improvements
MODIFY
src/server/rest/v1/service/BillingService.ts
src/server/rest/v1/service/BillingService.ts
@@ -543,7 +543,7 @@ export default class BillingService {
}
// Get the billing sub accounts
const subAccounts = await BillingStorage.getSubAccounts(req.tenant, {
- subAccountIDs: filteredRequest.SubAccountID ? filteredRequest.SubAccountID.split('|') : null,
+ IDs: filteredRequest.ID ? filteredRequest.ID.split('|') : null,
userIDs: filteredRequest.UserID ? filteredRequest.UserID.split('|') : null,
search: filteredRequest.Search ? filteredRequest.Search : null,
status: filteredRequest.Status ? filteredRequest.Status.split('|') : null,

MODIFY
src/storage/mongodb/BillingStorage.ts
src/storage/mongodb/BillingStorage.ts
@@ -239,7 +239,7 @@ export default class BillingStorage {
public static async getSubAccounts(tenant: Tenant,
params: {
- subAccountIDs?: string[], subAccountAccountIDs?: string[], search?: string, userIDs?: string[], status?: string[]
+ IDs?: string[], accountExternalIDs?: string[], search?: string, userIDs?: string[], status?: string[]
} = {},
dbParams: DbParams, projectFields?: string[]): Promise<DataResult<BillingAccount>> {
const startTime = Logging.traceDatabaseRequestStart();
@@ -261,18 +261,18 @@ export default class BillingStorage {
{ 'accountExternalID': { $regex: params.search, $options: 'i' } }
];
}
- if (!Utils.isEmptyArray(params.subAccountIDs)) {
+ if (!Utils.isEmptyArray(params.IDs)) {
filters._id = {
- $in: params.subAccountIDs.map((subAccountID) => DatabaseUtils.convertToObjectID(subAccountID))
+ $in: params.IDs.map((id) => DatabaseUtils.convertToObjectID(id))
};
}
- if (!Utils.isEmptyArray(params.subAccountAccountIDs)) {
- filters.accountID = {
- $in: params.subAccountAccountIDs
+ if (!Utils.isEmptyArray(params.accountExternalIDs)) {
+ filters.accountExternalID = {
+ $in: params.accountExternalIDs
};
}
if (!Utils.isEmptyArray(params.userIDs)) {
- filters.userID = {
+ filters.businessUserID = {
$in: params.userIDs.map((userID) => DatabaseUtils.convertToObjectID(userID))
};
}
@@ -341,7 +341,7 @@ export default class BillingStorage {
public static async getSubAccountByID(tenant: Tenant, id: string, projectFields?: string[]): Promise<BillingAccount> {
const subAccountMDB = await BillingStorage.getSubAccounts(tenant, {
- subAccountIDs: [id]
+ IDs: [id]
}, Constants.DB_PARAMS_SINGLE_RECORD, projectFields);
return subAccountMDB.count === 1 ? subAccountMDB.result[0] : null;
}

MODIFY
src/types/requests/HttpBillingRequest.ts
src/types/requests/HttpBillingRequest.ts
@@ -44,7 +44,7 @@ export interface HttpBillingSubAccountActivateRequest {
}
export interface HttpBillingSubAccountsGetRequest extends HttpDatabaseRequest {
- SubAccountID?: string;
+ ID?: string;
UserID?: string;
Status?: string;
StartDateTime?: Date;

MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
@@ -1122,7 +1122,9 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
expect(subAccountResponse.status).to.be.eq(StatusCodes.CREATED);
// List sub-accounts
- const subAccountsResponse = await billingTestHelper.userService.billingApi.readAllSubAccounts({});
+ const subAccountsResponse = await billingTestHelper.userService.billingApi.readSubAccounts({
+ userID: billingTestHelper.userContext.id
+ });
expect(subAccountsResponse.status).to.be.eq(StatusCodes.OK);
expect(subAccountsResponse.data.result.map((subAccount: BillingAccount) => subAccount.id)).to.include(subAccountResponse.data.id);
});
@@ -1213,7 +1215,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
});
it('should not be able to list sub-accounts', async () => {
- const subAccountsResponse = await billingTestHelper.userService.billingApi.readAllSubAccounts({});
+ const subAccountsResponse = await billingTestHelper.userService.billingApi.readSubAccounts({});
expect(subAccountsResponse.status).to.be.eq(StatusCodes.FORBIDDEN);
});

MODIFY
test/api/client/BillingApi.ts
test/api/client/BillingApi.ts
@@ -60,8 +60,8 @@ export default class BillingApi extends CrudApi {
return super.patch(params, super.buildUtilRestEndpointUrl(RESTServerRoute.REST_BILLING_SUB_ACCOUNT_ACTIVATE, { id: params.accountID }));
}
- public async readAllSubAccounts(params, paging = TestConstants.DEFAULT_PAGING, ordering = TestConstants.DEFAULT_ORDERING) {
- return super.readAll(params, paging, ordering, super.buildRestEndpointUrl(RESTServerRoute.REST_BILLING_SUB_ACCOUNTS));
+ public async readSubAccounts(params, paging = TestConstants.DEFAULT_PAGING, ordering = TestConstants.DEFAULT_ORDERING) {
+ return super.readAll(params, paging, ordering, super.buildRestEndpointUrl(RESTServerRoute.REST_BILLING_SUB_ACCOUNTS, params));
}
public async readSubAccount(id: string) {

billing platform - test stability improvements