meshblu-core-manager-token
Version:
Meshblu Token Manager
54 lines (42 loc) • 1.71 kB
text/coffeescript
{describe,beforeEach,it,expect} = global
mongojs = require 'mongojs'
Datastore = require 'meshblu-core-datastore'
TokenManager = require '../'
describe 'TokenManager->removeRootToken', ->
beforeEach (done) ->
= 'im-a-pepper'
= resolve: (uuid, callback) => callback(null, uuid)
database = mongojs 'token-manager-test', ['things']
= new Datastore
database: database
collection: 'things'
database.things.remove done
beforeEach ->
= new TokenManager {, , }
describe 'when there is a root token', ->
beforeEach (done) ->
.insert {uuid: 'spiral', root: true}, done
beforeEach (done) ->
.removeRootToken {uuid: 'spiral'}, (error) =>
done error
it 'should not exist in the database', (done) ->
.findOne {uuid: 'spiral', root: true}, (error, record) =>
return done error if error?
expect(record).to.not.exist
done()
describe 'when there are multiple root tokens', ->
beforeEach (done) ->
.insert [{uuid: 'spiral', root: true}, {uuid: 'spiral', root: true}], done
beforeEach (done) ->
.removeRootToken {uuid: 'spiral'}, (error) =>
done error
it 'should not exist in the database', (done) ->
.findOne {uuid: 'spiral', root: true}, (error, record) =>
return done error if error?
expect(record).to.not.exist
done()
describe 'when there is no root token', ->
beforeEach (done) ->
.removeRootToken {uuid: 'spiral'}, () => done()
it 'should not error', ->
expect().to.not.exist