1 | "use strict";
|
2 | var expect = require("expect.js");
|
3 | var gatewayAgent = require("../lib/index");
|
4 | var appID = 'f1e14d7c';
|
5 | var appKey = 'b5727ac2e89ff44268fd628c12da7d61';
|
6 | var site = 'https://api-sg.kii.com';
|
7 | var ownerToken = 'L_tj-jtSjDNYj1mRtJFKBD3eA5_x68AiFYQswS35TlA';
|
8 | var ownerID = 'ba28b2d34b60-270b-6e11-e3dd-0240f4e2';
|
9 | describe('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,
|
23 | ownerID,
|
24 | 'BABY5',
|
25 | '123123',
|
26 | 'toy',
|
27 | undefined)
|
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,
|
42 | ownerID,
|
43 | 'Donkey',
|
44 | '123123',
|
45 | 'toy',
|
46 | undefined)
|
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,
|
60 | 'th.7c698b427320-f689-6e11-06dd-0d68ad02',
|
61 | {
|
62 | 'batteryAlias': {
|
63 | 'power': true
|
64 | },
|
65 | 'lampAlias': {
|
66 | 'power': true
|
67 | }
|
68 | }
|
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,
|
82 | 'th.7c698b427320-f689-6e11-06dd-0d68ad02',
|
83 | true
|
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 | });
|