|
| 1 | +const config = require('../../../../src/.defaultsForValidator').defaults.shared; |
| 2 | +const expect = require('expect'); |
| 3 | +const { |
| 4 | + validate |
| 5 | +} = require('../../../../src/plugins/validation/2and3/semantic-validators/info'); |
| 6 | + |
| 7 | +describe('validation plugin - semantic - info', () => { |
| 8 | + //this is for openapi object |
| 9 | + it('should return an error when a parameter does not have info', () => { |
| 10 | + const spec = { |
| 11 | + Openapi: '3.0.0' |
| 12 | + }; |
| 13 | + |
| 14 | + const res = validate({ jsSpec: spec }, config); |
| 15 | + expect(res.errors.length).toEqual(1); |
| 16 | + expect(res.errors[0].path).toEqual(['info']); |
| 17 | + expect(res.errors[0].message).toEqual( |
| 18 | + 'API definition must have an `info` object' |
| 19 | + ); |
| 20 | + }); |
| 21 | + it('should return an error when a info is not defined as a proper object', () => { |
| 22 | + const spec = { |
| 23 | + Openapi: '3.0.0', |
| 24 | + info: 'abc' |
| 25 | + }; |
| 26 | + |
| 27 | + const res = validate({ jsSpec: spec }, config); |
| 28 | + expect(res.errors.length).toEqual(1); |
| 29 | + expect(res.errors[0].path).toEqual(['info']); |
| 30 | + expect(res.errors[0].message).toEqual( |
| 31 | + 'API definition must have an `info` object' |
| 32 | + ); |
| 33 | + }); |
| 34 | + it('should return an error when a title and version is not a string', () => { |
| 35 | + const spec = { |
| 36 | + Openapi: '3.0.0', |
| 37 | + info: { |
| 38 | + title: 32, |
| 39 | + version: '32' |
| 40 | + } |
| 41 | + }; |
| 42 | + |
| 43 | + const res = validate({ jsSpec: spec }, config); |
| 44 | + expect(res.errors.length).toEqual(1); |
| 45 | + expect(res.errors[0].path).toEqual(['info', 'title']); |
| 46 | + expect(res.errors[0].message).toEqual( |
| 47 | + '`info` object must have a string-type `title` field' |
| 48 | + ); |
| 49 | + }); |
| 50 | + it('should return an error when a title and version is not a string', () => { |
| 51 | + const spec = { |
| 52 | + Openapi: '3.0.0', |
| 53 | + info: { |
| 54 | + title: '32', |
| 55 | + version: 32 |
| 56 | + } |
| 57 | + }; |
| 58 | + |
| 59 | + const res = validate({ jsSpec: spec }, config); |
| 60 | + expect(res.errors.length).toEqual(1); |
| 61 | + expect(res.errors[0].path).toEqual(['info', 'version']); |
| 62 | + expect(res.errors[0].message).toEqual( |
| 63 | + '`info` object must have a string-type `version` field' |
| 64 | + ); |
| 65 | + }); |
| 66 | + it('should return an error when a title is missing', () => { |
| 67 | + const spec = { |
| 68 | + Openapi: '3.0.0', |
| 69 | + info: { |
| 70 | + version: '32' |
| 71 | + } |
| 72 | + }; |
| 73 | + |
| 74 | + const res = validate({ jsSpec: spec }, config); |
| 75 | + expect(res.errors.length).toEqual(1); |
| 76 | + expect(res.errors[0].path).toEqual(['info', 'title']); |
| 77 | + expect(res.errors[0].message).toEqual( |
| 78 | + '`info` object must have a string-type `title` field' |
| 79 | + ); |
| 80 | + }); |
| 81 | + it('should return an error when a version is missing', () => { |
| 82 | + const spec = { |
| 83 | + Openapi: '3.0.0', |
| 84 | + info: { |
| 85 | + title: '32' |
| 86 | + } |
| 87 | + }; |
| 88 | + |
| 89 | + const res = validate({ jsSpec: spec }, config); |
| 90 | + expect(res.errors.length).toEqual(1); |
| 91 | + expect(res.errors[0].path).toEqual(['info', 'version']); |
| 92 | + expect(res.errors[0].message).toEqual( |
| 93 | + '`info` object must have a string-type `version` field' |
| 94 | + ); |
| 95 | + }); |
| 96 | +}); |
0 commit comments