Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
realWorldAPIs = process.env.APIS.split(/\s+/)
.filter(Boolean)
.map(url => ({
swaggerUrl: url,
name: '',
version: '',
}));
return;
}
// This hook sometimes takes several seconds, due to the large download
// eslint-disable-next-line no-invalid-this
this.timeout(10000);
// Download a list of over 1500 real-world Swagger APIs from apis.guru
const res = await supertest('https://api.apis.guru')
.get('/v2/list.json')
.expect(200);
if (!res.ok) {
throw new Error('Unable to download API listing from apis.guru');
}
// Remove certain APIs that are known to cause problems
const apis = res.body;
// GitHub's CORS policy blocks this request
delete apis['googleapis.com:adsense'];
// These APIs cause infinite loops in json-schema-ref-parser. Still investigating.
// https://github.com/BigstickCarpet/json-schema-ref-parser/issues/56
delete apis['bungie.net'];
delete apis['stripe.com'];
it('parses query without decorated rest query params', async () => {
// This handler responds with the query object (which is expected to
// be parsed by Express)
function requestWithQueryHandler({request, response}: RequestContext) {
response.json(request.query);
response.end();
}
// See https://github.com/strongloop/loopback-next/issues/2088
const server = await givenAServer();
server.handler(requestWithQueryHandler);
await server.start();
await supertest(server.url)
.get('/?x=1&y[a]=2')
.expect(200, {x: '1', y: {a: '2'}});
await server.stop();
});
it('combines both baseUrl and basePath', async () => {
const lbApp = new RestApplication();
lbApp.handler(contextObservingHandler);
lbApp.basePath('/v1'); // set basePath at LoopBack level
const expressApp = express();
expressApp.use('/api', lbApp.requestHandler); // mount the app at baseUrl
await supertest(expressApp)
.get('/api/v1/products')
.expect(200);
expect(observedCtx.basePath).to.equal('/api/v1');
});
export async function setupExpressApplication(): Promise {
const server = new ExpressServer({rest: givenHttpServerConfig()});
await server.boot();
await server.start();
const lbApp = server.lbApp;
const client = supertest('http://127.0.0.1:3000');
return {server, client, lbApp};
}
export async function setupApplication(): Promise {
const app = new ExpressServer({
rest: givenHttpServerConfig(),
});
await app.boot();
await app.start();
const client = supertest(app.url);
return {app, client};
}
it('starts server', async () => {
const serverOptions = givenHttpServerConfig();
server = new HttpServer(dummyRequestHandler, serverOptions);
await server.start();
await supertest(server.url)
.get('/')
.expect(200);
});
it('exports rootUrl property', async () => {
server = await givenAServer();
server.handler(dummyRequestHandler);
expect(server.rootUrl).to.be.undefined();
await server.start();
expect(server)
.to.have.property('rootUrl')
.which.is.a.String()
.match(/http|https\:\/\//);
await supertest(server.rootUrl)
.get('/api')
.expect(200, 'Hello');
});
async function startServerCheck(app: Application) {
const server = await app.getServer(RestServer);
await app.start();
const port = await server.get(RestBindings.PORT);
await supertest(`http://localhost:${port}`)
.get('/')
.expect(200, 'hello world');
await app.stop();
}