describe('MqttHandler', () => { let mqttHandler; beforeEach(() => { mqttHandler = new MqttHandler(gladys, MockedMqttClient, 'faea9c35-759a-44d5-bcc9-2af1de37b8b4'); sinon.reset(); }); it('should have falsy status', () => { expect(mqttHandler.configured).to.eq(false); expect(mqttHandler.connected).to.eq(false); }); it('should have binded topics', async () => { await mqttHandler.init(); expect(Object.keys(mqttHandler.topicBinds)).deep.eq(['gladys/master/#']); assert.callCount(gladys.variable.getValue, 3); assert.calledOnce(MockedMqttClient.internalConnect); expect(mqttHandler.configured).to.eq(true); expect(mqttHandler.connected).to.eq(false); }); });
describe('MqttService', () => { beforeEach(() => { sinon.reset(); }); const mqttService = MqttService(gladys, 'faea9c35-759a-44d5-bcc9-2af1de37b8b4'); it('should start service', async () => { await mqttService.start(); assert.callCount(gladys.variable.getValue, 3); assert.calledOnce(MockedMqttClient.internalConnect); expect(mqttService.device.mqttClient.disconnected).to.eq(false); }); it('should start service while already started', async () => { await mqttService.start(); assert.callCount(gladys.variable.getValue, 3); assert.calledOnce(mqttService.device.mqttClient.internalEnd); assert.calledOnce(MockedMqttClient.internalConnect); expect(mqttService.device.mqttClient.disconnected).to.eq(false); }); it('should stop service', async () => { const { mqttClient } = mqttService.device; mqttService.stop(); assert.calledOnce(mqttClient.internalEnd); expect(mqttService.device.mqttClient).to.eq(null); expect(mqttClient.disconnected).to.eq(true); }); });
const result = await system.restartContainer('my-container'); expect(result).to.be.eq(true);
} catch (e) { assert.notCalled(mqttService.device.publish); expect(e.message).to.eq( 'Tasmota device external_id is invalid: "deviceInvalidTopic" should starts with "tasmota:"', ); } catch (e) { assert.notCalled(mqttService.device.publish); expect(e.message).to.eq('Tasmota device external_id is invalid: "tasmota:" have no MQTT topic');
expect(diskSpace).to.eq(null);
assert.fail('should have fail'); } catch (e) { expect(e).to.be.eq(error); assert.notCalled(execMock.exec); assert.calledOnce(gladys.event.emit);
context('#express fails when missing required field', function() { it('throws error on missing express app and express router', function() { try { testApp.express({}); } catch (er) { return expect(er.message).to.eq('You must specify an express app or an express router to attach to.'); } }); });
context('#express with debug set to true and has empty intents', function() { beforeEach(function() { testApp.intent('emptyIntent'); testApp.express({ expressApp: app, checkCert: false, debug: true }); }); it('returns no utterances', function() { return request(testServer) .get('/testApp?utterances') .expect(200).then(function(response) { expect(response.headers['content-type']).to.equal('text/plain; charset=utf-8'); expect(response.text).to.eq(''); }); }); });
describe("defaults", function() { it("sets persistent session to true", function() { return expect(testApp.persistentSession).to.eq(true); }); return expect(testApp.exhaustiveUtterances).to.eq(false); }); }); return expect(testApp.name).to.eq("testApp"); }); return expect(Alexa.apps["testApp"]).to.eq(testApp); }); }); return expect(Object.keys(CleanAlexaApp.apps).length).to.eq(0); }); });
.expect(200).then(function(response) { expect(response.headers['content-type']).to.equal('text/plain; charset=utf-8'); expect(response.text).to.eq(testApp.schema()); }); });
.expect(200).then(function(response) { expect(response.headers['content-type']).to.equal('text/plain; charset=utf-8'); expect(response.text).to.eq(testApp.schema()); }); }); .expect(200).then(function(response) { expect(response.headers['content-type']).to.equal('text/plain; charset=utf-8'); expect(response.text).to.eq(testApp.schemas.skillBuilder()); }); }); .expect(200).then(function(response) { expect(response.headers['content-type']).to.equal('text/plain; charset=utf-8'); expect(response.text).to.eq(''); }); }); .expect(200).then(function(response) { expect(response.headers['content-type']).to.equal('text/plain; charset=utf-8'); expect(response.text).to.eq(testApp.utterances()); }); });
expected += "testIntent" + " " + "flight delays for {AirportCode}" + "\n"; expected += "testIntent" + " " + "airport delays for {AirportCode}" + "\n"; expect(subject).to.eq(expected); }); });
.send(mockRequest) .expect(200).then(function(response) { return expect(response.body.response.outputSpeech.ssml).to.eq('<speak>Sorry, the application didn\'t know what to do with that intent</speak>'); }); }); }) .expect(200).then(function(response) { return expect(response.body.response.outputSpeech.ssml).to.eq('<speak>Error: not a valid request</speak>'); }); }); .send() .expect(500).then(function(response) { return expect(response.error.text).to.eq('Server Error'); }); });
describe('updateAll', () => { it('updates all records that match criteria', async () => { v.create('foo', 'bar'); v.create('x', { v: 'y' }); v.unlock(); v.updateAll(v => typeof v === 'string', v => `${v}-updated`); expect(await v.get('foo')).to.eq('bar-updated'); expect(await v.get('x')).to.eql({ v: 'y' }); }); });