UNPKG

1.43 kBJavaScriptView Raw
1const expect = require('chai').expect;
2const rewire = require('rewire');
3const sinon = require('sinon');
4const generic = require('../generic.js');
5const config = { refocusUrl: 'zzz', token: 'dummy' };
6
7global.user = '{"email":"test@test.com"'+
8 ',"id":"Test"}';
9global.window = { document: { }, location: { href: '' } };
10const bdk = rewire('../refocus-bdk-client.js');
11
12describe('getBotId function >', () => {
13 beforeEach(() => {
14
15 });
16 afterEach(() => {
17 generic.get.restore();
18 });
19 it('Ok, botName is defined. Fetches botId', (done) => {
20 const testBotName = 'Dummy-Bot';
21 const expectedId = 1234;
22 sinon.stub(generic, 'get').resolves({ body: [{ id: expectedId }] });
23 bdk.__get__('module.exports')(config)
24 .getBotId(config.refocusUrl, config.token, testBotName)
25 .then((res) => {
26 expect(res).to.equal(expectedId);
27 done();
28 })
29 .catch((err) => {
30 done(err);
31 });
32 });
33
34 it('Ok, botName is not defined. Returns undefined', (done) => {
35 const noBotName = '';
36 const expectedResult = undefined;
37 sinon.stub(generic, 'get').resolves({ body: [] });
38 bdk.__get__('module.exports')(config)
39 .getBotId(config.refocusUrl, config.token, noBotName)
40 .then((res) => {
41 expect(res).to.equal(expectedResult);
42 done();
43 })
44 .catch((err) => {
45 done(err);
46 });
47 });
48});