Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fix format error when url is not found #87

Merged
merged 1 commit into from
Sep 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -58,6 +58,9 @@ export class ResponseFormatMiddleware extends BuiltInMiddleware<ResponseFormatOp
public async handle(context: KoaContext, next: Next) {
// return to skip the middleware, if disabled
if (!this.enabled) return next();
// TODO: replace the hardcoded api with configurable prefix
// Only handle the path for Vulcan API
if (!context.request.path.startsWith('/api')) return next();

// get supported and request format to use.
const format = checkUsableFormat({
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as sinon from 'ts-sinon';
import { ResponseFormatMiddleware } from '@vulcan-sql/serve/middleware';
import { BaseResponseFormatter } from '@vulcan-sql/serve';
import { BaseResponseFormatter, KoaContext } from '@vulcan-sql/serve';

describe('Test format response middleware', () => {
afterEach(() => {
@@ -218,4 +218,17 @@ describe('Test format response middleware', () => {
});

// TODO: test handle to get context response

it('Test to do nothing with paths which are not start in /api', async () => {
// Arrange
const middleware = new ResponseFormatMiddleware({}, '', []);
const mockContext = sinon.stubInterface<KoaContext>();
mockContext.request.path = '/favicon.ico';
mockContext.response.body = '123';
// Act
await middleware.handle(mockContext, async () => null);

// Assert
expect(mockContext.response.body).toBe('123');
});
});