1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | const expect = require('chai').expect;
|
10 | const sinon = require('sinon');
|
11 | const _ = require('lodash');
|
12 | const config = { refocusUrl: 'zzz', token: 'dummy' };
|
13 | const bdk = require('../refocus-bdk-server')(config);
|
14 | const { bot, botWithUI } = require('./utils');
|
15 |
|
16 | describe('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 |
|
80 | if (err.name && (err.name === 'duplicate')) {
|
81 | done();
|
82 | } else if (err === 'duplicate') {
|
83 | done();
|
84 | } else {
|
85 | done(err);
|
86 | }
|
87 | });
|
88 | });
|
89 | });
|