|
| 1 | +import * as cli from '../cli'; |
| 2 | +import * as http from '../http-utils'; |
| 3 | +import * as utils from '../utils'; |
| 4 | + |
| 5 | +beforeEach(() => jest.clearAllMocks()); |
| 6 | + |
| 7 | +describe('cli', () => { |
| 8 | + describe('getInput', () => { |
| 9 | + test('should readFile when inputType is `file`', () => { |
| 10 | + jest.spyOn(utils, 'readFile').mockImplementationOnce(() => { }); |
| 11 | + |
| 12 | + cli.getInput('file', ['lol', 'foo'], [], 'callback'); |
| 13 | + |
| 14 | + expect(utils.readFile).toBeCalledTimes(1); |
| 15 | + expect(utils.readFile).toBeCalledWith('lol', 'callback'); |
| 16 | + }); |
| 17 | + |
| 18 | + test('should readStdin when inputType is `stdin`', () => { |
| 19 | + jest.spyOn(utils, 'readStdin').mockImplementationOnce(() => { }); |
| 20 | + |
| 21 | + cli.getInput('stdin', ['lol'], [], 'callback'); |
| 22 | + |
| 23 | + expect(utils.readStdin).toBeCalledTimes(1); |
| 24 | + expect(utils.readStdin).toBeCalledWith('callback'); |
| 25 | + }); |
| 26 | + |
| 27 | + test('should readStdin when inputType is `command`', () => { |
| 28 | + jest.spyOn(cli, 'runGitDiff').mockImplementationOnce(() => { }); |
| 29 | + |
| 30 | + cli.getInput('command', ['lol', 'foo'], [], 'callback'); |
| 31 | + |
| 32 | + expect(cli.runGitDiff).toBeCalledTimes(1); |
| 33 | + expect(cli.runGitDiff).toBeCalledWith(['lol', 'foo'], [], 'callback'); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + describe('preview', () => { |
| 38 | + test('should call `utils.writeFile`', () => { |
| 39 | + jest.spyOn(utils, 'writeFile').mockImplementationOnce(() => { }); |
| 40 | + |
| 41 | + cli.preview('a', 'b'); |
| 42 | + |
| 43 | + expect(utils.writeFile).toBeCalledTimes(1); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + describe('postToDiffy', () => { |
| 48 | + test('should call `http.put`', () => { |
| 49 | + jest.spyOn(http, 'put').mockImplementationOnce(() => Promise.resolve('http://example.com')); |
| 50 | + |
| 51 | + cli.postToDiffy('a', 'print'); |
| 52 | + |
| 53 | + expect(http.put).toBeCalledTimes(1); |
| 54 | + expect(http.put).toBeCalledWith('https://diffy.org/api/diff/', { diff: 'a' }); |
| 55 | + }); |
| 56 | + }); |
| 57 | +}); |
0 commit comments