|
| 1 | +const Ajv = require('ajv'); |
| 2 | +const yaml = require('js-yaml'); |
| 3 | +const fs = require('fs'); |
| 4 | + |
| 5 | +const { ServerlessReqValidatorPluginConfigSchema } = require('../src/index'); |
| 6 | + |
| 7 | +const ajv = new Ajv(); |
| 8 | + |
| 9 | +const validateConfig = ajv.compile({ |
| 10 | + type: 'object', |
| 11 | + ...ServerlessReqValidatorPluginConfigSchema, |
| 12 | +}); |
| 13 | + |
| 14 | +describe('serverless-reqvalidator-plugin schema', () => { |
| 15 | + it('should validate a configuration without reqValidatorName property', () => { |
| 16 | + const config = yaml.load(fs.readFileSync('./test/fixtures/noValidatorFunction.yaml', 'utf8')); |
| 17 | + |
| 18 | + const valid = validateConfig(config.functions.hello.events[0].http); |
| 19 | + expect(valid).toBeTruthy(); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should validate a configuration with a local reqValidatorName property', () => { |
| 23 | + const config = yaml.load(fs.readFileSync('./test/fixtures/localValidatorFunction.yaml', 'utf8')); |
| 24 | + |
| 25 | + const valid = validateConfig(config.functions.hello.events[0].http); |
| 26 | + expect(valid).toBeTruthy(); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should validate a configuration with an external reqValidatorName property', () => { |
| 30 | + const config = yaml.load(fs.readFileSync('./test/fixtures/externalValidatorFunction.yaml', 'utf8')); |
| 31 | + |
| 32 | + const valid = validateConfig(config.functions.hello.events[0].http); |
| 33 | + expect(valid).toBeTruthy(); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should not validate a configuration with an invalid reqValidatorName property', () => { |
| 37 | + const config = yaml.load(fs.readFileSync('./test/fixtures/invalidValidatorFunction.yaml', 'utf8')); |
| 38 | + const valid = validateConfig(config.functions.hello.events[0].http); |
| 39 | + expect(valid).toBeFalsy(); |
| 40 | + }); |
| 41 | +}); |
0 commit comments