1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | const expect = require('chai').expect;
|
11 | const rewire = require('rewire');
|
12 | const config = { refocusUrl: 'zzz', token: 'dummy' };
|
13 | const bdkServer = rewire('../refocus-bdk-server.js');
|
14 | const sinon = require('sinon');
|
15 | const generic = require('../generic.js');
|
16 |
|
17 |
|
18 | global.user = '{"email":"test@test.com"}';
|
19 | global.window = { document: { }, location: { href: '' } };
|
20 | const bdkClient = rewire('../refocus-bdk-client.js');
|
21 |
|
22 | describe('BDK Client Events: ', () => {
|
23 | beforeEach(() => {
|
24 | bdkClient.__set__('localStorage', { 'Name': 'User' });
|
25 | });
|
26 |
|
27 | it('Ok, Get Event < Limit', (done) => {
|
28 | const total = 3;
|
29 | sinon.stub(generic, 'get').resolves({ header: { 'x-total-count': total },
|
30 | body: ['test', 'test', 'test'] });
|
31 |
|
32 | bdkClient.__get__('module.exports')(config).getAllEvents('1')
|
33 | .then((res) => {
|
34 | expect(res.length).to.equal(total);
|
35 | }).then(() => generic.get.restore())
|
36 | .then(() => done());
|
37 | });
|
38 |
|
39 | it('Ok, Get Event > Limit', (done) => {
|
40 | const total = 100;
|
41 | sinon.stub(generic, 'get').resolves({ header: { 'x-total-count': total },
|
42 | body: ['test'] });
|
43 | bdkClient.__get__('module.exports')(config).getAllEvents('1')
|
44 | .then((res) => {
|
45 | expect(res.length).to.equal(total);
|
46 | }).then(() => generic.get.restore())
|
47 | .then(() => done());
|
48 | });
|
49 |
|
50 | it('Ok, bulk create sends correctly', (done) => {
|
51 | const arraySize = 2;
|
52 | const returnArray = [{ id: 0 }, { id: 1 }];
|
53 | sinon.stub(generic, 'post').resolves({ returnArray });
|
54 |
|
55 | bdkClient.__get__('module.exports')(config)
|
56 | .bulkCreateEvents([{ 'event1': 1 }, { 'event2': 1 }])
|
57 | .then((res) => {
|
58 | expect(res.returnArray.length).to.equal(arraySize);
|
59 | }).then(() => generic.post.restore())
|
60 | .then(() => done());
|
61 | });
|
62 | });
|
63 |
|
64 | describe('BDK Server Events: ', () => {
|
65 | it('Ok, Get Event < Limit', (done) => {
|
66 | const total = 3;
|
67 | sinon.stub(generic, 'get').resolves({ header: { 'x-total-count': total },
|
68 | body: ['test', 'test', 'test'] });
|
69 |
|
70 | bdkServer.__get__('module.exports')(config).getAllEvents('1')
|
71 | .then((res) => {
|
72 | expect(res.length).to.equal(total);
|
73 | }).then(() => generic.get.restore())
|
74 | .then(() => done());
|
75 | });
|
76 |
|
77 | it('Ok, Get Event > Limit', (done) => {
|
78 | const total = 100;
|
79 | sinon.stub(generic, 'get').resolves({ header: { 'x-total-count': total },
|
80 | body: ['test'] });
|
81 |
|
82 | bdkServer.__get__('module.exports')(config).getAllEvents('1')
|
83 | .then((res) => {
|
84 | expect(res.length).to.equal(total);
|
85 | }).then(() => generic.get.restore())
|
86 | .then(() => done());
|
87 | });
|
88 | });
|