-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[http] Expose isKibanaReponse helper in public API (#182392)
For some other changes I'm working on, I need to be able to distinguish if a route handler returned a `IKibanaResponse` / `KibanaResponse` object or some other object that needs to be wrapped before being sent back. Rather than duplicating this little helper I want to expose it as part of the public API of `core.http`.
- Loading branch information
1 parent
6f25042
commit 8a52c11
Showing
10 changed files
with
108 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/core/http/core-http-server/src/router/response.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { isKibanaResponse } from './response'; | ||
|
||
describe('isKibanaResponse', () => { | ||
it('expects the status to be a number', () => { | ||
expect( | ||
isKibanaResponse({ | ||
status: 200, | ||
options: {}, | ||
}) | ||
).toEqual(true); | ||
|
||
expect( | ||
isKibanaResponse({ | ||
status: '200', | ||
options: {}, | ||
}) | ||
).toEqual(false); | ||
}); | ||
|
||
it('expects the options to be an object', () => { | ||
expect( | ||
isKibanaResponse({ | ||
status: 200, | ||
options: {}, | ||
}) | ||
).toEqual(true); | ||
|
||
expect( | ||
isKibanaResponse({ | ||
status: 200, | ||
options: [], | ||
}) | ||
).toEqual(false); | ||
expect( | ||
isKibanaResponse({ | ||
status: 200, | ||
options: null, | ||
}) | ||
).toEqual(false); | ||
expect( | ||
isKibanaResponse({ | ||
status: 200, | ||
options: 'a string', | ||
}) | ||
).toEqual(false); | ||
expect( | ||
isKibanaResponse({ | ||
status: 200, | ||
options: new Set(), | ||
}) | ||
).toEqual(false); | ||
expect( | ||
isKibanaResponse({ | ||
status: 200, | ||
options: () => {}, | ||
}) | ||
).toEqual(false); | ||
}); | ||
|
||
it('allows a payload but no other properties', () => { | ||
expect( | ||
isKibanaResponse({ | ||
status: 200, | ||
options: {}, | ||
payload: 'My stuff', | ||
}) | ||
).toEqual(true); | ||
|
||
expect( | ||
isKibanaResponse({ | ||
status: 200, | ||
options: {}, | ||
data: 'Not allowed', | ||
}) | ||
).toEqual(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters