-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[http] Expose isKibanaReponse helper in public API #182392
Changes from all commits
d68ed31
3d6be53
d1a8d60
824f7dd
c7173de
797ff88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: {}, | ||
Comment on lines
+11
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue having this exposed from the public type package is that we can't even test it against our concrete implementation 😅. However it's probably fine for now, I don't have a better suggestion / place to put it that wouldn't imply create yet another package, so if @jloleysens is fine with the approach, I'm too. |
||
}) | ||
).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); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the most thorough check and would be nice to add unit tests for before making public but overall happy with the idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jloleysens I added some tests in d1a8d60 and made some small changes to the helper to make it a bit more strict, let me know what you think!