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');
});
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');
});
it('has cleared endpoint', () => {
expect(api.config.endpoint).to.equal(null)
})
it('calls url with delete method', async () => {
clientStub.resolves({
ok: true
})
await api.transport(clientStub).endpoint('some/url').del()
expect(clientStub.firstCall.args[1].method).equals('delete')
})
})
return client.add(5, 7).then((response: number) => {
expect(response).to.equal(12)
})
})