|
| 1 | +import Utils from '../../../src/PowerShell/Utilities/Utils'; |
| 2 | + |
| 3 | +const version: string = '9.0.0'; |
| 4 | +const moduleName: string = 'az'; |
| 5 | + |
| 6 | +afterEach(() => { |
| 7 | + jest.restoreAllMocks(); |
| 8 | +}); |
| 9 | + |
| 10 | +describe('Testing isValidVersion', () => { |
| 11 | + const validVersion: string = '1.2.4'; |
| 12 | + const invalidVersion: string = 'a.bcd'; |
| 13 | + |
| 14 | + test('isValidVersion should be true', () => { |
| 15 | + expect(Utils.isValidVersion(validVersion)).toBeTruthy(); |
| 16 | + }); |
| 17 | + test('isValidVersion should be false', () => { |
| 18 | + expect(Utils.isValidVersion(invalidVersion)).toBeFalsy(); |
| 19 | + }); |
| 20 | +}); |
| 21 | + |
| 22 | +describe('Testing setPSModulePath', () => { |
| 23 | + test('PSModulepath with azPSVersion non-empty', () => { |
| 24 | + if(!process.env.PSModulePath) { |
| 25 | + process.env.PSModulePath = process.env.PSModulePath + "modulePath"; |
| 26 | + } |
| 27 | + Utils.setPSModulePath(version); |
| 28 | + expect(process.env.PSModulepath).toContain(version); |
| 29 | + }); |
| 30 | + test('PSModulePath with azPSVersion empty', () => { |
| 31 | + const currPSModulePath = process.env.PSModulepath; |
| 32 | + Utils.setPSModulePath(); |
| 33 | + expect(process.env.PSModulePath).not.toEqual(currPSModulePath); |
| 34 | + }); |
| 35 | +}); |
| 36 | + |
| 37 | +describe('Testing getLatestModule', () => { |
| 38 | + let getLatestModuleSpy; |
| 39 | + |
| 40 | + beforeEach(() => { |
| 41 | + getLatestModuleSpy = jest.spyOn(Utils, 'getLatestModule'); |
| 42 | + }); |
| 43 | + test('getLatestModule should pass', async () => { |
| 44 | + getLatestModuleSpy.mockImplementationOnce((_moduleName: string) => Promise.resolve(version)); |
| 45 | + await Utils.getLatestModule(moduleName); |
| 46 | + expect(getLatestModuleSpy).toHaveBeenCalled(); |
| 47 | + }); |
| 48 | +}); |
0 commit comments