node-ciscospark
Version:
Super-Simple Lightweight Javascript wrapper for Cisco Spark API
94 lines (82 loc) • 3.04 kB
JavaScript
;
/* eslint-env mocha */
/* eslint-disable no-unused-expressions */
var Spark = require('../src');
var expect = require('chai').expect;
var TEST_ACCESSTOKEN = '**TestAccessToken**';
var TEST_USERAGENT = '**TestUsergent**';
var TEST_WEBHOOK_ID = '**TestWebhookId**';
/** @test {Webhooks} */
describe('CiscoSpark.webhooks', function () {
before(function () {
this.spark = new Spark(TEST_ACCESSTOKEN, TEST_USERAGENT);
this.spark.requestCallback = function (options, callback) {
return callback(null, {
options: options,
timestamp: Date.now()
});
};
this.instance = this.spark.webhooks;
});
/** @test {Webhooks#list} */
it('should list Webhooks', function (done) {
var _this = this;
var max = 99;
this.instance.list({ max: max }, function (err, response) {
expect(err).to.be.not.ok;
expect(response.options.headers.Authorization).to.be.equal('Bearer ' + TEST_ACCESSTOKEN);
expect(response.options.headers['User-Agent']).to.be.equal(TEST_USERAGENT);
expect(response.options.url).to.be.equal(_this.instance.apiUrl);
expect(response.options.method).to.be.equal('GET');
expect(response.options.qs.max).to.be.equal(max);
done();
});
});
/** @test {Webhooks#create} */
it('should create a Webhook', function (done) {
var name = 'Test Webhook';
this.instance.create({
name: name,
targetUrl: 'http://example.com/api',
resource: 'unittest',
event: 'tested'
}, function (err, response) {
expect(err).to.be.not.ok;
expect(response.options.method).to.be.equal('POST');
expect(response.options.form.name).to.be.equal(name);
expect(response.options.form.resource).to.be.ok;
done();
});
});
/** @test {Webhooks#get} */
it('should get Team Details', function (done) {
var _this2 = this;
this.instance.get(TEST_WEBHOOK_ID, function (err, response) {
expect(err).to.be.not.ok;
expect(response.options.url).to.be.equal(_this2.instance.apiUrl + '/' + TEST_WEBHOOK_ID);
expect(response.options.method).to.be.equal('GET');
done();
});
});
/** @test {Webhooks#update} */
it('should update Team Details', function (done) {
var _this3 = this;
this.instance.update(TEST_WEBHOOK_ID, { name: 'new name' }, function (err, response) {
expect(err).to.be.not.ok;
expect(response.options.url).to.be.equal(_this3.instance.apiUrl + '/' + TEST_WEBHOOK_ID);
expect(response.options.json.name).to.be.ok;
expect(response.options.method).to.be.equal('PUT');
done();
});
});
/** @test {Webhooks#delete} */
it('should delete a Team Membership', function (done) {
var _this4 = this;
this.instance.delete(TEST_WEBHOOK_ID, function (err, response) {
expect(err).to.be.not.ok;
expect(response.options.url).to.be.equal(_this4.instance.apiUrl + '/' + TEST_WEBHOOK_ID);
expect(response.options.method).to.be.equal('DELETE');
done();
});
});
});