UNPKG

2.11 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
9/* eslint-disable no-magic-numbers */
10
11const expect = require('chai').expect;
12const rewire = require('rewire');
13const sinon = require('sinon');
14const config = { refocusUrl: 'zzz', token: 'dummy',
15 botName: 'test' };
16const bdkServer = rewire('../refocus-bdk-server.js');
17const { botActionsArray } = require('./utils');
18const generic = require('../generic.js');
19
20// Create environment for client code to work
21global.user = '{"email":"test@test.com"'+
22 ',"id":"Test"}';
23global.window = { document: { }, location: { href: '' } };
24const bdkClient = rewire('../refocus-bdk-client.js');
25
26describe('BDK Client botActions: ', () => {
27 beforeEach(() => {
28 bdkClient.__set__('localStorage', { 'Name': 'User' });
29 });
30
31 it('Ok, createBotAction', (done) => {
32 const postStub = sinon.stub(generic, 'post')
33 .resolves({ body: { isPending: true } });
34 bdkClient.__get__('module.exports')(config, config.botName)
35 .createBotAction({})
36 .then(() => {
37 expect(postStub.firstCall.args[0])
38 .to.equal(config.refocusUrl+'/v1/botActions');
39 expect(postStub.firstCall.args[1].botId).to.equal(config.botName);
40 expect(postStub.firstCall.args[1].userId).to.equal('Test');
41 expect(postStub.firstCall.args[2]).to.equal(config.token);
42 expect(postStub.calledOnce).to.equal(true);
43 }).then(() => generic.post.restore())
44 .then(() => done())
45 .catch((err) => done(err));
46 });
47});
48
49describe('BDK Server botActions: ', () => {
50 it('Ok, getBotActions', (done) => {
51 sinon.stub(generic, 'get')
52 .resolves({ body: botActionsArray });
53
54 bdkServer.__get__('module.exports')(config).getBotActions()
55 .then((res) => {
56 expect(res.body.length).to.equal(botActionsArray.length);
57 }).then(() => generic.get.restore())
58 .then(() => done());
59 });
60});