UNPKG

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