Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('logs information at INFO or higher', async () => {
setAppLogToInfo();
const client: Client = createClientForHandler(app.requestHandler);
await client.get('/nolog').expect(200, 'nolog called');
expect(spy.called).to.be.False();
await client.get('/off').expect(200, 'off called');
expect(spy.called).to.be.False();
await client.get('/debug').expect(200, 'debug called');
expect(spy.called).to.be.False();
await client.get('/info').expect(200, 'info called');
sinon.assert.calledWith(spy, infoMatch);
await client.get('/warn').expect(200, 'warn called');
sinon.assert.calledWith(spy, warnMatch);
it('allows cors preflight', async () => {
const server = await givenAServer();
server.handler(dummyRequestHandler);
await createClientForHandler(server.requestHandler)
.options('/')
.expect(204)
.expect('Access-Control-Allow-Origin', '*')
.expect('Access-Control-Allow-Credentials', 'true')
.expect('Access-Control-Max-Age', '86400');
});
it('can add openApiSpec endpoints before express initialization', async () => {
const server = await givenAServer();
server.addOpenApiSpecEndpoint('/custom-openapi.json', {
version: '3.0.0',
format: 'json',
});
const test = createClientForHandler(server.requestHandler);
await test.get('/custom-openapi.json').expect(200);
});
function whenIMakeRequestTo(restServer: RestServer): Client {
return createClientForHandler(restServer.requestHandler);
}
});
function whenIRequest(restServerOrApp: HttpServerLike = server): Client {
return createClientForHandler(restServerOrApp.requestHandler);
}
});
function givenClient() {
client = createClientForHandler(expressApp);
}
});
function whenIMakeRequestTo(restServer: RestServer): Client {
return createClientForHandler(restServer.requestHandler);
}
});
function whenIMakeRequestTo(restServer: RestServer): Client {
return createClientForHandler(restServer.requestHandler);
}
});