From 2fdc30f16d158aeb84aa2270a034265a46292187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 13 May 2019 15:08:30 +0200 Subject: [PATCH] fixup! rework tests and fix express composition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- .../__tests__/acceptance/rest-explorer.acceptance.ts | 10 ++++++---- .../acceptance/rest-explorer.express.acceptance.ts | 12 +++++++----- .../rest-explorer/src/rest-explorer.controller.ts | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/rest-explorer/src/__tests__/acceptance/rest-explorer.acceptance.ts b/packages/rest-explorer/src/__tests__/acceptance/rest-explorer.acceptance.ts index 2501f7be66dc..53c7c011c036 100644 --- a/packages/rest-explorer/src/__tests__/acceptance/rest-explorer.acceptance.ts +++ b/packages/rest-explorer/src/__tests__/acceptance/rest-explorer.acceptance.ts @@ -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'\,/); }); }); diff --git a/packages/rest-explorer/src/__tests__/acceptance/rest-explorer.express.acceptance.ts b/packages/rest-explorer/src/__tests__/acceptance/rest-explorer.express.acceptance.ts index 2b5ac84851c9..97c0a8dbd9b6 100644 --- a/packages/rest-explorer/src/__tests__/acceptance/rest-explorer.express.acceptance.ts +++ b/packages/rest-explorer/src/__tests__/acceptance/rest-explorer.express.acceptance.ts @@ -7,7 +7,6 @@ import {RestApplication, RestServer, RestServerConfig} from '@loopback/rest'; import { Client, createClientForHandler, - expect, givenHttpServerConfig, } from '@loopback/testlab'; import * as express from 'express'; @@ -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( diff --git a/packages/rest-explorer/src/rest-explorer.controller.ts b/packages/rest-explorer/src/rest-explorer.controller.ts index be3ebd91119a..acc67b893407 100644 --- a/packages/rest-explorer/src/rest-explorer.controller.ts +++ b/packages/rest-explorer/src/rest-explorer.controller.ts @@ -53,7 +53,7 @@ export class ExplorerController { } if (rootPath && rootPath !== '/') { - openApiSpecUrl = this.request.baseUrl + openApiSpecUrl; + openApiSpecUrl = rootPath + openApiSpecUrl; } const data = { openApiSpecUrl,