Last active
April 5, 2017 19:05
-
-
Save dasheck0/78a5174d72e6f3f1d84fb5683676cf62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by s.neidig on 15/03/17. | |
*/ | |
const Hemera = require('nats-hemera'); | |
const nats = require('nats'); | |
const HemeraJoi = require('hemera-joi'); | |
const connection = nats.connect('nats://0.0.0.0:4222'); | |
const hemera = new Hemera(connection, { | |
logLevel: config.logLevel, | |
crashOnFatal: false | |
}); | |
hemera.use(HemeraJoi); | |
module.exports = hemera; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by s.neidig on 13/03/17. | |
*/ | |
const hemera = require('./hemera'); | |
const worker = require('./worker'); | |
hemera.ready(() => { | |
hemera.setOption('payloadValidator', 'hemera-joi'); | |
const Joi = hemera.exposition['hemera-joi'].joi; | |
hemera.add({ | |
topic: 'auth', | |
cmd: 'encode', | |
email: Joi.string().required(), | |
password: Joi.string().required() | |
}, (req, next) => { | |
worker.doSomething(req.email, req.password) | |
.then(token => next(null, { token })) | |
.catch(error => next(error)); | |
}); | |
}); | |
module.exports = hemera; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by s.neidig on 13/03/17. | |
*/ | |
process.env.NODE_ENV = 'test'; | |
const expect = require('chai').expect; | |
const timekeeper = require('timekeeper'); | |
const ActStub = require('hemera-testsuite/actStub'); | |
const hemera = require('../hemera'); | |
require('../index'); | |
hemera.ready(() => { | |
describe('auth:encode', () => { | |
describe('result', () => { | |
const actStub = new ActStub(hemera); | |
before((done) => { | |
actStub.stub({ | |
topic: 'user', | |
cmd: 'verify', | |
email: '[email protected]', | |
password: '12345678' | |
}, null, { uuid: 'b561b127-5bde-4889-a65f-32a0da4a41a1' }); | |
done(); | |
}); | |
after(() => { | |
actStub.restore(); | |
}); | |
it('should return a token', (done) => { | |
hemera.act({ | |
topic: 'auth', | |
cmd: 'encode', | |
email: '[email protected]', | |
password: '12345678' | |
}, (error, response) => { | |
expect(error).to.not.exist; | |
expect(response).to.exist; | |
expect(response).to.have.property('token'); | |
expect(response.token).to.be.a('string'); | |
done(); | |
}); | |
}); | |
}); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by s.neidig on 13/03/17. | |
*/ | |
const hemera = require('./hemera'); | |
class Worker { | |
static doSomething(email, password) { | |
return new Promise((resolve, reject) => { | |
hemera.act({ | |
topic: 'user', | |
cmd: 'verify', | |
email: email, | |
password: password | |
}, (error, response) => { | |
if (error) { | |
return reject(error.rootCause); | |
} | |
return resolve('sometoken'); | |
}); | |
}); | |
} | |
} | |
module.exports = Worker; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment