Files
login/__tests__/PowerShell/ServicePrinicipalLogin.test.ts
aksm-ms 3ec3e73a1c Added Unit tests (#15)
* Added unit tests for Azure PowerShell

* Added unit tests

* changes in utils

* removed babel

* changed variable name of enable-PSSession

* refactor

* added ci.yml

* changes in utils test
2020-04-08 17:42:18 +05:30

40 lines
1.2 KiB
TypeScript

import { ServicePrincipalLogin } from '../../src/PowerShell/ServicePrincipalLogin';
jest.mock('../../src/PowerShell/Utilities/Utils');
jest.mock('../../src/PowerShell/Utilities/PowerShellToolRunner');
let spnlogin: ServicePrincipalLogin;
beforeAll(() => {
spnlogin = new ServicePrincipalLogin("servicePrincipalID", "servicePrinicipalkey", "tenantId", "subscriptionId");
});
afterEach(() => {
jest.restoreAllMocks();
});
describe('Testing initialize', () => {
let initializeSpy;
beforeEach(() => {
initializeSpy = jest.spyOn(spnlogin, 'initialize');
});
test('ServicePrincipalLogin initialize should pass', async () => {
await spnlogin.initialize();
expect(initializeSpy).toHaveBeenCalled();
});
});
describe('Testing login', () => {
let loginSpy;
beforeEach(() => {
loginSpy = jest.spyOn(spnlogin, 'login');
});
test('ServicePrincipal login should pass', async () => {
loginSpy.mockImplementationOnce(() => Promise.resolve(
console.log('Azure PowerShell session successfully initialized')));
await spnlogin.login();
expect(loginSpy).toHaveBeenCalled();
});
});