Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

test: add unit test #8

Merged
merged 1 commit into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"latest"
]
}
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
coverage/
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ npm-debug.log
coverage/
.idea/
.editorconfig

6 changes: 6 additions & 0 deletions .istanbul.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
instrumentation:
include-all-sources: true
default-excludes: true
excludes: ['lib/**','*.test.js']
reporting:
print: both
61 changes: 32 additions & 29 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const AWS = require('aws-sdk');

class APIGatewayCustomiser {
constructor(serverless, options) {
this.createDeploymentRetryDelay = options.createDeploymentRetryDelay || 5 * 1000;
this.serverless = serverless;
this.options = options;
// this.options = options;
this.custom = this.serverless.service.custom;
this.hooks = {
'after:deploy:deploy': this.afterDeployFunctions.bind(this)
Expand Down Expand Up @@ -34,7 +35,7 @@ class APIGatewayCustomiser {
this.serverless.cli.log('API Gateway Configuring: Start');
/** Filter functions for those need API Gateway Config */
if (this.custom.apigateway) {
new Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
this.apiGatewaySDK.getRestApis({ limit: 500 }, (err, data) => {
if (err) {
reject(err);
Expand All @@ -45,29 +46,31 @@ class APIGatewayCustomiser {
}
});
})
.then((apiId) => {
const promises = [];
if (this.custom.apigateway.responses) {
this.custom.apigateway.responses.forEach((response) => {
if (response.response.headers) {
promises.push(this.configHeaders(apiId, response.response));
}
if (response.response.bodyMappingTemplate) {
promises.push(this.configBodyMapping(apiId, response.response));
}
});
}
if (this.custom.apigateway.binaryTypes) {
promises.push(this.configBinary(apiId));
}
promises.push(apiId);
return Promise.all(promises);
})
.then(promiseData => this.createDeployment(promiseData.pop()))
.then(() => this.serverless.cli.log('API Gateway Configuring: End'))
.catch((err) => {
throw err;
});
.then((apiId) => {
const promises = [];
if (this.custom.apigateway.responses) {
this.custom.apigateway.responses.forEach((response) => {
if (response.response.headers) {
promises.push(this.configHeaders(apiId, response.response));
}
if (response.response.bodyMappingTemplate) {
promises.push(this.configBodyMapping(apiId, response.response));
}
});
}
if (this.custom.apigateway.binaryTypes) {
promises.push(this.configBinary(apiId));
}
promises.push(apiId);
return Promise.all(promises);
})
.then((promiseData) => {
this.createDeployment(promiseData.pop());
})
.then(() => this.serverless.cli.log('API Gateway Configuring: End'))
.catch((err) => {
throw err;
});
}
}

Expand All @@ -89,13 +92,13 @@ class APIGatewayCustomiser {
this.serverless.cli.log('Deployment failed! Retry in 5s');
setTimeout(() => {
this.createDeployment(apiId);
}, 5 * 1000);
}, this.createDeploymentRetryDelay);
} else {
reject(error);
}
} else {
this.serverless.cli.log('Create deployment finished');
resolve();
resolve('Success');
}
});
});
Expand All @@ -122,7 +125,7 @@ class APIGatewayCustomiser {
reject(err);
} else {
this.serverless.cli.log('API Gateway Configuring: Headers are set correctly');
resolve('Header set successfully:', response.type);
resolve(`Header set successfully: ${response.type.toString()}`);
}
});
});
Expand Down Expand Up @@ -154,7 +157,7 @@ class APIGatewayCustomiser {
reject(err);
} else {
this.serverless.cli.log('API Gateway Configuring: Body mapping templates are set correctly');
resolve('Body Mapping Templates set successfully:', response.type);
resolve(`Body Mapping Templates set successfully: ${response.type.toString()}`);
}
});
});
Expand Down
Loading