Skip to content

Commit

Permalink
Moved test to test folder...
Browse files Browse the repository at this point in the history
  • Loading branch information
philliphenslee committed Oct 23, 2015
1 parent af5377b commit 0c7af42
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 126 deletions.
2 changes: 1 addition & 1 deletion lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var errors = require('./errors');

var Cache = function Cache() {

if (Cache.caller != Cache.getInstance) {
if (Cache.caller !== Cache.getInstance) {
throw new Error("This object cannot be instanciated");
}

Expand Down
66 changes: 0 additions & 66 deletions lib/cache.spec.js

This file was deleted.

30 changes: 16 additions & 14 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,19 @@ function SmartSlack(options) {
var accessToken = options.token;

// Need a valid Slack token to authenticate
if (!accessToken || typeof accessToken !== 'string' ||
!accessToken.match(/^([a-z]{4})-([0-9]{11})-([0-9a-zA-Z]{24})$/)) {
if (!accessToken || typeof accessToken !== 'string' || !accessToken.match(/^([a-z]{4})-([0-9]{11})-([0-9a-zA-Z]{24})$/)) {
throw new Error(errors.invalid_token);
}

// Save the cache data
this.cache = Cache;
this.cache.defaults(options);
this.cache.add({ hostname: 'slack.com' });
this.cache.add({hostname: 'slack.com'});

// API references
this.channels = slack.channels;
this.chat = slack.chat;
this.emoji = slack.emoji
this.emoji = slack.emoji;
this.groups = slack.groups;
this.im = slack.im;
this.reactions = slack.reactions;
Expand Down Expand Up @@ -124,7 +123,6 @@ SmartSlack.prototype.postDirectMessage = function (user, text, args, callback) {
};



/**
* Post a message via the API
* @description Convenience function so you can call
Expand Down Expand Up @@ -184,7 +182,8 @@ SmartSlack.prototype.sendToGroup = function (group, text, callback) {
* @param {function} callback(err,result)
*/
SmartSlack.prototype.sendToUser = function (username, text, callback) {
callback = (_.isFunction(callback)) ? callback : function () { };
callback = (_.isFunction(callback)) ? callback : function () {
};

if (!_.isString(username) && !_.isString(text)) {
return callback(new Error(errors.missing_required_arg));
Expand Down Expand Up @@ -312,18 +311,18 @@ SmartSlack.prototype._onRtmEvent = function (message) {
this._lastPong = _.now();

// Start pings every five seconds
this._pingInterval = setInterval(function () { _this._ping(); }, 5000);
this._pingInterval = setInterval(function () {
_this._ping();
}, 5000);
break;

case 'message':
this.emit('message', message);

uptime = this.getUptime();
if (message.text === 'naomi uptime') {
this._send(message.channel,uptime);
this._send(message.channel, uptime);
}


break;

case 'pong':
Expand All @@ -333,7 +332,7 @@ SmartSlack.prototype._onRtmEvent = function (message) {
break;

case 'presence_change':
_.find(this.cache.data.users, { id: message.user }).presence = message.presence;
_.find(this.cache.data.users, {id: message.user}).presence = message.presence;
this.log.info('User presence changed, updating user presence...');
break;

Expand Down Expand Up @@ -368,7 +367,7 @@ SmartSlack.prototype._onRtmEvent = function (message) {
SmartSlack.prototype._ping = function () {
var _this = this;
var result;
var ping = { type: "ping" };
var ping = {type: "ping"};
ping.id = _this._messageId;
ping.time = _.now();
result = JSON.stringify(ping);
Expand All @@ -391,7 +390,9 @@ SmartSlack.prototype._reconnect = function () {
_this._startTime = null;

// Attempt to resolve slack.com and call login when available
_this._reconnecting = setInterval(function () { _this._canResolve(); }, 5000);
_this._reconnecting = setInterval(function () {
_this._canResolve();
}, 5000);
_this.log.info('Connection lost, waiting to reconnect...');
};

Expand Down Expand Up @@ -437,7 +438,8 @@ SmartSlack.prototype._sendToType = function (slackType, typeName, text, callback

var entityId;

callback = (_.isFunction(callback)) ? callback : function () { };
callback = (_.isFunction(callback)) ? callback : function () {
};

switch (slackType) {
case slack.types.CHANNEL:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
},
"scripts": {
"test": "npm run test-unit",
"test-unit": "mocha -R spec $(find ./lib -name \"*.spec.js\" -not -path \"./node_modules/*\")",
"test-travis": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec $(find ./lib -name \"*.spec.js\" -not -path \"./node_modules/*\")",
"test-unit": "mocha -R spec $(find ./test -name \"*.spec.js\" -not -path \"./node_modules/*\")",
"test-travis": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec $(find ./test -name \"*.spec.js\" -not -path \"./node_modules/*\")",
"travis": "npm test"
}
}
8 changes: 4 additions & 4 deletions lib/slack/api.spec.js → test/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ var should = chai.should();
var expect = chai.expect;
var nock = require('nock');

var api = require('./api');
var errors = require('../errors');
var Cache = require('../cache');
var slackTypes = require('./types');
var api = require('./../lib/slack/api');
var errors = require('../lib/errors');
var Cache = require('../lib/cache');
var slackTypes = require('./../lib/slack/types');

describe('api', function () {

Expand Down
76 changes: 76 additions & 0 deletions test/cache.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
var chai = require('chai');
var should = chai.should();
var expect = chai.expect;
var nock = require('nock');

var cache = require('../lib/cache');
var slackType = require('../lib/slack/types');


describe('cache', function () {

it('should be a singleton', function (done) {
var cache1 = require('./../lib/cache');
var cache2 = require('./../lib/cache');
expect(cache1).to.equal(cache2);
done();
});

// function get(name, callback)
describe('#search', function () {

before(function () {

cache.data.users = [
{
"id": "U0BC6D9V1",
"name": "john",
"real_name": "John Doe",
"profile": {
"first_name": "John",
"last_name": "Doe",
"title": "Just a slack user",
"real_name": "John Doe",
"real_name_normalized": "John Doe",
"email": "john@somedomain.com"
}
}];
});

it('it should return a user by e-mail address', function (done) {
cache.data.users = [
{
"id": "U0BC6D9V1",
"name": "john",
"real_name": "John Doe",
"profile": {
"first_name": "John",
"last_name": "Doe",
"title": "Just a slack user",
"real_name": "John Doe",
"real_name_normalized": "John Doe",
"email": "john@somedomain.com"
}
}];
cache.search(slackType.USER, 'john@somedomain.com', function name(err, result) {
expect(result.name).to.equal('john');
done();
});

});

it('it should return a user by name', function (done) {
cache.search(slackType.USER, 'john', function name(err, result) {
expect(result.profile.email).to.equal('john@somedomain.com');
});
done();
});

it('it should return a user by user id', function (done) {
cache.search(slackType.USER, 'U0BC6D9V1', function name(err, result) {
expect(result.profile.real_name).to.equal('John Doe');
});
done();
});
});
});
8 changes: 4 additions & 4 deletions lib/slack/channels.spec.js → test/channels.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ var should = chai.should();
var expect = chai.expect;
var nock = require('nock');

var channels = require('./channels');
var errors = require('../errors');
var Cache = require('../cache');
var slackTypes = require('./types');
var channels = require('./../lib/slack/channels');
var errors = require('../lib/errors');
var Cache = require('../lib/cache');
var slackTypes = require('./../lib/slack/types');


describe('channels', function () {
Expand Down
8 changes: 4 additions & 4 deletions lib/slack/chat.spec.js → test/chat.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ var should = chai.should();
var expect = chai.expect;
var nock = require('nock');

var chat = require('./chat');
var errors = require('../errors');
var Cache = require('../cache');
var slackTypes = require('./types');
var chat = require('./../lib/slack/chat');
var errors = require('../lib/errors');
var Cache = require('../lib/cache');
var slackTypes = require('./../lib/slack/types');

describe('chat', function () {

Expand Down
8 changes: 4 additions & 4 deletions lib/slack/emoji.spec.js → test/emoji.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ var should = chai.should();
var expect = chai.expect;
var nock = require('nock');

var emoji = require('./emoji');
var errors = require('../errors');
var Cache = require('../cache');
var slackTypes = require('./types');
var emoji = require('./../lib/slack/emoji');
var errors = require('../lib/errors');
var Cache = require('../lib/cache');
var slackTypes = require('./../lib/slack/types');


describe('emoji', function () {
Expand Down
8 changes: 4 additions & 4 deletions lib/slack/groups.spec.js → test/groups.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ var should = chai.should();
var expect = chai.expect;
var nock = require('nock');

var groups = require('./groups');
var errors = require('../errors');
var Cache = require('../cache');
var slackTypes = require('./types');
var groups = require('./../lib/slack/groups');
var errors = require('../lib/errors');
var Cache = require('../lib/cache');
var slackTypes = require('./../lib/slack/types');


describe('groups', function () {
Expand Down
8 changes: 4 additions & 4 deletions lib/slack/im.spec.js → test/im.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ var should = chai.should();
var expect = chai.expect;
var nock = require('nock');

var im = require('./im');
var errors = require('../errors');
var Cache = require('../cache');
var slackTypes = require('./types');
var im = require('./../lib/slack/im');
var errors = require('../lib/errors');
var Cache = require('../lib/cache');
var slackTypes = require('./../lib/slack/types');


describe('im', function () {
Expand Down
2 changes: 1 addition & 1 deletion lib/index.spec.js → test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var should = chai.should();
var expect = chai.expect;
var nock = require('nock');

var Cache = require('./cache');
var Cache = require('./../lib/cache');
var SmartSlack = require('../lib/index.js');

describe('SmartSlack', function () {
Expand Down
8 changes: 4 additions & 4 deletions lib/slack/reactions.spec.js → test/reactions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ var should = chai.should();
var expect = chai.expect;
var nock = require('nock');

var reactions = require('./reactions');
var errors = require('../errors');
var Cache = require('../cache');
var slackTypes = require('./types');
var reactions = require('./../lib/slack/reactions');
var errors = require('../lib/errors');
var Cache = require('../lib/cache');
var slackTypes = require('./../lib/slack/types');


describe('reactions', function () {
Expand Down
4 changes: 2 additions & 2 deletions lib/slack/rtm.spec.js → test/rtm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ var should = chai.should();
var expect = chai.expect;
var nock = require('nock');

var rtm = require('./rtm');
var Cache = require('../cache');
var rtm = require('./../lib/slack/rtm');
var Cache = require('../lib/cache');


describe('rtm', function () {
Expand Down

0 comments on commit 0c7af42

Please sign in to comment.