Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('clears cache if _getValue changes', () => {
const providerSpy = sinon.spy();
class IndexProvider implements Provider {
value() {
return providerSpy();
}
}
const indexBinding = ctx
.bind('index')
.toDynamicValue(spy)
.inScope(BindingScope.SINGLETON);
ctx.getSync(indexBinding.key);
sinon.assert.calledOnce(spy);
spy.resetHistory();
// Singleton
ctx.getSync(indexBinding.key);
it('coerces parameter in query from nested keys to object', async () => {
spy = sinon.spy(MyController.prototype, 'getObjectFromQuery');
await client
.get('/object-from-query')
.query({
'filter[where][id]': 1,
'filter[where][name]': 'Pen',
'filter[where][active]': true,
})
.expect(200);
sinon.assert.calledWithExactly(spy, {
// Notice that numeric and boolean values are converted to strings.
// This is because all values are encoded as strings on URL queries
// and we did not specify any schema in @param.query.object() decorator.
where: {
id: '1',
name: 'Pen',
active: 'true',
it('logs the error', async () => {
const logger = sinon.spy() as LogError & SinonSpy;
const reject = new RejectProvider(logger).value();
reject(contextStub, testError);
await contextStub.result;
sinon.assert.calledWith(logger, testError, 500, contextStub.request);
});
it('coerces parameter in header from string to number', async () => {
spy = sinon.spy(MyController.prototype, 'createNumberFromHeader');
await client.get('/create-number-from-header').set({num: 100});
sinon.assert.calledWithExactly(spy, 100);
});
it('coerces parameter in path from string to number', async () => {
spy = sinon.spy(MyController.prototype, 'createNumberFromPath');
await client.get('/create-number-from-path/100').expect(200);
sinon.assert.calledWithExactly(spy, 100);
});
it('coerces parameter in query from string to number', async () => {
spy = sinon.spy(MyController.prototype, 'createNumberFromQuery');
await client
.get('/create-number-from-query')
.query({num: 100})
.expect(200);
sinon.assert.calledWithExactly(spy, 100);
});
beforeEach(() => {
spy = sinon.spy();
});
export function createLogSpy() {
return sinon.spy(InMemoryLog.prototype, 'add');
}