Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('finds "GET /orders, /orders/{id}, /orders/{orderId}/shipments" endpoints', () => {
class TestController {
@get('/orders/{id}')
async getOrderById(@param.path.number('id') id: number): Promise {
return {id};
}
// A path that overlaps with `/orders/{id}`. Please note a different var
// name is used - `{orderId}`
@get('/orders/{orderId}/shipments')
async getShipmentsForOrder(
@param.path.number('orderId') id: number,
): Promise {
return [];
}
// With trailing `/`
@get('/orders/')
async findOrders(): Promise {
return [];
}
it('allows anonymous requests to methods with no decorator', async () => {
class InfoController {
@get('/status')
status() {
return {running: true};
}
}
app.controller(InfoController);
await whenIMakeRequestTo(server)
.get('/status')
.expect(200, {running: true});
});
it('allows anonymous requests to methods with no decorator', async () => {
class InfoController {
@get('/status')
status() {
return {running: true};
}
}
app.controller(InfoController);
await whenIMakeRequestTo(server)
.get('/status')
.expect(200, {running: true});
});
it(`allows anonymous requests to methods with no 'authenticate' decorator`, async () => {
class InfoController {
@get('/status')
status() {
return {running: true};
}
}
app.controller(InfoController); //overriding 'beforeEach(givenControllerInApp);' above
await remainingSetup(ScenarioEnum.WithoutProviders);
await whenIMakeRequestTo(server)
.get('/status')
.expect(200, {running: true});
});
beforeEach(function setupHelloController() {
class HelloController {
@get('/hello')
public async greet(): Promise {
return 'Hello world!';
}
}
givenControllerClass(HelloController);
});
return 'error called';
}
@get('/off')
@log(LOG_LEVEL.OFF)
off() {
return 'off called';
}
@get('/')
@log()
hello(@param.query.string('name') name: string) {
return `hello ${name}`;
}
@get('/nolog')
nolog() {
return 'nolog called';
}
}
app.controller(MyController);
}
return 'info called';
}
@get('/error')
@log(LOG_LEVEL.ERROR)
error() {
return 'error called';
}
@get('/off')
@log(LOG_LEVEL.OFF)
off() {
return 'off called';
}
@get('/')
@log()
hello(@param.query.string('name') name: string) {
return `hello ${name}`;
}
@get('/nolog')
nolog() {
return 'nolog called';
}
}
app.controller(MyController);
}
return 'debug called';
}
@get('/warn')
@log(LOG_LEVEL.WARN)
warn() {
return 'warn called';
}
@get('/info')
@log(LOG_LEVEL.INFO)
info() {
return 'info called';
}
@get('/error')
@log(LOG_LEVEL.ERROR)
error() {
return 'error called';
}
@get('/off')
@log(LOG_LEVEL.OFF)
off() {
return 'off called';
}
@get('/')
@log()
hello(@param.query.string('name') name: string) {
return `hello ${name}`;
}
function createController() {
class MyController {
@get('/debug')
@log(LOG_LEVEL.DEBUG)
debug() {
return 'debug called';
}
@get('/warn')
@log(LOG_LEVEL.WARN)
warn() {
return 'warn called';
}
@get('/info')
@log(LOG_LEVEL.INFO)
info() {
return 'info called';
}
@get('/error')
@log(LOG_LEVEL.ERROR)
error() {
return 'error called';
}
export class HomePageController {
render: TemplateExecutor;
constructor(
@inject(PackageKey) private pkg: PackageInfo,
@inject(RestBindings.Http.RESPONSE) private response: Response,
) {
const html = fs.readFileSync(
path.join(__dirname, '../../../public/index.html.template'),
'utf-8',
);
this.render = template(html);
}
@get('/', {
responses: {
'200': {
description: 'Home Page',
content: {'text/html': {schema: {type: 'string'}}},
},
},
})
homePage() {
const homePage = this.render(this.pkg);
this.response
.status(200)
.contentType('html')
.send(homePage);
}
}