UNPKG

node-ciscospark

Version:

Super-Simple Lightweight Javascript wrapper for Cisco Spark API

115 lines (100 loc) 3.71 kB
'use strict'; /* 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_PERSON_ID = 12345678; var TEST_EMAIL = 'test@example.com'; /** @test {People} */ describe('CiscoSpark.people', 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.people; }); /** @test {People#list} */ it('should list People in the organisation', function (done) { var _this = this; this.instance.list(TEST_EMAIL, 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.email).to.be.equal(TEST_EMAIL); done(); }); }); /** @test {People#create} */ it('should create a new Person', function (done) { var displayName = 'John Doe'; this.instance.create({ displayName: displayName, emails: [TEST_EMAIL] }, function (err, response) { expect(err).to.be.not.ok; expect(response.options.method).to.be.equal('POST'); expect(response.options.form.emails).to.contains(TEST_EMAIL); expect(response.options.form.displayName).to.be.equal(displayName); done(); }); }); /** @test {People#get} */ it('should get a Person Details', function (done) { var _this2 = this; this.instance.get(TEST_PERSON_ID, function (err, response) { expect(err).to.be.not.ok; expect(response.options.url).to.be.equal(_this2.instance.apiUrl + '/' + TEST_PERSON_ID); expect(response.options.method).to.be.equal('GET'); done(); }); }); /** @test {People#me} */ it('should get my own Details', function (done) { var _this3 = this; this.instance.me(function (err, response) { expect(err).to.be.not.ok; expect(response.options.url).to.be.equal(_this3.instance.apiUrl + '/me'); expect(response.options.method).to.be.equal('GET'); done(); }); }); /** @test {People#update} */ it('should update a Person Details', function (done) { var _this4 = this; this.instance.update(TEST_PERSON_ID, { displayName: 'John Doe' }, function (err, response) { expect(err).to.be.not.ok; expect(response.options.url).to.be.equal(_this4.instance.apiUrl + '/' + TEST_PERSON_ID); expect(response.options.json.displayName).to.be.ok; expect(response.options.method).to.be.equal('PUT'); done(); }); }); /** @test {People#delete} */ it('should delete a Person', function (done) { var _this5 = this; this.instance.delete(TEST_PERSON_ID, function (err, response) { expect(err).to.be.not.ok; expect(response.options.url).to.be.equal(_this5.instance.apiUrl + '/' + TEST_PERSON_ID); expect(response.options.method).to.be.equal('DELETE'); done(); }); }); describe('- Test Errors', function () { /** @test {People#list} */ it('should error when list without details', function (done) { this.instance.list(null, function (err, response) { expect(err).to.be.instanceOf(Error); expect(response).to.be.not.ok; done(); }); }); }); });