Skip to content

Commit

Permalink
Added tests for index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
achambers committed Jun 22, 2015
1 parent 8e1003d commit 7ebbc4f
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 25 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ module.exports = {

_resolvePipelineData: function(config, context) {
config.revisionKey = config.revisionKey || function(context) {
return context.deployment.commandLineArgs.revisionKey || context.deployment.revisionKey;
return context.deployment.commandLineArgs.revisionKey || context.revisionKey;
};

return Promise.resolve();
Expand Down
142 changes: 118 additions & 24 deletions tests/unit/index-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ var Promise = require('ember-cli/lib/ext/promise');

var assert = require('ember-cli/tests/helpers/assert');

function hooks(plugin) {
return Object.keys(plugin).filter(function(key) {
return (key !== 'name') && (key.charAt(0) !== '_') && (typeof plugin[key] === 'function');
});
}

var stubUi = { write: function() {}, writeLine: function() {} };
var stubProject = {
name: function(){
return 'my-project';
}
};

describe('redis plugin', function() {
var subject;

Expand All @@ -20,28 +33,24 @@ describe('redis plugin', function() {
});

it('implements the correct hooks', function() {
var result = subject.createDeployPlugin({
var plugin = subject.createDeployPlugin({
name: 'test-plugin'
});

assert.equal(typeof result.configure, 'function');
assert.equal(typeof result.upload, 'function');
assert.equal(hooks(plugin).length, 3);
assert.sameMembers(hooks(plugin), ['configure', 'upload', 'activate']);
});

describe('willDeploy hook', function() {
describe('configure hook', function() {
it('resolves if config is ok', function() {
var plugin = subject.createDeployPlugin({
name: 'redis'
});

var context = {
deployment: {
ui: { write: function() {}, writeLine: function() {} },
project: {
name: function(){
return 'my-project';
}
},
ui: stubUi,
project: stubProject,
config: {
redis: {
host: 'somehost',
Expand All @@ -53,6 +62,96 @@ describe('redis plugin', function() {

return assert.isFulfilled(plugin.configure.call(plugin, context))
});

describe('resolving data from the pipeline', function() {
it('uses the config data if it already exists', function() {
var plugin = subject.createDeployPlugin({
name: 'redis'
});

var config = {
host: 'somehost',
port: 1234,
revisionKey: '12345'
};
var context = {
deployment: {
ui: stubUi,
project: stubProject,
config: {
redis: config
}
},

revisionKey: 'something-else'
};

return assert.isFulfilled(plugin.configure.call(plugin, context))
.then(function() {
assert.equal(config.revisionKey, '12345');
});
});

it('uses the commandLineArgs value if it exists', function() {
var plugin = subject.createDeployPlugin({
name: 'redis'
});

var config = {
host: 'somehost',
port: 1234
};
var context = {
deployment: {
ui: stubUi,
project: stubProject,
config: {
redis: config
},
commandLineArgs: {
revisionKey: 'abcd'
}
},

revisionKey: 'something-else'
};

return assert.isFulfilled(plugin.configure.call(plugin, context))
.then(function() {
assert.typeOf(config.revisionKey, 'function');
assert.equal(config.revisionKey(context), 'abcd');
});
})

it('uses the context value if it exists and commandLineArgs don\'t', function() {
var plugin = subject.createDeployPlugin({
name: 'redis'
});

var config = {
host: 'somehost',
port: 1234
};
var context = {
deployment: {
ui: stubUi,
project: stubProject,
config: {
redis: config
},
commandLineArgs: { }
},

revisionKey: 'something-else'
};

return assert.isFulfilled(plugin.configure.call(plugin, context))
.then(function() {
assert.typeOf(config.revisionKey, 'function');
assert.equal(config.revisionKey(context), 'something-else');
});
})
});
});

describe('upload hook', function() {
Expand All @@ -66,34 +165,29 @@ describe('redis plugin', function() {

context = {
redisClient: {
upload: function() {
return Promise.resolve('redis-key');
upload: function(keyPrefix, revisionKey) {
return Promise.resolve(keyPrefix + ':' + revisionKey);
}
},
tag: 'some-tag',
deployment: {
ui: { write: function() {} },
project: { name: function() { return 'test-project'; } },
ui: stubUi,
project: stubProject,
config: {
redis: {
keyPrefix: 'test-prefix',
filePattern: 'tests/index.html',
revisionKey: '123abc'
}
}
}
},
};
});

it('uploads the index to redis', function() {
return assert.isFulfilled(plugin.upload.call(plugin, context))
.then(function(result) {
assert.deepEqual(result, { redisKey: 'redis-key' });
});
});

it('returns the uploaded key', function() {
it('uploads the index', function() {
return assert.isFulfilled(plugin.upload.call(plugin, context))
.then(function(result) {
assert.deepEqual(result.redisKey, 'redis-key');
assert.deepEqual(result, { redisKey: 'test-prefix:123abc' });
});
});
});
Expand Down

0 comments on commit 7ebbc4f

Please sign in to comment.