diff --git a/lib/commands/deploy_api.js b/lib/commands/deploy_api.js index d5ca03777..fdaa058df 100644 --- a/lib/commands/deploy_api.js +++ b/lib/commands/deploy_api.js @@ -35,7 +35,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; - + console.log(JAWS._meta); // Validate Stage if (!JAWS._meta.projectJson.project.regions[state.region].stages[state.stage]) { reject(new JawsError( @@ -54,7 +54,7 @@ module.exports = function(JAWS) { state.spinner = new Spinner('%s Creating your REST API for the state "' + state.stage + '"...'); state.spinner.setSpinnerString('|/-\\'); state.spinner.start(); - + console.log(state) // Check Project's jaws.json for restApiId, otherwise create an api if (state.restApiId) { @@ -270,7 +270,7 @@ module.exports = function(JAWS) { methodBody.requestParameters[requestParam] = true; } } - + console.log(state.restApiId, endpoint.endpoint); // Create Method client.putMethod(state.restApiId, endpoint.endpoint.apig.resource.id, endpoint.endpoint.method, methodBody) .then(function(response) { diff --git a/tests/allSpot.js b/tests/allSpot.js index 6ebd9e7d7..7247aa74a 100644 --- a/tests/allSpot.js +++ b/tests/allSpot.js @@ -5,24 +5,37 @@ * @type {async|exports|module.exports} */ -var async = require('async'); +var async = require('async'), + os = require('os'), + path = require('path'), + AWS = require('aws-sdk'), + shortid = require('shortid'); // Define Test Data var testData = {}; +testData.name = 'test-prj'; +testData.notifyEmail = 'tester@jawsstack.com'; +testData.s3Bucket = process.env.TEST_JAWS_S3_BUCKET || 'jawstest6'; +testData.stage = 'unittest'; +testData.region = 'us-east-1'; +testData.profile = 'default'; + +// Add aws-sdk to Test Data Object (helps clean up test resources, etc.) +testData.AWS = require('aws-sdk'); +testData.AWS.config.credentials = new testData.AWS.SharedIniFileCredentials({ + profile: testData.profile, +}); +testData.AWS.config.update({ + region: testData.region, +}); // Require Tests var tests = [ + require('./new'), require('./deploy/api'), ]; // Run Tests async.eachSeries(tests, function(test, cb) { - - test(testData, function(testData) { - return cb(); - }); - -}, function(error) { - console.log('Tests completed'); -}); - + test(testData, function(testData) { return cb(); }); +}, function(error) { console.log('Tests completed'); }); \ No newline at end of file diff --git a/tests/deploy/api.js b/tests/deploy/api.js index 4a2223be2..bc7f4eba0 100644 --- a/tests/deploy/api.js +++ b/tests/deploy/api.js @@ -1,20 +1,26 @@ 'use strict'; -// Dependencies +/** + * JAWS Test: Deploy API Command + * - Copies the test-prj template to your system's temp directory + * - Deploys an API based on the endpoints in the project + */ var testUtils = require('../test_utils'); module.exports = function(testData, cb) { - before(function() { - testData.projectPath = testUtils.createTestProject(); - }); - - after(function() { - testUtils.deleteTestProject(testData.projectPath); - return cb(testData); - }); - describe('Test deploy api command', function() { + + before(function() { + testData.projectPath = testUtils.createTestProject(testData.name); + process.chdir(testData.projectPath); + }); + + after(function(done) { + cb(testData); + done(); + }); + it('Doesn\'t error', function(done) { this.timeout(0); diff --git a/tests/new/index.js b/tests/new/index.js index 8181a0d13..9809b236c 100644 --- a/tests/new/index.js +++ b/tests/new/index.js @@ -1,33 +1,66 @@ 'use strict'; -var JAWS = require('../../lib/index.js'), - JawsError = require('../../lib/jaws-error'), - path = require('path'), - assert = require('chai').assert; +/** + * JAWS Test: New Command + * - Creates a new project in your system's temp directory + * - Deletes the CF stack created by the project + */ +var path = require('path'), + os = require('os'), + assert = require('chai').assert, + testUtils = require('../test_utils'), + AWS = require('aws-sdk'); -var projName = process.env.TEST_PROJECT_NAME, - stage = 'unittest', - lambdaRegion = 'us-east-1', - notificationEmail = 'tester@jawsstack.com', - awsProfile = 'default'; +module.exports = function(testData, cb) { -// Tests -describe('Test new command', function() { + describe('Test new command', function() { - it('Existing aws creds', function(done) { - this.timeout(0); + before(function() { + process.chdir(os.tmpdir()); + }); - JAWS.new(projName, stage, process.env.TEST_JAWS_S3_BUCKET, lambdaRegion, notificationEmail, awsProfile) - .then(function() { - var jawsJson = require(process.env.TEST_PROJECT_DIR + '/' + process.env.TEST_PROJECT_NAME + '/jaws.json'); - assert.isTrue(!!jawsJson.project.regions['us-east-1'].stages[stage].iamRoleArn); - done(); - }) - .catch(JawsError, function(e) { - done(e); - }) - .error(function(e) { - done(e); - }); + after(function(done) { + cb(testData); + done(); + }); + + it('Create new project without errors', function(done) { + + this.timeout(0); + + // Require + var JAWS = require('../../lib/index.js'), + JawsError = require('../../lib/jaws-error'); + + // Test + JAWS.new( + testData.name, + testData.stage, + testData.s3Bucket, + testData.region, + testData.notifyEmail, + testData.profile + ) + .then(function() { + var jawsJson = require(path.join(os.tmpdir(), testData.name, 'jaws.json')); + assert.isTrue(!!jawsJson.project.regions['us-east-1'].stages[testData.stage].iamRoleArn); + done(); + }) + .catch(JawsError, function(e) { + done(e); + }) + .error(function(e) { + done(e); + }); + }); + + it('Delete Cloudformation stack from new project', function(done) { + this.timeout(0); + var CF = new testData.AWS.CloudFormation(); + CF.deleteStack({ StackName: testData.stage + '-' + testData.name }, function(err, data) { + if (err) console.log(err, err.stack); + done(); + }); + }); }); -}); +}; \ No newline at end of file diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/.gitignore b/tests/test-prj/back/users/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/.gitignore rename to tests/test-prj/back/users/.gitignore diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/README.md b/tests/test-prj/back/users/README.md old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/README.md rename to tests/test-prj/back/users/README.md diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/jaws.json b/tests/test-prj/back/users/jaws.json old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/jaws.json rename to tests/test-prj/back/users/jaws.json diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/show/event.json b/tests/test-prj/back/users/lambdas/show/event.json old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/show/event.json rename to tests/test-prj/back/users/lambdas/show/event.json diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/show/index.js b/tests/test-prj/back/users/lambdas/show/index.js old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/show/index.js rename to tests/test-prj/back/users/lambdas/show/index.js diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/show/jaws.json b/tests/test-prj/back/users/lambdas/show/jaws.json old mode 100755 new mode 100644 similarity index 75% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/show/jaws.json rename to tests/test-prj/back/users/lambdas/show/jaws.json index 573814d79..4beee1dd6 --- a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/show/jaws.json +++ b/tests/test-prj/back/users/lambdas/show/jaws.json @@ -4,12 +4,22 @@ "location": "https://github.com/jaws-stack/jaws-users-crud-ddb-jwt-js", "author": "JAWS", "description": "A lambda function to fetch a user from the database and show them", + "envVars": [ + "MYAPP_SERVICE_KEY", + "MYAPP_SERVICE2_KEY" + ], "lambda": { - "functionName": "users-show", - "handler": "index.handler", + "functionName": "usersShow", "runtime": "nodejs", - "memorySize": 513, - "timeout": 5 + "runtimeVer": "0.10.33", + "handler": "index.handler", + "memorySize": 1024, + "timeout": 6, + "deploy": false, + "optimize": true, + "includePaths": [], + "ignoreFiles": [], + "excludeFiles": [] }, "endpoint": { "path": "sessions/{sessionId}", @@ -31,4 +41,4 @@ } } } -} +} \ No newline at end of file diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/signin/event.json b/tests/test-prj/back/users/lambdas/signin/event.json old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/signin/event.json rename to tests/test-prj/back/users/lambdas/signin/event.json diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/signin/index.js b/tests/test-prj/back/users/lambdas/signin/index.js old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/signin/index.js rename to tests/test-prj/back/users/lambdas/signin/index.js diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/signin/jaws.json b/tests/test-prj/back/users/lambdas/signin/jaws.json old mode 100755 new mode 100644 similarity index 75% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/signin/jaws.json rename to tests/test-prj/back/users/lambdas/signin/jaws.json index 7ef9758f8..8d195108b --- a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/signin/jaws.json +++ b/tests/test-prj/back/users/lambdas/signin/jaws.json @@ -4,12 +4,22 @@ "location": "https://github.com/jaws-stack/jaws-users-crud-ddb-jwt-js", "author": "JAWS", "description": "A group of lambda functions for user crud operations using dynamodb, JSON web tokens and javascript", + "envVars": [ + "MYAPP_SERVICE_KEY", + "MYAPP_SERVICE2_KEY" + ], "lambda": { - "functionName": "users-signin", - "handler": "index.handler", + "functionName": "usersSignIn", "runtime": "nodejs", - "memorySize": 513, - "timeout": 5 + "runtimeVer": "0.10.33", + "handler": "index.handler", + "memorySize": 1024, + "timeout": 6, + "deploy": false, + "optimize": true, + "includePaths": [], + "ignoreFiles": [], + "excludeFiles": [] }, "endpoint": { "path": "sessions/{sessionId}", diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/signup/event.json b/tests/test-prj/back/users/lambdas/signup/event.json old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/signup/event.json rename to tests/test-prj/back/users/lambdas/signup/event.json diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/signup/index.js b/tests/test-prj/back/users/lambdas/signup/index.js old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/signup/index.js rename to tests/test-prj/back/users/lambdas/signup/index.js diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/signup/jaws.json b/tests/test-prj/back/users/lambdas/signup/jaws.json old mode 100755 new mode 100644 similarity index 75% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/signup/jaws.json rename to tests/test-prj/back/users/lambdas/signup/jaws.json index 0fd1d5e9a..94fbda31e --- a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lambdas/signup/jaws.json +++ b/tests/test-prj/back/users/lambdas/signup/jaws.json @@ -4,12 +4,22 @@ "location": "https://github.com/jaws-stack/jaws-users-crud-ddb-jwt-js", "author": "JAWS", "description": "A group of lambda functions for user crud operations using dynamodb, JSON web tokens and javascript", + "envVars": [ + "MYAPP_SERVICE_KEY", + "MYAPP_SERVICE2_KEY" + ], "lambda": { - "functionName": "users-signup", - "handler": "index.handler", + "functionName": "usersSignUp", "runtime": "nodejs", - "memorySize": 513, - "timeout": 5 + "runtimeVer": "0.10.33", + "handler": "index.handler", + "memorySize": 1024, + "timeout": 6, + "deploy": false, + "optimize": true, + "includePaths": [], + "ignoreFiles": [], + "excludeFiles": [] }, "endpoint": { "path": "users", diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lib/config/config.js b/tests/test-prj/back/users/lib/config/config.js old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lib/config/config.js rename to tests/test-prj/back/users/lib/config/config.js diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lib/index.js b/tests/test-prj/back/users/lib/index.js old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lib/index.js rename to tests/test-prj/back/users/lib/index.js diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lib/middleware/middleware_incoming.js b/tests/test-prj/back/users/lib/middleware/middleware_incoming.js old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lib/middleware/middleware_incoming.js rename to tests/test-prj/back/users/lib/middleware/middleware_incoming.js diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lib/models/model_aws.js b/tests/test-prj/back/users/lib/models/model_aws.js old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lib/models/model_aws.js rename to tests/test-prj/back/users/lib/models/model_aws.js diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lib/models/model_user.js b/tests/test-prj/back/users/lib/models/model_user.js old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lib/models/model_user.js rename to tests/test-prj/back/users/lib/models/model_user.js diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lib/package.json b/tests/test-prj/back/users/lib/package.json old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lib/package.json rename to tests/test-prj/back/users/lib/package.json diff --git a/tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lib/utilities/utilities.js b/tests/test-prj/back/users/lib/utilities/utilities.js old mode 100755 new mode 100644 similarity index 100% rename from tests/jaws-test-project/back/jaws-users-crud-ddb-jwt-js/lib/utilities/utilities.js rename to tests/test-prj/back/users/lib/utilities/utilities.js diff --git a/tests/jaws-test-project/jaws-cf.json b/tests/test-prj/jaws-cf.json similarity index 100% rename from tests/jaws-test-project/jaws-cf.json rename to tests/test-prj/jaws-cf.json diff --git a/tests/jaws-test-project/jaws-swagger.json b/tests/test-prj/jaws-swagger.json similarity index 100% rename from tests/jaws-test-project/jaws-swagger.json rename to tests/test-prj/jaws-swagger.json diff --git a/tests/jaws-test-project/jaws.json b/tests/test-prj/jaws.json similarity index 83% rename from tests/jaws-test-project/jaws.json rename to tests/test-prj/jaws.json index c5e46f56d..9e46daf9b 100644 --- a/tests/jaws-test-project/jaws.json +++ b/tests/test-prj/jaws.json @@ -1,5 +1,5 @@ { - "name": "jaws-new-EJYMNmGh", + "name": "jaws-test-project", "version": "0.0.1", "profile": "project", "author": "Vera D. Servers http://vera.io", @@ -11,8 +11,7 @@ "dev": { "iamRoleArn": "arn:aws:iam::8902348097:role/dev_-_jaws-test_-_jaws" } - }, - "restApiId": "gnwo1d58q0" + } } }, "cfTemplate": {} diff --git a/tests/test_utils.js b/tests/test_utils.js index 1cda302ae..ad5bd906c 100644 --- a/tests/test_utils.js +++ b/tests/test_utils.js @@ -9,21 +9,18 @@ var fs = require('fs'), /** * Create Test Project */ -module.exports.createTestProject = function() { - +module.exports.createTestProject = function(projectName) { // Create Test Project - var projectPath = path.join(os.tmpdir(), 'jaws-test-project'); + var projectPath = path.join(os.tmpdir(), './', projectName); if (fs.existsSync(projectPath)) { del.sync([projectPath], { force: true }); } fs.mkdirSync(projectPath); - wrench.copyDirSyncRecursive('./jaws-test-project', projectPath, { + wrench.copyDirSyncRecursive(path.join(__dirname, './test-prj'), projectPath, { forceDelete: true, }); - - // Reset CWD to test project - Must be done before requiring in tests - process.chdir(projectPath); + console.log(projectPath); return projectPath; };