Fixed tenant creation error return code
MODIFY
src/server/rest/v1/service/TenantService.ts
src/server/rest/v1/service/TenantService.ts
@@ -236,7 +236,7 @@ export default class TenantService {
if (foundTenant) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.USER_EMAIL_ALREADY_EXIST_ERROR,
+ errorCode: HTTPError.TENANT_ALREADY_EXIST,
message: `The tenant with name '${filteredRequest.name}' already exists`,
module: MODULE_NAME, method: 'handleCreateTenant',
user: req.user,
@@ -248,7 +248,7 @@ export default class TenantService {
if (foundTenant) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.USER_EMAIL_ALREADY_EXIST_ERROR,
+ errorCode: HTTPError.TENANT_ALREADY_EXIST,
message: `The tenant with subdomain '${filteredRequest.subdomain}' already exists`,
module: MODULE_NAME, method: 'handleCreateTenant',
user: req.user,

MODIFY
src/types/HTTPError.ts
src/types/HTTPError.ts
@@ -35,6 +35,7 @@ export enum HTTPError {
USER_ACCOUNT_INACTIVE_ERROR = 594,
USER_ACCOUNT_CHANGED = 595,
TENANT_COMPONENT_CHANGED = 596,
+ TENANT_ALREADY_EXIST = 597,
INVALID_CAPTCHA = 530,
INVALID_TOKEN_ERROR = 540,

MODIFY
test/api/TenantTest.ts
test/api/TenantTest.ts
@@ -2,7 +2,7 @@ import chai, { expect } from 'chai';
import CentralServerService from '../api/client/CentralServerService';
import Factory from '../factories/Factory';
-import Tenant from '../types/Tenant';
+import Tenant from '../../src/types/Tenant';
import TestUtils from './TestUtils';
import chaiSubset from 'chai-subset';
import faker from 'faker';
@@ -250,5 +250,45 @@ describe('Tenant tests', function() {
// Check
expect(response.status).to.equal(500);
});
+
+ it('Should not be possible to create a tenant with an already existing subdomain', async () => {
+ // Create
+ 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(200);
+
+ // Create
+ tenant = Factory.tenant.build();
+ tenant.subdomain = tenantSubdomain;
+ // Call
+ response = await CentralServerService.defaultInstance.createEntity(
+ CentralServerService.defaultInstance.tenantApi, tenant, false);
+ // Check
+ expect(response.status).to.equal(597);
+ });
+
+ it('Should not be possible to create a tenant with an already existing name', async () => {
+ // Create
+ let tenant: Tenant = Factory.tenant.build();
+ const tenantName = tenant.name;
+ // Call
+ let response = await CentralServerService.defaultInstance.createEntity(
+ CentralServerService.defaultInstance.tenantApi, tenant, false);
+ // Check
+ expect(response.status).to.equal(200);
+
+ // Create
+ tenant = Factory.tenant.build();
+ tenant.name = tenantName;
+ // Call
+ response = await CentralServerService.defaultInstance.createEntity(
+ CentralServerService.defaultInstance.tenantApi, tenant, false);
+ // Check
+ expect(response.status).to.equal(597);
+ });
});
});

Fixed tenant creation error return code