1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const expect = require('chai').expect;
|
12 | const rewire = require('rewire');
|
13 | const sinon = require('sinon');
|
14 | const config = { refocusUrl: 'zzz', token: 'dummy',
|
15 | botName: 'test' };
|
16 | const bdkServer = rewire('../refocus-bdk-server.js');
|
17 | const { botActionsArray } = require('./utils');
|
18 | const generic = require('../generic.js');
|
19 |
|
20 |
|
21 | global.user = '{"email":"test@test.com"'+
|
22 | ',"id":"Test"}';
|
23 | global.window = { document: { }, location: { href: '' } };
|
24 | const bdkClient = rewire('../refocus-bdk-client.js');
|
25 |
|
26 | describe('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 |
|
49 | describe('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 | });
|