|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, salesforce.com, inc. |
| 3 | + * All rights reserved. |
| 4 | + * Licensed under the BSD 3-Clause license. |
| 5 | + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause |
| 6 | + */ |
| 7 | +import { IConfig } from '@oclif/config'; |
| 8 | +import { expect } from '@salesforce/command/lib/test'; |
| 9 | +import Inspect from '../../lib/commands/cli/versions/inspect'; |
| 10 | +import { Channel, Info, Location } from '../../src/commands/cli/versions/inspect'; |
| 11 | + |
| 12 | +describe('cli:versions:inspect', () => { |
| 13 | + let cmd; |
| 14 | + beforeEach(() => { |
| 15 | + cmd = new Inspect(['-c', 'stable', '-l', 'archive'], {} as IConfig); |
| 16 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 17 | + // @ts-ignore |
| 18 | + cmd.ux = { |
| 19 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 20 | + // @ts-ignore |
| 21 | + log: () => {}, |
| 22 | + }; |
| 23 | + }); |
| 24 | + |
| 25 | + it('should throw an error when versions are different', () => { |
| 26 | + const results: Info[] = [ |
| 27 | + { |
| 28 | + location: Location.ARCHIVE, |
| 29 | + version: '1.0.0', |
| 30 | + origin: '', |
| 31 | + channel: Channel.STABLE, |
| 32 | + dependencies: [{ name: 'dep1', version: '1.0.0' }], |
| 33 | + }, |
| 34 | + { |
| 35 | + location: Location.ARCHIVE, |
| 36 | + version: '1.1.1', |
| 37 | + origin: '', |
| 38 | + channel: Channel.STABLE, |
| 39 | + dependencies: [{ name: 'dep1', version: '1.1.1' }], |
| 40 | + }, |
| 41 | + ]; |
| 42 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 43 | + // @ts-ignore private method |
| 44 | + expect(() => cmd.logResults(results, Location.ARCHIVE, [Channel.STABLE])).to.throw('Version Mismatch'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should throw an error when versions are different and locations are different', () => { |
| 48 | + const results: Info[] = [ |
| 49 | + { |
| 50 | + location: Location.NPM, |
| 51 | + version: '1.0.0', |
| 52 | + origin: '', |
| 53 | + channel: Channel.STABLE, |
| 54 | + dependencies: [{ name: 'dep1', version: '1.0.0' }], |
| 55 | + }, |
| 56 | + { |
| 57 | + location: Location.ARCHIVE, |
| 58 | + version: '1.1.1', |
| 59 | + origin: '', |
| 60 | + channel: Channel.STABLE, |
| 61 | + dependencies: [{ name: 'dep1', version: '1.1.1' }], |
| 62 | + }, |
| 63 | + ]; |
| 64 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 65 | + // @ts-ignore private method |
| 66 | + expect(() => cmd.logResults(results, Location.ARCHIVE, [Channel.STABLE])).to.throw('Version Mismatch'); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should not throw an error when versions match', () => { |
| 70 | + const results: Info[] = [ |
| 71 | + { |
| 72 | + location: Location.ARCHIVE, |
| 73 | + version: '1.0.0', |
| 74 | + origin: '', |
| 75 | + channel: Channel.STABLE, |
| 76 | + dependencies: [{ name: 'dep1', version: '1.0.0' }], |
| 77 | + }, |
| 78 | + { |
| 79 | + location: Location.ARCHIVE, |
| 80 | + version: '1.0.0', |
| 81 | + origin: '', |
| 82 | + channel: Channel.STABLE, |
| 83 | + dependencies: [{ name: 'dep1', version: '1.0.0' }], |
| 84 | + }, |
| 85 | + ]; |
| 86 | + try { |
| 87 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 88 | + // @ts-ignore private method |
| 89 | + cmd.logResults(results, Location.ARCHIVE, [Channel.STABLE]); |
| 90 | + } catch (e) { |
| 91 | + expect(e).to.be.undefined; |
| 92 | + } |
| 93 | + }); |
| 94 | +}); |
0 commit comments