|
1
|
|
|
'use strict' |
|
2
|
|
|
|
|
3
|
|
|
const chai = require('chai') |
|
4
|
|
|
const expect = chai.expect |
|
5
|
|
|
chai.use(require('chai-integer')) |
|
6
|
|
|
chai.use(require('chai-string')) |
|
7
|
|
|
|
|
8
|
|
|
const configuration = require('../src/configuration.js') |
|
9
|
|
|
const fixtureInput = require('./fixtures/input.json') |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Test behavior |
|
13
|
|
|
* |
|
14
|
|
|
* 1. Test configuration |
|
15
|
|
|
* - source: url, password |
|
16
|
|
|
* - params: payload, topic |
|
17
|
|
|
* 2. Test to send payloads |
|
18
|
|
|
* 3. Test callback to send status |
|
19
|
|
|
*/ |
|
20
|
|
|
describe('configuration', () => { |
|
21
|
|
|
|
|
22
|
|
|
describe('MQTT', () => { |
|
23
|
|
|
let mqttConfig = configuration.mqtt(JSON.parse(JSON.stringify(fixtureInput))) |
|
24
|
|
|
it('has all properties defined', (done) => { |
|
25
|
|
|
expect(mqttConfig.username).to.not.be.undefined |
|
|
|
|
|
|
26
|
|
|
expect(mqttConfig.password).to.not.be.undefined |
|
|
|
|
|
|
27
|
|
|
expect(mqttConfig.port).to.not.be.undefined |
|
|
|
|
|
|
28
|
|
|
expect(mqttConfig.qos).to.not.be.undefined |
|
|
|
|
|
|
29
|
|
|
expect(mqttConfig.will.topic).to.not.be.undefined |
|
|
|
|
|
|
30
|
|
|
expect(mqttConfig.will.payload).to.not.be.undefined |
|
|
|
|
|
|
31
|
|
|
done() |
|
32
|
|
|
}) |
|
33
|
|
|
it('has the username as string', (done) => { |
|
34
|
|
|
expect(mqttConfig.username).to.have.string('yourusername') |
|
35
|
|
|
done() |
|
36
|
|
|
}) |
|
37
|
|
|
it('has the password as string', (done) => { |
|
38
|
|
|
expect(mqttConfig.password).to.have.string('yourpassword') |
|
39
|
|
|
done() |
|
40
|
|
|
}) |
|
41
|
|
|
it('has the port as integer', (done) => { |
|
42
|
|
|
expect(mqttConfig.port).to.be.integer() |
|
43
|
|
|
done() |
|
44
|
|
|
}) |
|
45
|
|
|
it('has the qos as integer', (done) => { |
|
46
|
|
|
expect(mqttConfig.qos).to.be.integer() |
|
47
|
|
|
done() |
|
48
|
|
|
}) |
|
49
|
|
|
}) |
|
50
|
|
|
|
|
51
|
|
|
}) |
|
52
|
|
|
|