|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const lint = require('../../lint.js'); |
| 4 | + |
| 5 | +const commandConfig = { |
| 6 | + quiet: false, |
| 7 | + rules: [], |
| 8 | + skip: [] |
| 9 | +}; |
| 10 | + |
| 11 | +beforeEach(() => { |
| 12 | + jest.resetAllMocks(); |
| 13 | +}); |
| 14 | + |
| 15 | +describe('Lint command', () => { |
| 16 | + describe('properly handles scheme validation', () => { |
| 17 | + test('succesfully validates a valid spec', () => { |
| 18 | + expect.assertions(4); |
| 19 | + const logSpy = jest.spyOn(console, 'log'); |
| 20 | + const warnSpy = jest.spyOn(console, 'warn'); |
| 21 | + const errorSpy = jest.spyOn(console, 'error'); |
| 22 | + |
| 23 | + return lint.command('./test/fixtures/loader/openapi.yaml', commandConfig).then(() => { |
| 24 | + expect(logSpy).toBeCalledTimes(1); |
| 25 | + expect(logSpy.mock.calls[0][0]).toEqual('\x1b[32mSpecification is valid, with 0 lint errors\x1b[0m'); |
| 26 | + expect(warnSpy).toBeCalledTimes(0); |
| 27 | + expect(errorSpy).toBeCalledTimes(0); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + test('displays a validation error on invalid key', () => { |
| 32 | + expect.assertions(4); |
| 33 | + const logSpy = jest.spyOn(console, 'log'); |
| 34 | + const warnSpy = jest.spyOn(console, 'warn'); |
| 35 | + const errorSpy = jest.spyOn(console, 'error'); |
| 36 | + |
| 37 | + return lint.command('./test/fixtures/integration/invalid-key.yaml', commandConfig).catch(() => { |
| 38 | + expect(logSpy).toBeCalledTimes(0); |
| 39 | + expect(warnSpy).toBeCalledTimes(0); |
| 40 | + expect(errorSpy).toBeCalledTimes(2); |
| 41 | + expect(errorSpy).toHaveBeenCalledWith('\x1b[31mSpecification schema is invalid.\x1b[0m'); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + test('displays a validation error on missing reference', () => { |
| 46 | + expect.assertions(4); |
| 47 | + const logSpy = jest.spyOn(console, 'log'); |
| 48 | + const warnSpy = jest.spyOn(console, 'warn'); |
| 49 | + const errorSpy = jest.spyOn(console, 'error'); |
| 50 | + |
| 51 | + return lint.command('./test/fixtures/integration/missing-ref.yaml', commandConfig).catch(() => { |
| 52 | + expect(logSpy).toBeCalledTimes(0); |
| 53 | + expect(warnSpy).toBeCalledTimes(0); |
| 54 | + expect(errorSpy).toBeCalledTimes(2); |
| 55 | + expect(errorSpy).toHaveBeenCalledWith('\x1b[31mSpecification schema is invalid.\x1b[0m'); |
| 56 | + }); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + describe('properly handles linter warnings', () => { |
| 61 | + test('displays a linting error on missing contact field', () => { |
| 62 | + expect.assertions(5); |
| 63 | + const logSpy = jest.spyOn(console, 'log'); |
| 64 | + const warnSpy = jest.spyOn(console, 'warn'); |
| 65 | + const errorSpy = jest.spyOn(console, 'error'); |
| 66 | + |
| 67 | + return lint.command('./test/fixtures/integration/missing-contact.yaml', commandConfig).catch(() => { |
| 68 | + expect(logSpy).toBeCalledTimes(0); |
| 69 | + expect(warnSpy).toBeCalledTimes(1); |
| 70 | + expect(errorSpy).toBeCalledTimes(1); |
| 71 | + expect(errorSpy.mock.calls[0][0]).toEqual('\x1b[31mSpecification contains lint errors: 1\x1b[0m'); |
| 72 | + expect(warnSpy.mock.calls[0][0]).toContain('info-contact'); |
| 73 | + }); |
| 74 | + }); |
| 75 | + }); |
| 76 | +}); |
0 commit comments