serverless/tests/cli/generate.js
2015-09-08 22:44:42 -05:00

87 lines
2.7 KiB
JavaScript

'use strict';
/**
* 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 Jaws = require('../../lib/index.js'),
theCmd = require('../../lib/commands/generate'),
testUtils = require('../test_utils'),
path = require('path'),
fs = require('fs'),
assert = require('chai').assert;
var config = require('../config');
var resourceDir,
projPath,
JAWS;
describe('Test generate command', function() {
before(function(done) {
projPath = testUtils.createTestProject(
config.name,
config.region,
config.stage,
config.iamRoleArnLambda,
config.iamRoleArnApiGateway,
config.envBucket);
process.chdir(projPath);
JAWS = new Jaws();
resourceDir = path.join(projPath, 'back', 'lambdas', 'unittests');
done();
});
after(function(done) {
done();
});
describe('Positive tests', function() {
it('Just lambda', function() {
this.timeout(0);
var testAction = 'lambdaOnly';
return theCmd.run(JAWS, true, false, testAction, 'unittests')
.then(function() {
var jawsJson = require(resourceDir + '/' + testAction + '/jaws.json');
assert.equal(true, !!jawsJson);
assert.equal(true, !!jawsJson.lambda);
assert.equal(true, !jawsJson.endpoint);
assert.equal(true, fs.existsSync(path.join(resourceDir, testAction, 'index.js')));
assert.equal(true, fs.existsSync(path.join(resourceDir, testAction, 'event.json')));
testAction = 'apiOnly';
return theCmd.run(JAWS, false, true, testAction, 'unittests');
})
.then(function() {
var jawsJson = require(resourceDir + '/' + testAction + '/jaws.json');
assert.equal(true, !!jawsJson);
assert.equal(true, !jawsJson.lambda);
assert.equal(true, !!jawsJson.endpoint);
assert.equal(true, !fs.existsSync(path.join(resourceDir, testAction, 'index.js')));
assert.equal(true, !fs.existsSync(path.join(resourceDir, testAction, 'event.json')));
testAction = 'both';
return theCmd.run(JAWS, true, true, testAction, 'unittests')
})
.then(function() {
var jawsJson = require(resourceDir + '/' + testAction + '/jaws.json');
assert.equal(true, !!jawsJson);
assert.equal(true, !!jawsJson.lambda);
assert.equal(true, !!jawsJson.endpoint);
assert.equal(true, fs.existsSync(path.join(resourceDir, testAction, 'index.js')));
assert.equal(true, fs.existsSync(path.join(resourceDir, testAction, 'event.json')));
});
});
});
});