Move device logs pubnub event to config

This commit is contained in:
Juan Cruz Viotti 2014-12-01 09:50:18 -04:00
parent 8f13e9bf44
commit d4b189f785
4 changed files with 26 additions and 1 deletions

View File

@ -32,7 +32,7 @@ exports.logs = (uuid) ->
# all other actions from exiting on completion
pubnub = PubNub.init(resin.config.pubnub)
channel = "device-#{uuid}-logs"
channel = helpers.template(resin.config.events.deviceLogs, { uuid })
pubnub.history
count: LOGS_HISTORY_COUNT

View File

@ -12,3 +12,6 @@ exports.isDeviceUUIDValid = (uuid, callback) ->
return callback?(error) if error?
uuidExists = _.findWhere(devices, { uuid })?
return callback(null, uuidExists)
exports.template = (template, data) ->
return _.template(template, data)

View File

@ -63,3 +63,22 @@ describe 'Helpers:', ->
expect(error).to.not.exist
expect(isValid).to.be.false
done()
describe '#template()', ->
templateString = 'Hello, <%= name %>'
templateData = name: 'John Doe'
it 'should call _.template', ->
templateSpy = sinon.spy(_, 'template')
helpers.template(templateString, templateData)
expect(templateSpy).to.have.been.calledOnce
expect(templateSpy).to.have.been.calledWithExactly(templateString, templateData)
templateSpy.restore()
it 'should correctly compute the result', ->
result = helpers.template(templateString, templateData)
expectedResult = _.template(templateString, templateData)
expect(result).to.equal(expectedResult)

View File

@ -18,6 +18,9 @@ config =
publish_key: 'pub-c-6cbce8db-bfd1-4fdf-a8c8-53671ae2b226'
ssl: true
events:
deviceLogs: 'device-<%= uuid %>-logs'
config.pluginsDirectory = path.join(config.dataPrefix, 'plugins')
config.urls =