Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

covered untested files #89

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion multitenancy-rest-service/src/iam/keycloakUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export class KeycloakUser {
entitlements: false,
context: {
attributes: {}
}
},
}

);
Expand Down
195 changes: 186 additions & 9 deletions multitenancy-rest-service/test/unit/app.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('Testing AppController', () => {
createTable: jest.fn(() => of(mockMessage)),
createRealm: jest.fn(),
getAdminDetails: jest.fn(),
createRedirectUrl: jest.fn(),
createUser: jest.fn(),
listAllUser: jest.fn(),
userInfo: jest.fn(),
Expand Down Expand Up @@ -104,6 +105,19 @@ describe('Testing AppController', () => {
mockgetAccessToken.mockRestore();
});

it('Testing appcontroller "when login failed"', async () => {
const mockBody = {
username: '',
password: process.env.TEST_PASSWORD,
tenantName: 'tenantName',
clientId: 'clientId',
clientSecret: 'clientSecret',
}

expect(async () => await appController.login(mockBody, mockResponse)).rejects.toThrow('Please enter userName');

});

it('Testing appcontroller "logout"', async () => {
const mockBody = {
tenantName: 'tenantName',
Expand All @@ -130,6 +144,16 @@ describe('Testing AppController', () => {
mockrefreshAccessToken.mockRestore();
});

it('Testing appcontroller "forgetPassword"', () => {
mockRequest.query ={
tenantName: 'tenantName'
};
const createRedirectUrl = jest.spyOn(appService, 'createRedirectUrl');
appController.forgotPassword(mockRequest,mockResponse);
expect(createRedirectUrl).toHaveBeenCalled();
createRedirectUrl.mockRestore();
});

it('Testing appcontroller "publicKey"', async () => {
mockRequest.params = {
tenantName: 'tenantName'
Expand Down Expand Up @@ -181,7 +205,7 @@ describe('Testing AppController', () => {
});

it('Testing appcontroller "getTenantConfig"', async () => {
mockRequest.params = {
mockRequest.query = {
tenantName: 'tenantName',
};
mockRequest.headers = {
Expand All @@ -195,10 +219,28 @@ describe('Testing AppController', () => {
mockSubscribe.mockRestore();
});

it('Testing appcontroller "listAllTenant"', async () => {
it('Testing appcontroller "when getTenantConfig gets failed"', async () => {
mockRequest.query = {
tenantName: 'tenantname',
};
mockRequest.headers = {
authorization: authToken
};

expect(async () => await appController.getTenantConfig(mockRequest, mockResponse)).rejects.toThrow("Not Allowed");
});

it('Testing appcontroller "listAllTenant"', () => {
mockRequest.query = {
tenantName: 'tenantName',
isDeleted: 'true',
page: '1'
};
const mockSubscribe = jest.spyOn(Observable.prototype, 'subscribe');
const listAllTenant = jest.spyOn(appService, 'listAllTenant');
appController.listAllTenant(mockRequest, mockResponse);
expect(mockSubscribe).toHaveBeenCalled();
expect(listAllTenant).toHaveBeenCalledWith('tenantName', 'true','1');
mockSubscribe.mockRestore();
});

Expand All @@ -217,10 +259,31 @@ describe('Testing AppController', () => {
mockSubscribe.mockRestore();
});

it('Testing appcontroller "when updateDescription gets failed"', async () => {
mockRequest.body = {
action: {
tenantName: '__',
description: 'newDescription'
}
};
expect(async () => await appController.updateDescription(mockRequest, mockResponse)).rejects.toThrow('Updation Not Allowed');
});


it('Testing appcontroller "deleteTenant"', async () => {
mockRequest.params ={
tenantName: 'tenantName'
};

mockRequest.headers = {
authorization: 'Bearer token'
};

const mockSubscribe = jest.spyOn(Observable.prototype, 'subscribe');
const deleteTenant = jest.spyOn(appService, 'deleteTenant');
await appController.deleteTenant(mockRequest, mockResponse);
expect(mockSubscribe).toHaveBeenCalled();
expect(deleteTenant).toHaveBeenCalledWith('tenantName', mockRequest.headers['authorization']);
mockSubscribe.mockRestore();
});

Expand All @@ -236,7 +299,7 @@ describe('Testing AppController', () => {
}
};
mockRequest.body = {
tenantName: 'tenantName',
tenantName: '',
password: process.env.TEST_PASSWORD,
userDetails: {
userName: 'userName',
Expand All @@ -258,7 +321,7 @@ describe('Testing AppController', () => {

it('Testing appcontroller "listAllUser"', async () => {
mockRequest.query = {
tenantName: 'tenantName',
tenantName: '',
page: '1'
};

Expand All @@ -279,8 +342,8 @@ describe('Testing AppController', () => {

it('Testing appcontroller "getUserInfo"', async () => {
mockRequest.query = {
tenantName: 'tenantName',
usertName: 'usertName',
tenantName: '',
userName: 'userName',
};

mockRequest.headers = {
Expand All @@ -297,7 +360,7 @@ describe('Testing AppController', () => {

it('Testing appcontroller "updateUser"', async () => {
mockRequest.body = {
tenantName: 'tenantName',
tenantName: '',
userName: 'userName',
action: {
firstName: 'firstName'
Expand All @@ -316,6 +379,22 @@ describe('Testing AppController', () => {
mockSend.mockRestore();
});

it('Testing appcontroller "when updateUser gets failed"', async () => {
mockRequest.body = {
tenantName: 'tenantName',
userName: '',
action: {
firstName: 'firstName'
}
};

mockRequest.headers = {
authorization: authToken
};

expect(async () => await appController.updateUser(mockRequest, mockResponse)).rejects.toThrow('Please enter userName');
});

it('Testing appcontroller "deleteUser"', async () => {
mockRequest.params = {
tenantName: 'tenantName',
Expand All @@ -334,6 +413,19 @@ describe('Testing AppController', () => {
mockSend.mockRestore();
});

it('Testing appcontroller "when deleteUser gets failed"', async () => {
mockRequest.params = {
tenantName: 'tenantName',
userName: 'userName',
};

mockRequest.headers = {
authorization: authToken
};

expect(async () => await appController.deleteUser(mockRequest, mockResponse)).rejects.toThrow("Not Allowed");
});

it('Testing appcontroller "tenantClient"', async () => {
mockRequest.body = {
tenantName: 'string',
Expand Down Expand Up @@ -371,9 +463,22 @@ describe('Testing AppController', () => {
mockSend.mockRestore();
});

it('Testing appcontroller "when createRole gets failed"', async () => {
mockRequest.body = {
tenantName: '',
roleDetails: {
name: 'string'
}
};
mockRequest.headers = {
authorization: authToken
};
expect(async () => await appController.createRole(mockRequest, mockResponse)).rejects.toThrow("Please enter tenantName");
});

it('Testing appcontroller "getAvailableRoles"', async () => {
mockRequest.query = {
tenantName: 'tenantName',
tenantName: '',
};
mockRequest.headers = {
authorization: authToken
Expand Down Expand Up @@ -402,6 +507,30 @@ describe('Testing AppController', () => {
mockSend.mockRestore();
});

it('Testing appcontroller "when getRoleInfo tenantName get failed"', async () => {
mockRequest.query = {
tenantName: '',
roleName: 'roleName'
};
mockRequest.headers = {
authorization: authToken
};

expect(async () => await appController.getRoleInfo(mockRequest, mockResponse)).rejects.toThrow("Please enter tenantName");
});

it('Testing appcontroller "when getRoleInfo roleName get failed"', async () => {
mockRequest.query = {
tenantName: 'tenantName',
roleName: ''
};
mockRequest.headers = {
authorization: authToken
};

expect(async () => await appController.getRoleInfo(mockRequest, mockResponse)).rejects.toThrow("Please enter roleName");
});

it('Testing appcontroller "updateRole"', async () => {
mockRequest.body = {
tenantName: 'tenantName',
Expand All @@ -421,6 +550,37 @@ describe('Testing AppController', () => {
mockSend.mockRestore();
});

it('Testing appcontroller "when updateRole tenantName gets failed"', async () => {
mockRequest.body = {
tenantName: '',
roleName: 'roleName',
action: {
name: 'string'
}
};
mockRequest.headers = {
authorization: authToken
};

expect(async () => await appController.updateRole(mockRequest, mockResponse)).rejects.toThrow("Please enter tenantName");
});

it('Testing appcontroller "when updateRole roleName gets failed"', async () => {
mockRequest.body = {
tenantName: 'tenantName',
roleName: '',
action: {
name: 'string'
}
};
mockRequest.headers = {
authorization: authToken
};

expect(async () => await appController.updateRole(mockRequest, mockResponse)).rejects.toThrow("Please enter roleName");
});


it('Testing appcontroller "deleteRole"', async () => {
mockRequest.params = {
tenantName: 'tenantName',
Expand Down Expand Up @@ -460,7 +620,7 @@ describe('Testing AppController', () => {

it('Testing appcontroller "listPermission"', async () => {
mockRequest.query = {
tenantName: 'string',
tenantName: '',
clientName: 'string',
}
mockRequest.headers = {
Expand Down Expand Up @@ -589,6 +749,23 @@ describe('Testing AppController', () => {
connect.mockRestore();
});

it('Testing appcontroller "when connectDatabase method gets failed"', async () => {
mockRequest.query = {
host: 'host',
port: '3306',
tenantName: '',
password: process.env.TEST_PASSWORD,
dbName: 'tenant_db'
}

mockRequest.headers = {
authorization: authToken
};

expect(async () => await appController.connectDatabase(mockRequest, mockResponse)).rejects.toThrow("Updation Not Allowed");

});

it('Testing appcontroller "createTable"', async () => {
const mockSubscribe = jest.spyOn(Observable.prototype, 'subscribe');
await appController.createTable(mockRequest, mockResponse);
Expand Down
Loading