-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-dingtalk.js
99 lines (88 loc) · 1.97 KB
/
test-dingtalk.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict';
const config = require('./config');
const DingTalk = require('../lib').DingTalk;
const should = require('should');
const dingTalk = new DingTalk({
corpId: config.corpId,
secret: config.secret,
agentId: config.agentId,
});
let unionid;
describe('DingTalk', function () {
it('获取前端签名', (done) => {
dingTalk.getSign()
.then(ret => {
should.ok(ret);
should.ok(ret.timeStamp);
should.ok(ret.nonceStr);
should.ok(ret.ticket);
should.ok(ret.signature);
done();
})
.catch(err => {
done(err);
});
});
it('simpleList', (done) => {
const pamras = {
department_id: config.department_id,
};
dingTalk.get('/user/simplelist', pamras, 'userlist')
.then(ret => {
should.ok(ret);
done();
})
.catch(err => {
done(err);
});
});
it('获取成员详情 - /user/get', (done) => {
const pamras = {
userid: config.user_id,
};
dingTalk.get('/user/get', pamras)
.then(ret => {
should.ok(ret);
unionid = ret.unionid;
ret.userid.should.equal(config.user_id);
done();
})
.catch(err => {
done(err);
});
});
it('根据unionid获取成员的userid - /user/getUseridByUnionid', (done) => {
const pamras = {
unionid,
};
dingTalk.get('/user/getUseridByUnionid', pamras, 'userid')
.then(ret => {
should.ok(ret);
ret.should.equal(config.user_id);
done();
})
.catch(err => {
done(err);
});
});
it('发送文字消息', (done) => {
dingTalk.sendText(config.toUsers, new Date().toString())
.then(ret => {
should.ok(ret);
done();
})
.catch(err => {
done(err);
});
});
it('发送链接消息', (done) => {
dingTalk.sendLink(config.toUsers, config.url, 'Hello Yourtion', new Date().toString(), config.img)
.then(ret => {
should.ok(ret);
done();
})
.catch(err => {
done(err);
});
});
});