UNPKG

1.67 kBJavaScriptView Raw
1
2/**
3 * Copyright (c) 2020, salesforce.com, inc.
4 * All rights reserved.
5 * Licensed under the BSD 3-Clause license.
6 * For full license text, see LICENSE.txt file in the repo root or
7 * https://opensource.org/licenses/BSD-3-Clause
8 */
9
10const expect = require('chai').expect;
11const config = { refocusUrl: 'zzz', token: 'dummy' };
12const bdk = require('../refocus-bdk-server')(config);
13const generic = require('../generic');
14const sinon = require('sinon');
15
16const room = {
17 'body': {
18 'id': 2,
19 'name': 'testRoom',
20 'origin': 'other',
21 'active': false,
22 'bots': [
23 'test-Bot'
24 ],
25 'type': 'e118e6f1-a6d5-4164-9c14-7344c733c3e6'
26 }
27};
28
29describe('getRoomById', () => {
30 let getGenericRoomStub;
31 beforeEach(() => {
32 getGenericRoomStub = sinon.stub(generic, 'get');
33 });
34
35 afterEach(() => {
36 getGenericRoomStub.restore();
37 });
38
39 it('OK if roomId matches response', async () => {
40 getGenericRoomStub.returns(Promise.resolve(room));
41 const roomId = 2;
42 const roomBody = await bdk.getRoomById(roomId);
43 // eslint-disable-next-line no-unused-expressions
44 expect(roomBody).to.not.be.null;
45 });
46
47 it('OK should fail when invalid id', async () => {
48 getGenericRoomStub.returns(Promise.resolve(room));
49 const roomBody = await bdk.getRoomById();
50 // eslint-disable-next-line no-unused-expressions
51 expect(roomBody).to.be.null;
52 });
53
54 it('OK should be null in when request fails', async () => {
55 getGenericRoomStub.returns(Promise.resolve());
56 const roomId = '3';
57 const roomBody = await bdk.getRoomById(roomId);
58 // eslint-disable-next-line no-unused-expressions
59 expect(roomBody).to.be.null;
60 });
61});