-
Notifications
You must be signed in to change notification settings - Fork 138
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(surveys): Handle filtering on undefined #810
Conversation
Size Change: -856 B (0%) Total Size: 708 kB
ℹ️ View Unchanged
|
src/posthog-surveys.ts
Outdated
@@ -29,6 +29,9 @@ export class PostHogSurveys { | |||
|
|||
getActiveMatchingSurveys(callback: SurveyCallback, forceReload = false) { | |||
this.getSurveys((surveys) => { | |||
if (!surveys) { |
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.
Since our end users using the API would face this annoying issue as well, I'd say we should always return an array from getSurveys
, and add a test for this case :)
src/__tests__/surveys.js
Outdated
@@ -101,6 +101,13 @@ describe('surveys', () => { | |||
expect(given.instance._send_request).toHaveBeenCalledTimes(2) | |||
}) | |||
|
|||
it('getSurveys returns empty array if surveys are undefined', () => { | |||
given('surveysResponse', () => ({ surveys: undefined })) |
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.
This occurs when the request errors out, which is why there's nothing in surveys. As in other cases, our API always returns an array.
given('surveysResponse', () => ({ surveys: undefined })) | |
given('surveysResponse', () => ({ status: 0 })) |
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.
🚀
Changes
sentry error link
problem: Filtering on undefined surveys causes an error
Checklist