|
| 1 | +import { lint, validate } from '../src/lint'; |
| 2 | +import { hasErrorDiagnostic, hasWarningDiagnostic } from '../src/utils'; |
| 3 | + |
| 4 | +describe('lint() & validate()', function() { |
| 5 | + describe('lint()', function() { |
| 6 | + it('should lint invalid document', async function() { |
| 7 | + const document = { |
| 8 | + asyncapi: '2.0.0', |
| 9 | + info: { |
| 10 | + title: 'Valid AsyncApi document', |
| 11 | + version: '1.0', |
| 12 | + }, |
| 13 | + } |
| 14 | + |
| 15 | + const diagnostics = await lint(document); |
| 16 | + if (!diagnostics) { |
| 17 | + return; |
| 18 | + } |
| 19 | + |
| 20 | + expect(diagnostics.length > 0).toEqual(true); |
| 21 | + expect(hasErrorDiagnostic(diagnostics)).toEqual(true); |
| 22 | + expect(hasWarningDiagnostic(diagnostics)).toEqual(true); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should lint valid document', async function() { |
| 26 | + const document = { |
| 27 | + asyncapi: '2.0.0', |
| 28 | + info: { |
| 29 | + title: 'Valid AsyncApi document', |
| 30 | + version: '1.0', |
| 31 | + }, |
| 32 | + channels: {} |
| 33 | + } |
| 34 | + |
| 35 | + const diagnostics = await lint(document); |
| 36 | + if (!diagnostics) { |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + expect(diagnostics.length > 0).toEqual(true); |
| 41 | + expect(hasErrorDiagnostic(diagnostics)).toEqual(false); |
| 42 | + expect(hasWarningDiagnostic(diagnostics)).toEqual(true); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('validate()', function() { |
| 47 | + it('should validate invalid document', async function() { |
| 48 | + const document = JSON.stringify({ |
| 49 | + asyncapi: '2.0.0', |
| 50 | + info: { |
| 51 | + title: 'Valid AsyncApi document', |
| 52 | + version: '1.0', |
| 53 | + }, |
| 54 | + }, undefined, 2); |
| 55 | + const { validated, diagnostics } = await validate(document); |
| 56 | + |
| 57 | + expect(validated).toBeUndefined(); |
| 58 | + expect(diagnostics.length > 0).toEqual(true); |
| 59 | + }); |
| 60 | + |
| 61 | + it('should validate valid document', async function() { |
| 62 | + const document = JSON.stringify({ |
| 63 | + asyncapi: '2.0.0', |
| 64 | + info: { |
| 65 | + title: 'Valid AsyncApi document', |
| 66 | + version: '1.0', |
| 67 | + }, |
| 68 | + channels: {} |
| 69 | + }, undefined, 2); |
| 70 | + const { validated, diagnostics } = await validate(document); |
| 71 | + |
| 72 | + expect(validated).not.toBeUndefined(); |
| 73 | + expect(diagnostics.length > 0).toEqual(true); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should validate valid document - do not allow warning severity', async function() { |
| 77 | + const document = JSON.stringify({ |
| 78 | + asyncapi: '2.0.0', |
| 79 | + info: { |
| 80 | + title: 'Valid AsyncApi document', |
| 81 | + version: '1.0', |
| 82 | + }, |
| 83 | + channels: {} |
| 84 | + }, undefined, 2); |
| 85 | + const { validated, diagnostics } = await validate(document, { allowedSeverity: { warning: false } }); |
| 86 | + |
| 87 | + expect(validated).toBeUndefined(); |
| 88 | + expect(diagnostics.length > 0).toEqual(true); |
| 89 | + }); |
| 90 | + }); |
| 91 | +}); |
0 commit comments