Skip to content

Commit

Permalink
fixup! rework tests and fix express composition
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
  • Loading branch information
bajtos committed May 13, 2019
1 parent 960518e commit 842415b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ describe('API Explorer (acceptance)', () => {

it('uses correct URLs', async () => {
// static assets (including swagger-ui) honor basePath
const response = await request.get('/api/explorer/').expect(200);
const body = response.body;
// OpenAPI endpoints DO NOT honor basePath
expect(body).to.match(/^\s*url: '\/openapi.json',\s*$/m);
await request
.get('/api/explorer/')
.expect(200)
.expect('content-type', /html/)
// OpenAPI endpoints DO NOT honor basePath
.expect(/url\: '\/openapi\.json'\,/);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {RestApplication, RestServer, RestServerConfig} from '@loopback/rest';
import {
Client,
createClientForHandler,
expect,
givenHttpServerConfig,
} from '@loopback/testlab';
import * as express from 'express';
Expand Down Expand Up @@ -38,10 +37,13 @@ describe('REST Explorer mounted as an express router', () => {

it('honors basePath config', async () => {
server.basePath('/v1');
// static assets (including swagger-ui) honor basePath
const response = await client.get('/api/v1/explorer/').expect(200);
// OpenAPI endpoints DO NOT honor basePath
expect(response.body).to.match(/^\s*url: '\/api\/openapi.json',\s*$/m);
await client
// static assets (including swagger-ui) honor basePath
.get('/api/v1/explorer/')
.expect(200)
.expect('content-type', /html/)
// OpenAPI endpoints DO NOT honor basePath
.expect(/url\: '\/api\/openapi\.json'\,/);
});

async function givenLoopBackApp(
Expand Down
2 changes: 1 addition & 1 deletion packages/rest-explorer/src/rest-explorer.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class ExplorerController {
}

if (rootPath && rootPath !== '/') {
openApiSpecUrl = this.request.baseUrl + openApiSpecUrl;
openApiSpecUrl = rootPath + openApiSpecUrl;
}
const data = {
openApiSpecUrl,
Expand Down

0 comments on commit 842415b

Please sign in to comment.