hall-integrations
Version:
Node.js wrapper for Hall Custom Integration API. Send custom messages to your rooms on Hall.
99 lines (78 loc) • 2.88 kB
JavaScript
var expect = require('expect.js'),
horaa = require('horaa'),
Hall = require('../index'),
events = require('events');
describe('Hall Integrations API Client', function () {
describe('Instantiate the Hall Integrations Client', function () {
it('should create a new instance', function () {
var instance = new Hall('satoheuaoeu9080');
});
it('should throw an exception if a number is passed', function () {
expect(function () {
var instance = new Hall(3234);
}).to.throwError();
});
it('should throw an exception if a boolean is passed', function () {
expect(function () {
var instance = new Hall();
}).to.throwError();
});
it('should throw an exception if a function is passed', function () {
expect(function () {
var instance = new Hall();
}).to.throwError();
});
it('should throw an exception if an abject is passed', function () {
expect(function () {
var instance = new Hall();
}).to.throwError();
});
it('should throw an exception if no value is passed', function () {
expect(function () {
var instance = new Hall();
}).to.throwError();
});
});
describe('Send integration messages', function () {
var hall, roomApiToken, httpsHoraa, requests;
before(function () {
roomApiToken = 'notheu90890809';
hall = new Hall(roomApiToken);
requests = [];
// Mock https module
httpsHoraa = horaa('https');
httpsHoraa.hijack('request', function (options, callback) {
var request, response;
request = new events.EventEmitter();
response = new events.EventEmitter();
response.statusCode = 201;
requests.push('https://' + options.hostname + options.path);
callback(response);
request.write = function () {};
request.end = function () {};
return request;
});
});
beforeEach(function () {
});
it('should send request to correct url', function () {
var expectedUrl = 'https://hall.com/api/1/services/generic/' + roomApiToken;
hall.send('Plant Time', 'Time to <b>Water</b> the plants!', 'http://cool.com/smile.png');
expect(requests[0]).to.be(expectedUrl);
});
it('should trigger callback', function (done) {
var callback = function (error, result) {
expect(result.statusCode).to.be(201);
done();
};
hall.send('Plant Time', 'Time to <b>Water</b> the plants!', 'http://cool.com/smile.png', callback);
});
it('should resolve promise', function (done) {
hall.send('Plant Time', 'Time to <b>Water</b> the plants!', 'http://cool.com/smile.png')
.then(function (result) {
expect(result.statusCode).to.be(201);
done();
});
});
});
});