UNPKG

2.92 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2018, salesforce.com, inc.
3 * All rights reserved.
4 * Licensed under the BSD 3-Clause license.
5 * For full license text, see LICENSE.txt file in the repo root or
6 * https://opensource.org/licenses/BSD-3-Clause
7 */
8/* eslint-disable no-magic-numbers */
9
10const expect = require('chai').expect;
11const rewire = require('rewire');
12const config = { refocusUrl: 'zzz', token: 'dummy' };
13const bdkServer = rewire('../refocus-bdk-server.js');
14const sinon = require('sinon');
15const generic = require('../generic.js');
16
17// Create environment for client code to work
18global.user = '{"email":"test@test.com"}';
19global.window = { document: { }, location: { href: '' } };
20const bdkClient = rewire('../refocus-bdk-client.js');
21
22describe('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
64describe('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});