refactor(deploy): Make resource ids camel case to make them easier to read

This commit is contained in:
Jamie Sutherland 2016-07-29 09:22:08 +01:00
parent 18fbc6ef76
commit 6e14a457c2
2 changed files with 13 additions and 13 deletions

View File

@ -50,8 +50,8 @@ module.exports = {
const resourceName = path.split('/')[path.split('/').length - 1];
const resourcePath = path;
const resourceIndex = this.resourcePaths.indexOf(resourcePath);
const resourceFunction = this.resourceFunctions[resourceIndex] +
path.replace(/\//g, '');
const resourceFunction = _.capitalize(this.resourceFunctions[resourceIndex]) +
resourcesArray.map(_.capitalize).join('');
const resourceLogicalId = `ResourceApigEvent${resourceFunction}`;
this.resourceLogicalIds[resourcePath] = resourceLogicalId;
resourcesArray.pop();
@ -62,8 +62,8 @@ module.exports = {
} else {
const resourceParentPath = resourcesArray.join('/');
const resourceParentIndex = this.resourcePaths.indexOf(resourceParentPath);
const resourceParentFunction = this.resourceFunctions[resourceParentIndex] +
resourcesArray.join('');
const resourceParentFunction = _.capitalize(this.resourceFunctions[resourceParentIndex]) +
resourcesArray.map(_.capitalize).join('');
resourceParentId = `{ "Ref" : "ResourceApigEvent${resourceParentFunction}" }`;
}

View File

@ -39,10 +39,10 @@ describe('#compileResources()', () => {
it('should construct the correct resourceLogicalIds object', () => awsCompileApigEvents
.compileResources().then(() => {
const expectedResourceLogicalIds = {
'foo/bar': 'ResourceApigEventfirstfoobar',
foo: 'ResourceApigEventfirstfoo',
'bar/foo': 'ResourceApigEventfirstbarfoo',
bar: 'ResourceApigEventfirstbar',
'foo/bar': 'ResourceApigEventFirstFooBar',
foo: 'ResourceApigEventFirstFoo',
'bar/foo': 'ResourceApigEventFirstBarFoo',
bar: 'ResourceApigEventFirstBar',
};
expect(awsCompileApigEvents.resourceLogicalIds).to.deep.equal(expectedResourceLogicalIds);
})
@ -51,16 +51,16 @@ describe('#compileResources()', () => {
it('should create resource resources when http events are given', () => awsCompileApigEvents
.compileResources().then(() => {
expect(awsCompileApigEvents.serverless.service.resources.Resources
.ResourceApigEventfirstfoobar.Properties.PathPart)
.ResourceApigEventFirstFooBar.Properties.PathPart)
.to.equal('bar');
expect(awsCompileApigEvents.serverless.service.resources.Resources
.ResourceApigEventfirstfoobar.Properties.ParentId.Ref)
.to.equal('ResourceApigEventfirstfoo');
.ResourceApigEventFirstFooBar.Properties.ParentId.Ref)
.to.equal('ResourceApigEventFirstFoo');
expect(awsCompileApigEvents.serverless.service.resources.Resources
.ResourceApigEventfirstfoo.Properties.ParentId['Fn::GetAtt'][0])
.ResourceApigEventFirstFoo.Properties.ParentId['Fn::GetAtt'][0])
.to.equal('RestApiApigEvent');
expect(awsCompileApigEvents.serverless.service.resources.Resources
.ResourceApigEventfirstbar.Properties.ParentId['Fn::GetAtt'][1])
.ResourceApigEventFirstBar.Properties.ParentId['Fn::GetAtt'][1])
.to.equal('RootResourceId');
})
);