tests and deploy api: refactor more tests, fix deploy api

This commit is contained in:
Austen Collins 2015-08-31 19:55:26 -07:00
parent eaa07cbf82
commit 388082ea5f
8 changed files with 33 additions and 31 deletions

View File

@ -23,7 +23,9 @@ var JawsError = require('../jaws-error'),
Promise.promisifyAll(fs);
module.exports = function(JAWS) {
var client = null;
/**
* Find Or Create Rest Api
* @returns {bluebird|exports|module.exports}
@ -35,6 +37,7 @@ module.exports = function(JAWS) {
// Set Region
state.region = Object.keys(JAWS._meta.projectJson.project.regions)[0];
state.restApiId = JAWS._meta.projectJson.project.regions[state.region].restApiId || null;
// Validate Stage
if (!JAWS._meta.projectJson.project.regions[state.region].stages[state.stage]) {
reject(new JawsError(
@ -42,6 +45,10 @@ module.exports = function(JAWS) {
JawsError.errorCodes.UNKNOWN));
}
// Get AWS Account Number
state.awsAccountNumber = JAWS._meta.projectJson.project.regions[state.region].stages[state.stage].iamRoleArn
state.awsAccountNumber = state.awsAccountNumber.replace('arn:aws:iam::','').split(':')[0];
// Instantiate JawsApiGatewayClient
client = new JawsAPIClient({
accessKeyId: JAWS._meta.credentials.aws_access_key_id,
@ -309,18 +316,21 @@ module.exports = function(JAWS) {
+ state.region
+ ':lambda:path/2015-03-31/functions/arn:aws:lambda:'
+ state.region
+ ':814070455730:function:'
+ ':'
+ state.awsAccountNumber
+ ':function:'
+ [state.stage,
JAWS._meta.projectJson.name,
endpoint.lambda.functionName,
].join('_-_').replace(/ /g, '')
+ '/invocations',
credentials: null,
credentials: JAWS._meta.projectJson.project.regions[state.region].stages[state.stage].iamRoleArn,
requestParameters: endpoint.endpoint.requestParameters || {},
requestTemplates: endpoint.endpoint.requestTemplates || {},
cacheNamespace: endpoint.endpoint.cacheNamespace || null,
cacheKeyParameters: endpoint.endpoint.cacheKeyParameters || [],
};
} else {
reject(new JawsError(
'JAWS API Gateway integration currently supports lambda only',
@ -424,7 +434,7 @@ module.exports = function(JAWS) {
integrationResponseBody.responseTemplates = thisResponse.responseTemplates;
// Add SelectionPattern
integrationResponseBody.selectionPattern = responseKey;
integrationResponseBody.selectionPattern = responseKey === 'default' ? null : responseKey;// null = default
// Create Integration Response
client.putIntegrationResponse(state.restApiId,

View File

@ -244,7 +244,7 @@ exports.createBucket = function(awsProfile, awsRegion, bucketName) {
});
};
exports.putS3Oject = function(awsProfile, awsRegion, params) {
exports.putS3Object = function(awsProfile, awsRegion, params) {
this.configAWS(awsProfile, awsRegion);
var s3 = Promise.promisifyAll(new AWS.S3());
return s3.putObjectAsync(params);
@ -301,7 +301,7 @@ exports.putEnvFile = function(awsProfile, awsRegion, bucketName, projectName, st
Body: contents,
};
return this.putS3Oject(awsProfile, awsRegion, params);
return this.putS3Object(awsProfile, awsRegion, params);
};
/**

View File

@ -36,7 +36,7 @@ testData.AWS.config.update({
var tests = [
require('./tests/tag'),
require('./tests/deploy_lambda'),
//require('./tests/deploy_api'),
require('./tests/deploy_api'),
//require('./tests/new'), // Must be last
];

View File

@ -2,4 +2,8 @@
* API: Users: Show
*/
exports.handler = function(event, context) {};
exports.handler = function(event, context) {
context.done(null, { message: 'You\'ve made a successful request to your JAWS API!' });
};

View File

@ -33,10 +33,14 @@
"integration.request.querystring.integrationQueryParam": "method.request.querystring.access_token"
},
"responses": {
"2//d{2}": {
"statusCode": "200"
},
"default": {
"statusCode": "200",
"responseParameters" : {},
"responseTemplates" : {
"application/json" : ""
}
},
"400": {
"statusCode": "400"
}
}

View File

@ -1,20 +0,0 @@
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "jaws-new-EJYMNmGh",
"description": "The Swagger template for this JAWS project to use with AWS API Gateway"
},
"host": "",
"schemes": [
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {},
"definitions": {}
}

View File

@ -17,7 +17,7 @@ module.exports.createTestProject = function(projectName, projectRegion, projectS
del.sync([projectPath], { force: true });
}
// Copy test project ot temp directory
// Copy test project to temp directory
fs.mkdirSync(projectPath);
wrench.copyDirSyncRecursive(path.join(__dirname, './test-prj'), projectPath, {
forceDelete: true,
@ -36,5 +36,8 @@ module.exports.createTestProject = function(projectName, projectRegion, projectS
};
fs.writeFileSync(path.join(projectPath, 'jaws.json'), projectJSON);
// Create admin.env file
fs.writeFileSync(path.join(projectPath, 'admin.env'), 'ADMIN_AWS_PROFILE=jawstest');
return projectPath;
};

View File

@ -34,6 +34,7 @@ module.exports = function(testData, cb) {
var JAWS = require('../../lib/index.js'),
JawsError = require('../../lib/jaws-error');
// Test
JAWS.deployApi(testData.stage)
.then(function() {