meshblu-core-manager-token
Version:
Meshblu Token Manager
104 lines (79 loc) • 3.78 kB
text/coffeescript
{describe,beforeEach,it,expect} = global
mongojs = require 'mongojs'
Datastore = require 'meshblu-core-datastore'
TokenManager = require '../'
describe 'TokenManager->storeToken', ->
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 {, , }
beforeEach (done) ->
.insert {uuid: 'spiral'}, done
describe 'when called', ->
beforeEach (done) ->
.storeToken { uuid: 'spiral', token: 'abc123' }, (error) =>
done error
describe 'when the record is retrieved', ->
beforeEach (done) ->
.findOne { uuid: 'spiral', hashedToken: 'T/GMBdFNOc9l3uagnYZSwgFfjtp8Vlf6ryltQUEUY1U=' }, (error, ) =>
done error
it 'should not add a root to the datastore', ->
expect(.root).to.not.exist
it 'should add a token to the datastore', ->
expect(.hashedToken).to.equal 'T/GMBdFNOc9l3uagnYZSwgFfjtp8Vlf6ryltQUEUY1U='
it 'should match the generated token', ->
hashedToken = ._hashToken { uuid: 'spiral', token: 'abc123' }
expect(.hashedToken).to.equal hashedToken
describe 'when called and the token already exists', ->
beforeEach (done) ->
.storeToken { uuid: 'spiral', token: 'abc123' }, (error) =>
done error
beforeEach (done) ->
.storeToken { uuid: 'spiral', token: 'abc123' }, (error) =>
done error
describe 'when the record is retrieved', ->
beforeEach (done) ->
.find { uuid: 'spiral', hashedToken: 'T/GMBdFNOc9l3uagnYZSwgFfjtp8Vlf6ryltQUEUY1U=' }, (error, ) =>
done error
it 'should only have one', ->
expect(.length).to.equal 1
describe 'when called with an expiresON', ->
beforeEach (done) ->
= new Date()
.storeToken { uuid: 'spiral', token: 'abc123', }, (error) =>
done error
describe 'when the record is retrieved', ->
beforeEach (done) ->
.findOne { uuid: 'spiral', hashedToken: 'T/GMBdFNOc9l3uagnYZSwgFfjtp8Vlf6ryltQUEUY1U=' }, (error, ) =>
done error
it 'should add a token to the datastore', ->
expect(.hashedToken).to.equal 'T/GMBdFNOc9l3uagnYZSwgFfjtp8Vlf6ryltQUEUY1U='
it 'should not add a root to the datastore', ->
expect(.root).to.not.exist
it 'should add a expiresOn to the datastore', ->
expect(.expiresOn).to.deep.equal
it 'should match the generated token', ->
hashedToken = ._hashToken { uuid: 'spiral', token: 'abc123' }
expect(.hashedToken).to.equal hashedToken
describe 'when called with root: true', ->
beforeEach (done) ->
= new Date()
.storeToken { uuid: 'spiral', token: 'abc123', root: true }, (error) =>
done error
describe 'when the record is retrieved', ->
beforeEach (done) ->
.findOne { uuid: 'spiral', root: true }, (error, ) =>
done error
it 'should add a token to the datastore', ->
expect(.hashedToken).to.equal 'T/GMBdFNOc9l3uagnYZSwgFfjtp8Vlf6ryltQUEUY1U='
it 'should add a root to the datastore', ->
expect(.root).to.be.true
it 'should match the generated token', ->
hashedToken = ._hashToken { uuid: 'spiral', token: 'abc123' }
expect(.hashedToken).to.equal hashedToken