UNPKG

2.69 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2018, salesforce.com, inc.
3 * All rights reserved.
4 * Licensed under the BSD 3-Clause license.
5 * For full license text, see LICENSE.txt file in the repo root or
6 * https://opensource.org/licenses/BSD-3-Clause
7 */
8
9const expect = require('chai').expect;
10const sinon = require('sinon');
11const _ = require('lodash');
12const config = { refocusUrl: 'zzz', token: 'dummy' };
13const bdk = require('../refocus-bdk-server')(config);
14const { bot, botWithUI } = require('./utils');
15
16describe('New Bot Installation: ', () => {
17 beforeEach(() => {
18 sinon.stub(bdk, 'installBot');
19 });
20
21 afterEach(() => {
22 bdk.installBot.restore();
23 });
24
25 it('Ok, Bot Installed (No UI)', (done) => {
26 const botWithId = _.clone(bot);
27 botWithId.id = 'botId';
28
29 bdk.installBot.resolves({ body: botWithId });
30
31 bdk.installBot(bot)
32 .then((res) => {
33 const installedBot = res.body;
34 expect(installedBot).to.have.property('id');
35 expect(installedBot.name).to.equal(bot.name);
36 expect(installedBot.url).to.equal(bot.url);
37 expect(installedBot.version).to.equal(bot.version);
38 expect(installedBot.displayName).to.equal(bot.displayName);
39 expect(installedBot.helpUrl).to.equal(bot.helpUrl);
40 expect(installedBot.ownerUrl).to.equal(bot.ownerUrl);
41 expect(installedBot.actions).to.deep.equal(bot.actions);
42 done();
43 })
44 .catch((error) => {
45 done(error);
46 });
47 });
48
49 it('Ok, Bot Installed (With UI)', (done) => {
50 const botWithId = _.clone(botWithUI);
51 botWithId.id = 'botId';
52
53 bdk.installBot.resolves({ body: botWithId });
54
55 bdk.installBot(botWithUI)
56 .then((res) => {
57 const installedBot = res.body;
58 expect(installedBot).to.have.property('id');
59 expect(installedBot).to.have.property('ui');
60 expect(installedBot.name).to.equal(botWithUI.name);
61 expect(installedBot.url).to.equal(botWithUI.url);
62 expect(installedBot.version).to.equal(botWithUI.version);
63 expect(installedBot.actions).to.deep.equal(botWithUI.actions);
64 done();
65 })
66 .catch((error) => {
67 done(error);
68 });
69 });
70
71 it('Fail, Attempt to install the same Bot twice', (done) => {
72 const error = 'duplicate';
73
74 bdk.installBot.rejects(error);
75
76 bdk.installBot(bot)
77 .then(done)
78 .catch((err) => {
79 // err object is returned by sinon
80 if (err.name && (err.name === 'duplicate')) {
81 done();
82 } else if (err === 'duplicate') { // refocus returns string
83 done();
84 } else { // if none of the errors were returned fail test
85 done(err);
86 }
87 });
88 });
89});