From 388082ea5fbf5f6a96e307a8d205fbcfb7e4e79c Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Mon, 31 Aug 2015 19:55:26 -0700 Subject: [PATCH] tests and deploy api: refactor more tests, fix deploy api --- lib/commands/deploy_api.js | 16 ++++++++++++--- lib/utils/aws.js | 4 ++-- tests/allSpot.js | 2 +- .../test-prj/back/users/lambdas/show/index.js | 6 +++++- .../back/users/lambdas/show/jaws.json | 10 +++++++--- tests/test-prj/jaws-swagger.json | 20 ------------------- tests/test_utils.js | 5 ++++- tests/tests/deploy_api.js | 1 + 8 files changed, 33 insertions(+), 31 deletions(-) delete mode 100644 tests/test-prj/jaws-swagger.json diff --git a/lib/commands/deploy_api.js b/lib/commands/deploy_api.js index 10201c45b..fe3fc4f06 100644 --- a/lib/commands/deploy_api.js +++ b/lib/commands/deploy_api.js @@ -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, diff --git a/lib/utils/aws.js b/lib/utils/aws.js index d19a05855..15d7297a1 100644 --- a/lib/utils/aws.js +++ b/lib/utils/aws.js @@ -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); }; /** diff --git a/tests/allSpot.js b/tests/allSpot.js index 81a82f20a..335dbebf7 100644 --- a/tests/allSpot.js +++ b/tests/allSpot.js @@ -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 ]; diff --git a/tests/test-prj/back/users/lambdas/show/index.js b/tests/test-prj/back/users/lambdas/show/index.js index 13f7885c3..7b0fbaa0a 100644 --- a/tests/test-prj/back/users/lambdas/show/index.js +++ b/tests/test-prj/back/users/lambdas/show/index.js @@ -2,4 +2,8 @@ * API: Users: Show */ -exports.handler = function(event, context) {}; \ No newline at end of file +exports.handler = function(event, context) { + + context.done(null, { message: 'You\'ve made a successful request to your JAWS API!' }); + +}; \ No newline at end of file diff --git a/tests/test-prj/back/users/lambdas/show/jaws.json b/tests/test-prj/back/users/lambdas/show/jaws.json index 1b4d5980e..78738c81b 100644 --- a/tests/test-prj/back/users/lambdas/show/jaws.json +++ b/tests/test-prj/back/users/lambdas/show/jaws.json @@ -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" } } diff --git a/tests/test-prj/jaws-swagger.json b/tests/test-prj/jaws-swagger.json deleted file mode 100644 index 7c02491c2..000000000 --- a/tests/test-prj/jaws-swagger.json +++ /dev/null @@ -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": {} -} \ No newline at end of file diff --git a/tests/test_utils.js b/tests/test_utils.js index a23348aa3..dc3256287 100644 --- a/tests/test_utils.js +++ b/tests/test_utils.js @@ -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; }; \ No newline at end of file diff --git a/tests/tests/deploy_api.js b/tests/tests/deploy_api.js index 689fad8d0..c85e773e2 100644 --- a/tests/tests/deploy_api.js +++ b/tests/tests/deploy_api.js @@ -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() {