chenyc
2025-12-09 545c24c6a711d71b65f3d4e8122fee3837fb1edc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const Buffer = require('buffer').Buffer;
const util = require('util');
const aliyunIot = require('../../lib');
const Device = require('../../lib/device');
const fixtures = require('../fixtures');
 
let gateway;
const sub_device1 = fixtures.sub_device1;
const sub_device2 = fixtures.sub_device2;
 
beforeAll(()=> {
  return new Promise((resolve, reject)=>{
    gateway = aliyunIot.gateway({...fixtures.sdk_gateway1});
    gateway.on('connect', () => {
      resolve();
    });
  })
},3000)
 
afterAll(() => {
  gateway.end();
});
 
describe('device test', () => {
  test('gateway connect linkPlatform should be ok', done => {
    if(gateway.connected){
      done();
    }
  });
 
  test('get topo should not be ok', done => {
    try {
        //网关获子设备 ok, aliyunIot.gateway#getTopo()
        gateway.getTopo(
          (res)=>{
              console.log('>>>>>getTopo',res)
              done();
          }
      );
    } catch (e) { console.error(e)}
  });
 
  test('add topo should not be ok', done => {
    try {
      // 添加topo ok 
      gateway.addTopo(
        [sub_device1,sub_device2],
        (res)=>{
          console.log('>>>>>addTopo',res.message,res.data);
          done();
        }
      );
    } catch (e) { console.error(e)}
  });
 
  test('delete topo should not be ok', done => {
    try {
      // 删除设备ok
      gateway.removeTopo( 
        [sub_device2],
        (res)=>{
            console.log('>>>>>removeTopo')
            console.log(res)
            done();
        }
    );
    } catch (e) { console.error(e)}
  });
 
  
 
});