|
| 1 | +import * as path from 'path' |
| 2 | +import generateOutput from '../../src/utils/output' |
| 3 | +const invalidJsonOutput = require('../data/invalidRegex.json') |
| 4 | +const invalidTableOutput = require('../data/tableData.json') |
| 5 | +const regexMessages = require('../../messages/index.json').validateRegex |
| 6 | + |
| 7 | +jest.mock('fs') |
| 8 | + |
| 9 | +describe('Generate Output after Stack is Processed', () => { |
| 10 | + beforeEach(() => { |
| 11 | + jest.restoreAllMocks() |
| 12 | + }) |
| 13 | + |
| 14 | + test('Filepath Flag is not set & Invalid Regex is found', async () => { |
| 15 | + const resultFile = 'results.csv' |
| 16 | + const storagePath = path.resolve(__dirname, '../../', resultFile) |
| 17 | + const consoleSpy = jest.spyOn(console, 'log') |
| 18 | + await generateOutput({}, invalidJsonOutput, invalidTableOutput) |
| 19 | + expect(consoleSpy).toHaveBeenCalledTimes(4) |
| 20 | + expect(consoleSpy).toHaveBeenCalledWith(regexMessages.tableOutput) |
| 21 | + expect(consoleSpy).toHaveBeenCalledWith(regexMessages.csvOutput, storagePath) |
| 22 | + expect(consoleSpy).toHaveBeenCalledWith(regexMessages.docsLink) |
| 23 | + }) |
| 24 | + |
| 25 | + test('Filepath Flag is set & Invalid Regex is found', async () => { |
| 26 | + const flags = { |
| 27 | + filePath: '/path/to/output/directory/', |
| 28 | + } |
| 29 | + const resultFile = 'results.csv' |
| 30 | + const storagePath = flags.filePath + resultFile |
| 31 | + const consoleSpy = jest.spyOn(console, 'log') |
| 32 | + await generateOutput(flags, invalidJsonOutput, invalidTableOutput) |
| 33 | + expect(consoleSpy).toHaveBeenCalledTimes(4) |
| 34 | + expect(consoleSpy).toHaveBeenCalledWith(regexMessages.tableOutput) |
| 35 | + expect(consoleSpy).toHaveBeenCalledWith(regexMessages.csvOutput, storagePath) |
| 36 | + expect(consoleSpy).toHaveBeenCalledWith(regexMessages.docsLink) |
| 37 | + }) |
| 38 | + |
| 39 | + test('Invalid Regex is not found', async () => { |
| 40 | + const consoleSpy = jest.spyOn(console, 'log') |
| 41 | + await generateOutput({}, [], []) |
| 42 | + expect(consoleSpy).toHaveBeenCalledTimes(1) |
| 43 | + expect(consoleSpy).toHaveBeenCalledWith(regexMessages.noInvalidRegex) |
| 44 | + }) |
| 45 | +}) |
0 commit comments