UNPKG

3.15 kBPlain TextView Raw
1import expect = require('expect.js');
2import request = require('request');
3import gatewayAgent = require('../lib/index');
4
5const appID = 'f1e14d7c';
6const appKey = 'b5727ac2e89ff44268fd628c12da7d61';
7const site = 'https://api-sg.kii.com';
8const ownerToken = 'L_tj-jtSjDNYj1mRtJFKBD3eA5_x68AiFYQswS35TlA';
9const ownerID = 'ba28b2d34b60-270b-6e11-e3dd-0240f4e2';
10
11describe('Kii Gateway Agent', () => {
12 describe('.init()', () => {
13 it('should set appID, appKey, site', done => {
14 gatewayAgent.init(appID, appKey, site);
15 expect(gatewayAgent.appID).to.be(appID);
16 expect(gatewayAgent.appKey).to.be(appKey);
17 expect(gatewayAgent.site).to.be(site);
18 done();
19 })
20 });
21
22 describe('.onboardGatewayByOwner()', () => {
23 let result
24 beforeEach(done => {
25 gatewayAgent.onboardGatewayByOwner(
26 ownerToken, // owner token
27 ownerID, //owner userid
28 'BABY5', //gateway vendorThingID
29 '123123', //gateway password
30 'toy', // thing type
31 undefined) // thing properties
32 .then(chainOutput => {
33 result = chainOutput
34 done()
35 })
36 })
37 it('should onboard gateway', () => {
38 expect(result.gatewayInfo.thingID).to.be('th.7c698b427320-f689-6e11-b4dd-0cd49ec9')
39 expect(result.gatewayInfo.mqttEndpoint).to.be.an('object')
40 })
41 });
42
43 describe('.onboardEndnodeByOwner()', () => {
44 let result
45 beforeEach(done => {
46 gatewayAgent.onboardEndnodeByOwner(
47 ownerToken, // owner token
48 ownerID, //owner userid
49 'Donkey', // endnode vendorThingID
50 '123123', // endnode password
51 'toy', // endnode type
52 undefined) // endnode properties
53 .then(chainOutput => {
54 result = chainOutput
55 done()
56 })
57 })
58 it('should onboard end node', () => {
59 expect(result.endNodeThingID).to.be('th.7c698b427320-f689-6e11-06dd-0d68ad02')
60 })
61 });
62
63 describe('.updateEndnodeState()', () => {
64 let result
65 beforeEach(done => {
66 gatewayAgent.updateEndnodeState(
67 ownerToken, // owner token
68 'th.7c698b427320-f689-6e11-06dd-0d68ad02', // endnode vendorThingID
69 {
70 'batteryAlias': {
71 'power': true
72 },
73 'lampAlias': {
74 'power': true
75 }
76 } // endnode states
77 ).then(chainOutput => {
78 result = chainOutput
79 done()
80 })
81 })
82 it('should update endnode states', () => {
83 expect(result).to.be(204);
84 })
85 });
86
87 describe('.updateEndnodeConnectivity()', () => {
88 let result
89 beforeEach(done => {
90 gatewayAgent.updateEndnodeConnectivity(
91 ownerToken, // owner token
92 'th.7c698b427320-f689-6e11-06dd-0d68ad02', // endnode vendorThingID
93 true //online
94 ).then(chainOutput => {
95 result = chainOutput
96 done()
97 })
98 })
99 it('should update endnode connection status', () => {
100 expect(result).to.be(204);
101 })
102 });
103
104 describe('.detectEndnodeOnboardingStatus()', () => {
105 let donkey;
106 let notExistingDonkey;
107 beforeEach(done => {
108 donkey = gatewayAgent.detectEndnodeOnboardingStatus('Donkey');
109 notExistingDonkey = gatewayAgent.detectEndnodeOnboardingStatus('notExistingDonkey');
110 done();
111 })
112 it('should return if endnode is onboarding or not', () => {
113 expect(donkey).to.be(true)
114 expect(notExistingDonkey).to.be(false)
115 })
116 });
117})
\No newline at end of file