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(surveys): Handle filtering on undefined #810

Merged
merged 4 commits into from
Oct 2, 2023
Merged

Conversation

liyiy
Copy link
Contributor

@liyiy liyiy commented Sep 26, 2023

Changes

sentry error link

problem: Filtering on undefined surveys causes an error

Checklist

@github-actions
Copy link

github-actions bot commented Sep 26, 2023

Size Change: -856 B (0%)

Total Size: 708 kB

Filename Size Change
dist/array.full.js 177 kB -214 B (0%)
dist/array.js 118 kB -214 B (0%)
dist/es.js 118 kB -214 B (0%)
dist/module.js 118 kB -214 B (0%)
ℹ️ View Unchanged
Filename Size
dist/recorder-v2.js 95 kB
dist/recorder.js 58.3 kB
dist/surveys.js 23.6 kB

compressed-size-action

@@ -29,6 +29,9 @@ export class PostHogSurveys {

getActiveMatchingSurveys(callback: SurveyCallback, forceReload = false) {
this.getSurveys((surveys) => {
if (!surveys) {
Copy link
Contributor

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 :)

@liyiy liyiy changed the title Handle filtering on undefined surveys fix(surveys): Handle filtering on undefined Sep 26, 2023
@liyiy liyiy requested a review from neilkakkar September 26, 2023 22:53
@@ -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 }))
Copy link
Contributor

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.

Suggested change
given('surveysResponse', () => ({ surveys: undefined }))
given('surveysResponse', () => ({ status: 0 }))

Copy link
Contributor

@neilkakkar neilkakkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@neilkakkar neilkakkar added the bump patch Bump patch version when this PR gets merged label Sep 27, 2023
@liyiy liyiy merged commit 93adf1a into master Oct 2, 2023
@liyiy liyiy deleted the fix-surveys-undefined branch October 2, 2023 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump patch Bump patch version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants