UNPKG

masterblaster

Version:

Scheduling and componsation system for biodome

75 lines (69 loc) 2.31 kB
var chai = require('chai') , expect = chai.expect , assert = chai.assert , switchDevice = require('../lib/switch') describe('Device switching scheduling', function() { describe('#schedule', function() { it('returns a new TimedDeviceEvent with null options', function() { var s = switchDevice('dummy', 'off'); expect(s.opts.device).to.equal('dummy'); expect(s.opts.scheduledState).to.equal('off'); expect(s.opts.goTime).to.be.null; expect(s.opts.endTime).to.be.null; expect(s.opts.duration).to.be.null; expect(s.opts.endState).to.be.null; expect(s.resolved).to.be.false; }); }); describe('#on', function() { before(function() { s = switchDevice('monkey', 'hungry').on('20:45 on Sunday'); }); it('sets goTime', function() { expect(s.opts.goTime).to.equal('at 20:45 on Sunday'); }); it('is chainable', function() { assert(s instanceof switchDevice.TimedDeviceEvent); }); }); describe('#resolveOptions', function() { before(function() { s = switchDevice('pump', 'on').at('10:15am on Tuesday').until('2:40pm on Tuesday'); s.resolveOptions(); }); it('ensures goTime is parsed', function() { assert(s.parsed.startSchedule instanceof Object); }); it('ensures endTime is parsed', function() { assert(s.parsed.endSchedule instanceof Object); }); }); describe('#until', function() { before(function() { s = switchDevice('monkey', 'hungry').until('2:00am on Thursday', 'foo'); }); it('sets endTime option', function() { assert(s.opts.endTime == 'at 2:00am on Thursday'); }); it('sets endState option', function() { assert(s.opts.endState == 'foo'); }); it('is chainable', function() { assert(s instanceof switchDevice.TimedDeviceEvent); }); }); describe('#for', function() { before(function() { s = switchDevice('monkey', 'hungry').for('12 minutes', 'bar'); }); it('sets duration option', function() { assert(s.opts.duration == '12 minutes'); }); it('sets endState option', function() { assert(s.opts.endState == 'bar'); }); it('is chainable', function() { assert(s instanceof switchDevice.TimedDeviceEvent); }); }); });