-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
100 lines (78 loc) · 1.56 KB
/
test.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
100
var assert = require('assert')
var decode = require('partly').Multipart.decode
var nock = require('nock')
var Toolbox = require('./index')
nock.disableNetConnect()
const FIWARE_SERVICE = 'MyService'
const TOKEN = 'token'
const CHAT_ID = 'chat_id'
var contextBroker = nock('http://example.com')
var telegram = nock('https://api.telegram.org')
it('connect blocks', function(done)
{
var expected =
{
attributes:
[
{
name: 'temperature',
type: 'centigrade',
value: 23
},
{
name: 'pressure',
type: 'mmHg',
value: 720
}
],
id: 'Room1',
type: 'Room'
}
//
// Configure fake servers
//
contextBroker.persist().post('/NGSI10/queryContext').reply(200,
{
contextResponses:
[{
contextElement: expected,
statusCode:
{
code: 200,
reasonPhrase: 'OK'
}
}]
})
telegram.post('/bot'+TOKEN+'/sendMessage')
.reply(200, function(uri, requestBody)
{
var boundary = this.req.headers['content-type'].split('=')[1]
var actual = JSON.parse(decode(requestBody, boundary)[1].Body)
assert.deepEqual(actual, expected)
done()
toolbox.close()
return {}
})
//
// Exec test
//
var config =
{
contextBroker:
{
fiwareService: FIWARE_SERVICE,
entities:
{
type: 'Room',
id: 'Room1'
}
},
connectors:
{
type: 'telegram-bot-log-stream',
token: TOKEN,
chat_id: CHAT_ID
}
}
var toolbox = Toolbox(config).on('error', done)
})