Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const Lab = require('@hapi/lab');
const Exiting = require('exiting');
const Manager = require('utils/manager');
const Config = require('config');
const ConfigValidation = require('utils/config-validation');
const Sinon = require('sinon');
const { after, before, beforeEach, describe, expect, it } = (exports.lab = Lab.script());
describe('Manager', () => {
before(() => {
// Silence log messages
Exiting.log = function() {};
});
beforeEach(() => {
Manager.reset();
});
after(() => {
Manager.reset();
});
it('validates configuration', async flags => {
'use strict';
const Bell = require('../..');
const Code = require('@hapi/code');
const Hapi = require('@hapi/hapi');
const Hoek = require('@hapi/hoek');
const Lab = require('@hapi/lab');
const Mock = require('../mock');
const internals = {};
const { describe, it } = exports.lab = Lab.script();
const expect = Code.expect;
describe('google', () => {
it('authenticates with mock', async (flags) => {
const mock = await Mock.v2(flags);
const server = Hapi.server({ host: 'localhost', port: 80 });
await server.register(Bell);
const custom = Bell.providers.google();
Hoek.merge(custom, mock.provider);
const profile = {
sub: '1234567890',
'use strict';
const Util = require('util');
const Hoek = require('@hapi/hoek');
const Lab = require('@hapi/lab');
const Code = require('..');
const internals = {};
const { describe, it } = exports.lab = Lab.script();
describe('count()', () => {
it('returns assertion count', () => {
Code.expect(10).to.be.above(5);
Code.expect('abc').to.be.a.string();
Hoek.assert(Code.count() === 2);
});
});
describe('expect()', () => {
it('validates assertion', () => {
'use strict';
const Bell = require('../..');
const Code = require('@hapi/code');
const Hapi = require('@hapi/hapi');
const Hoek = require('@hapi/hoek');
const Lab = require('@hapi/lab');
const Mock = require('../mock');
const internals = {};
const { describe, it } = exports.lab = Lab.script();
const expect = Code.expect;
describe('bitbucket', () => {
it('authenticates with mock', async (flags) => {
const mock = await Mock.v2(flags);
const server = Hapi.server({ host: 'localhost', port: 80 });
await server.register(Bell);
const custom = Bell.providers.bitbucket();
Hoek.merge(custom, mock.provider);
Mock.override('https://api.bitbucket.org/2.0/user', {
repositories: [{}],
'use strict';
const Code = require('@hapi/code');
const Lab = require('@hapi/lab');
const Joi = require('..');
const internals = {};
const { describe, it } = exports.lab = Lab.script();
const { expect } = Code;
describe('Cache', () => {
describe('schema', () => {
it('caches values', () => {
const schema = Joi.string().pattern(/abc/).cache();
const validate = schema._definition.rules.pattern.validate;
let count = 0;
schema._definition.rules.pattern.validate = function (...args) {
++count;
'use strict';
const Path = require('path');
const Code = require('@hapi/code');
const Handlebars = require('handlebars');
const Hapi = require('@hapi/hapi');
const Lab = require('@hapi/lab');
const Pug = require('pug');
const Vision = require('..');
const internals = {};
const { it, describe } = exports.lab = Lab.script();
const expect = Code.expect;
describe('handler()', () => {
it('handles routes to views', async () => {
const server = Hapi.server();
await server.register(Vision);
server.views({
engines: { html: require('handlebars') },
path: __dirname + '/templates'
});
server.route({ method: 'GET', path: '/{param}', handler: { view: 'valid/handler' } });
const res = await server.inject({ method: 'GET', url: '/hello' });
'use strict';
const Code = require('@hapi/code');
const Hapi = require('@hapi/hapi');
const Schmervice = require('..');
const Lab = require('@hapi/lab');
const { describe, it } = exports.lab = Lab.script();
const expect = Code.expect;
describe('Schmervice', () => {
describe('Service class', () => {
const sleep = (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
it('sets server and options on the instance.', () => {
const service = new Schmervice.Service('server', 'options');
expect(service.server).to.equal('server');
const Code = require('@hapi/code');
const Handlebars = require('handlebars');
const Hapi = require('..');
const Hoek = require('@hapi/hoek');
const Inert = require('@hapi/inert');
const Lab = require('@hapi/lab');
const Vision = require('@hapi/vision');
const Response = require('../lib/response');
const internals = {};
const { describe, it } = exports.lab = Lab.script();
const expect = Code.expect;
describe('Response', () => {
it('returns a response', async () => {
const handler = (request, h) => {
return h.response('text')
.type('text/plain')
.charset('ISO-8859-1')
.ttl(1000)
.header('set-cookie', 'abc=123')
.state('sid', 'abcdefg123456')
.state('other', 'something', { isSecure: true })
'use strict';
const Code = require('@hapi/code');
const Hapi = require('@hapi/hapi');
const Lab = require('@hapi/lab');
const Path = require('path');
const Proxyquire = require('proxyquire');
const lab = exports.lab = Lab.script();
const config = {
mongodb: {
connection: {
uri: process.env.MONGODB_URI || 'mongodb://localhost:27017/',
db: 'hapi-mongo-models-test'
},
options: {}
},
models: [
Path.resolve(__dirname, 'fixtures/dummy-model'),
Path.resolve(__dirname, 'fixtures/noindex-model')
]
};
const stub = {
MongoModels: {}
};
'use strict';
const AdminGroup = require('../../../server/models/admin-group');
const Code = require('@hapi/code');
const Config = require('../../../config');
const Fixtures = require('../fixtures');
const Lab = require('@hapi/lab');
const lab = exports.lab = Lab.script();
const config = Config.get('/hapiMongoModels/mongodb');
lab.experiment('AdminGroup Model', () => {
lab.before(async () => {
await AdminGroup.connect(config.connection, config.options);
await Fixtures.Db.removeAllData();
});
lab.after(async () => {
await Fixtures.Db.removeAllData();