Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
lab.test('it hydrates roles and caches the results for subsequent access', async () => {
const user = await User.findByUsername('ren');
await user.hydrateRoles();
Code.expect(user._roles).to.be.an.object();
Code.expect(Object.keys(user._roles)).to.have.length(1);
Code.expect(user._roles.admin).to.be.an.instanceOf(Admin);
const roles = await user.hydrateRoles();
Code.expect(user._roles).to.equal(roles);
});
});
lab.test('it parses names into name fields', () => {
const justFirst = Account.nameAdapter('Steve');
Code.expect(justFirst).to.be.an.object();
Code.expect(justFirst.first).to.equal('Steve');
Code.expect(justFirst.middle).to.equal('');
Code.expect(justFirst.last).to.equal('');
const firstAndLast = Account.nameAdapter('Ren Höek');
Code.expect(firstAndLast).to.be.an.object();
Code.expect(firstAndLast.first).to.equal('Ren');
Code.expect(firstAndLast.middle).to.equal('');
Code.expect(firstAndLast.last).to.equal('Höek');
const withMiddle = Account.nameAdapter('Stimpson J Cat');
Code.expect(withMiddle).to.be.an.object();
Code.expect(withMiddle.first).to.equal('Stimpson');
Code.expect(withMiddle.middle).to.equal('J');
Code.expect(withMiddle.last).to.equal('Cat');
});
'use strict';
const Code = require('@hapi/code');
const Lab = require('@hapi/lab');
const Plugin = require('..');
const internals = {};
const { describe, it } = exports.lab = Lab.script();
const expect = Code.expect;
Code.settings.truncateMessages = false;
describe('ESLint Plugin', () => {
it('exposes all expected rules', () => {
expect(Plugin.rules).to.exist();
expect(Plugin.rules).to.be.an.object();
const rules = Object.keys(Plugin.rules);
expect(rules.length).to.equal(5);
expect(rules.includes('capitalize-modules')).to.be.true();
expect(rules.includes('for-loop')).to.be.true();
expect(rules.includes('no-var')).to.be.true();
expect(rules.includes('scope-start')).to.be.true();
handler: request => request.location || 'no-location',
config: {
plugins: { 'hapi-geo-locate': { enabled: false } }
}
}
server.route(routeOptions)
const request = {
url: routeOptions.path,
method: routeOptions.method
}
const response = await server.inject(request)
Code.expect(response.statusCode).to.equal(200)
Code.expect(response.result).to.equal('no-location')
})
})
[publishOptions.routeKey]: async (
consumedMessage,
meta,
ack
) => {
expect(consumedMessage).to.equal(messageString);
expect(meta).to.not.be.a.function();
expect(meta.headers).to.exist();
await ack();
resolve();
}
};
handler: request => request.location,
config: {
plugins: { 'hapi-geo-locate': { enabled: true } }
}
}
server.route(routeOptions)
const request = {
url: routeOptions.path,
method: routeOptions.method
}
const response = await server.inject(request)
Code.expect(response.statusCode).to.equal(200)
Code.expect(Object.keys(response.result)).to.contain(['ip'])
})
})
const documentB = new Admin({
name: Admin.nameAdapter('Ren B Höek'),
groups: {
sales: 'Sales',
support: 'Support'
}
});
const testB1 = await documentB.hasPermissionTo('SPACE_MADNESS');
Code.expect(testB1).to.equal(true);
const testB2 = await documentB.hasPermissionTo('UNTAMED_WORLD');
Code.expect(testB2).to.equal(false);
});
expect(res.result.status).to.equal(true);
expect(res.result.result.email).to.equal('sample2@test.com');
const header = res.headers['set-cookie'];
const yarCookie = header[0].match(/hapi-moon-auth=([^\x00-\x20\"\,\;\\\x7F]*)/);
const res2 = await server.inject({
url: '/user',
method: 'get',
headers: {
cookie: `crumb=${cookie[1]};hapi-moon-auth=${yarCookie[1]}`,
'x-csrf-token': cookie[1]
}
});
expect(res2.statusCode).to.equal(200);
expect(res2.result.email).to.equal('sample2@test.com');
});
const Path = require('path');
const Code = require('@hapi/code');
const ESLint = require('eslint');
const Lab = require('@hapi/lab');
const Config = require('..');
const internals = {};
const { describe, it } = exports.lab = Lab.script();
const expect = Code.expect;
Code.settings.truncateMessages = false;
internals.lintFile = function (file) {
const cli = new ESLint.CLIEngine({
useEslintrc: false,
baseConfig: Config
});
const data = Fs.readFileSync(Path.join(__dirname, file), 'utf8');
return cli.executeOnText(data);
};
describe('eslint-config', () => {
it('has cleared endpoint', () => {
expect(api.config.endpoint).to.equal(null)
})