Skip to content

Commit

Permalink
v2.2.0 added unregister
Browse files Browse the repository at this point in the history
  • Loading branch information
sqrtofsaturn committed May 22, 2015
1 parent 008fc00 commit 95a1e6e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
9 changes: 9 additions & 0 deletions index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,13 @@ class Meshblu
return callback new Error(body.error.message) if body?.error?
callback null

unregister: (device, callback=->) =>
options = @getDefaultRequestOptions()

@request.del "#{@urlBase}/devices/#{device.uuid}", options, (error, response, body) ->
debug "unregister", error, body
return callback error if error?
return callback new Error(body.error.message) if body?.error?
callback null

module.exports = Meshblu
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meshblu-http",
"version": "2.1.0",
"version": "2.2.0",
"description": "Meshblu HTTP API",
"main": "index.js",
"scripts": {
Expand Down
33 changes: 33 additions & 0 deletions test/index-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,36 @@ describe 'Meshblu', ->

it 'should callback with an error', ->
expect(@error).to.deep.equal new Error

describe '->unregister', ->
beforeEach ->
@request = del: sinon.stub()
@dependencies = request: @request
@sut = new Meshblu {}, @dependencies

describe 'with a device', ->
beforeEach (done) ->
@request.del = sinon.stub().yields null, null, null
@sut.unregister {uuid: 'howdy', token: 'sweet'}, (@error) => done()

it 'should not have an error', ->
expect(@error).to.not.exist

it 'should call request.del on the device', ->
expect(@request.del).to.have.been.calledWith 'https://meshblu.octoblu.com:443/devices/howdy'

describe 'with an invalid device', ->
beforeEach (done) ->
@request.del = sinon.stub().yields new Error('unable to delete device'), null, null
@sut.unregister {uuid: 'NOPE', token: 'NO'}, (@error) => done()

it 'should have an error', ->
expect(@error.message).to.equal 'unable to delete device'

describe 'when request returns an error in the body', ->
beforeEach (done) ->
@request.del = sinon.stub().yields null, null, error: new Error('body error')
@sut.unregister {uuid: 'NOPE', token: 'NO'}, (@error) => done()

it 'should have an error', ->
expect(@error.message).to.equal 'body error'

0 comments on commit 95a1e6e

Please sign in to comment.