Clear test tenants after mochatest
MODIFY
test/api/TenantTest.ts
test/api/TenantTest.ts
@@ -14,6 +14,7 @@ chai.use(chaiSubset);
class TestData {
public newTenant: any;
public superAdminCentralService: any;
+ public tenantsToCleanUp: any[];
}
const testData: TestData = new TestData();
@@ -22,6 +23,15 @@ describe('Tenant tests', function() {
this.timeout(30000);
before(async () => {
testData.superAdminCentralService = new CentralServerService('');
+ testData.tenantsToCleanUp = [];
+ });
+
+ after(async () => {
+ // Final clean up at the end
+ for (const tenant of testData.tenantsToCleanUp) {
+ await CentralServerService.defaultInstance.deleteEntity(
+ CentralServerService.defaultInstance.tenantApi, tenant);
+ }
});
describe('Success cases', () => {
@@ -79,8 +89,7 @@ describe('Tenant tests', function() {
'type': null
}
};
- await CentralServerService.defaultInstance.createEntity(
- CentralServerService.defaultInstance.tenantApi, tenant);
+ testData.tenantsToCleanUp.push(await CentralServerService.defaultInstance.createEntity(CentralServerService.defaultInstance.tenantApi, tenant));
});
it('Should find the created tenant by id', async () => {
@@ -258,16 +267,14 @@ describe('Tenant tests', function() {
let tenant: Tenant = Factory.tenant.build();
const tenantSubdomain = tenant.subdomain;
// Call
- let response = await CentralServerService.defaultInstance.createEntity(
- CentralServerService.defaultInstance.tenantApi, tenant, false);
- // Check
- expect(response.status).to.equal(StatusCodes.OK);
+ testData.tenantsToCleanUp.push(await CentralServerService.defaultInstance.createEntity(
+ CentralServerService.defaultInstance.tenantApi, tenant));
// Create
tenant = Factory.tenant.build();
tenant.subdomain = tenantSubdomain;
// Call
- response = await CentralServerService.defaultInstance.createEntity(
+ const response = await CentralServerService.defaultInstance.createEntity(
CentralServerService.defaultInstance.tenantApi, tenant, false);
// Check
expect(response.status).to.equal(HTTPError.TENANT_ALREADY_EXIST);

Clear test tenants after mochatest