1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | const expect = require('chai').expect;
|
11 | const config = { refocusUrl: 'zzz', token: 'dummy' };
|
12 | const bdk = require('../refocus-bdk-server')(config);
|
13 | const generic = require('../generic');
|
14 | const sinon = require('sinon');
|
15 |
|
16 | const 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 |
|
29 | describe('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 |
|
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 |
|
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 |
|
59 | expect(roomBody).to.be.null;
|
60 | });
|
61 | });
|