1 | import expect = require('expect.js');
|
2 | import request = require('request');
|
3 | import gatewayAgent = require('../lib/index');
|
4 |
|
5 | const appID = 'f1e14d7c';
|
6 | const appKey = 'b5727ac2e89ff44268fd628c12da7d61';
|
7 | const site = 'https://api-sg.kii.com';
|
8 | const ownerToken = 'L_tj-jtSjDNYj1mRtJFKBD3eA5_x68AiFYQswS35TlA';
|
9 | const ownerID = 'ba28b2d34b60-270b-6e11-e3dd-0240f4e2';
|
10 |
|
11 | describe('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,
|
27 | ownerID,
|
28 | 'BABY5',
|
29 | '123123',
|
30 | 'toy',
|
31 | undefined)
|
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,
|
48 | ownerID,
|
49 | 'Donkey',
|
50 | '123123',
|
51 | 'toy',
|
52 | undefined)
|
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,
|
68 | 'th.7c698b427320-f689-6e11-06dd-0d68ad02',
|
69 | {
|
70 | 'batteryAlias': {
|
71 | 'power': true
|
72 | },
|
73 | 'lampAlias': {
|
74 | 'power': true
|
75 | }
|
76 | }
|
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,
|
92 | 'th.7c698b427320-f689-6e11-06dd-0d68ad02',
|
93 | true
|
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 |