tests: rewrite, still needs fixing

This commit is contained in:
Austen Collins 2015-08-28 21:32:49 -07:00
parent 9ea7bddc82
commit 1a2b447333
27 changed files with 150 additions and 72 deletions

View File

@ -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) {

View File

@ -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'); });

View File

@ -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);

View File

@ -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();
});
});
});
});
};

View File

@ -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 @@
}
}
}
}
}

View File

@ -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}",

View File

@ -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",

View File

@ -1,5 +1,5 @@
{
"name": "jaws-new-EJYMNmGh",
"name": "jaws-test-project",
"version": "0.0.1",
"profile": "project",
"author": "Vera D. Servers <vera@gmail.com> http://vera.io",
@ -11,8 +11,7 @@
"dev": {
"iamRoleArn": "arn:aws:iam::8902348097:role/dev_-_jaws-test_-_jaws"
}
},
"restApiId": "gnwo1d58q0"
}
}
},
"cfTemplate": {}

View File

@ -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;
};