How to use @hapi/code - 10 common examples

To help you get started, we’ve selected a few @hapi/code examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jedireza / frame / test / server / models / user.js View on Github external
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);
    });
});
github jedireza / frame / test / server / models / account.js View on Github external
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');
    });
github hapijs / eslint-plugin-hapi / test / index.js View on Github external
'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();
github futurestudio / hapi-geo-locate / test / plugin-registration-without-config.js View on Github external
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')
  })
})
github xogroup / bunnybus / test / integration.js View on Github external
[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();
                    }
                };
github futurestudio / hapi-geo-locate / test / plugin-registration-disabled-by-default.js View on Github external
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'])
  })
})
github jedireza / frame / test / server / models / admin.js View on Github external
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);
    });
github metoikos / hapi-moon / test / all-routes.js View on Github external
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');
    });
github hapijs / eslint-config-hapi / test / index.js View on Github external
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', () => {
github beyonk-adventures / sapper-httpclient / lib / api / api.spec.js View on Github external
it('has cleared endpoint', () => {
        expect(api.config.endpoint).to.equal(null)
      })

@hapi/code

assertion library

BSD-3-Clause
Latest version published 2 years ago

Package Health Score

59 / 100
Full package analysis

Popular @hapi/code functions