@whook/example
Version:
A basic Whook server
76 lines (70 loc) • 2.1 kB
JavaScript
;
var _authentication = _interopRequireDefault(require("./authentication"));
var _yerror = _interopRequireDefault(require("yerror"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
describe('authentication', () => {
const TOKEN = 'my_secret';
describe('.check()', () => {
describe('with bearer type', () => {
it('should work with a good token', async () => {
const authentication = await (0, _authentication.default)({
TOKEN
});
const result = await authentication.check('bearer', {
hash: TOKEN
});
expect({
result
}).toMatchSnapshot();
});
it('should fail with a bad token', async () => {
const authentication = await (0, _authentication.default)({
TOKEN
});
try {
await authentication.check('bearer', {
hash: 'lol'
});
throw new _yerror.default('E_UNEXPECTED_SUCCESS');
} catch (err) {
expect({
errorCode: err.code,
errorParams: err.params
}).toMatchSnapshot();
}
});
});
describe('with fake type', () => {
it('should work with fakedata', async () => {
const authentication = await (0, _authentication.default)({
TOKEN
});
const result = await authentication.check('fake', {
userId: 1,
scopes: ['user']
});
expect({
result
}).toMatchSnapshot();
});
});
describe('with a bad auth type', () => {
it('should fail', async () => {
const authentication = await (0, _authentication.default)({
TOKEN
});
try {
await authentication.check('yolo', {
hash: 'lol'
});
throw new _yerror.default('E_UNEXPECTED_SUCCESS');
} catch (err) {
expect({
errorCode: err.code,
errorParams: err.params
}).toMatchSnapshot();
}
});
});
});
});