Philipp Muens 919caa8f91 Remove validations for existence of compiledCloudFormationTemplate
Because it's already available at the beginning of the deploy plugin as the core CloudFormation
template will be attached there (which is then used to merge other resources into it later on).
2016-08-15 15:36:54 +02:00

122 lines
2.8 KiB
JavaScript

'use strict';
const expect = require('chai').expect;
const AwsCompileApigEvents = require('../index');
const Serverless = require('../../../../../../../Serverless');
describe('#validate()', () => {
let awsCompileApigEvents;
let serverless;
beforeEach(() => {
serverless = new Serverless();
serverless.service.provider.compiledCloudFormationTemplate = { Resources: {} };
awsCompileApigEvents = new AwsCompileApigEvents(serverless);
awsCompileApigEvents.options = {
stage: 'dev',
region: 'us-east-1',
};
awsCompileApigEvents.serverless.service.environment = {
vars: {},
stages: {
dev: {
vars: {},
regions: {},
},
},
};
awsCompileApigEvents.serverless.service.environment.stages.dev.regions['us-east-1'] = {
vars: {},
};
});
it('should validate the http events "path" property', () => {
awsCompileApigEvents.serverless.service.functions = {
first: {
events: [
{
http: {
method: 'POST',
},
},
],
},
};
expect(() => awsCompileApigEvents.validate()).to.throw(Error);
});
it('should validate the http events "method" property', () => {
awsCompileApigEvents.serverless.service.functions = {
first: {
events: [
{
http: {
path: 'foo/bar',
},
},
],
},
};
expect(() => awsCompileApigEvents.validate()).to.throw(Error);
});
it('should validate the http events object syntax method is case insensitive', () => {
awsCompileApigEvents.serverless.service.functions = {
first: {
events: [
{
http: {
method: 'POST',
path: 'foo/bar',
},
},
{
http: {
method: 'post',
path: 'foo/bar',
},
},
],
},
};
expect(() => awsCompileApigEvents.validate()).to.not.throw(Error);
});
it('should validate the http events string syntax method is case insensitive', () => {
awsCompileApigEvents.serverless.service.functions = {
first: {
events: [
{
http: 'POST foo/bar',
},
{
http: 'post foo/bar',
},
],
},
};
expect(() => awsCompileApigEvents.validate()).to.not.throw(Error);
});
it('should throw an error if the method is invalid', () => {
awsCompileApigEvents.serverless.service.functions = {
first: {
events: [
{
http: {
path: 'foo/bar',
method: 'INVALID',
},
},
],
},
};
expect(() => awsCompileApigEvents.validate()).to.throw(Error);
});
});