Skip to content

Commit

Permalink
fix(surveys): Handle filtering on undefined (#810)
Browse files Browse the repository at this point in the history
* return early for undefined surveys

* move empty array return into getSurveys

* Update src/__tests__/surveys.js

* fix

---------

Co-authored-by: Neil Kakkar <[email protected]>
  • Loading branch information
liyiy and neilkakkar authored Oct 2, 2023
1 parent 471406f commit 93adf1a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/__tests__/surveys.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ describe('surveys', () => {
expect(given.instance._send_request).toHaveBeenCalledTimes(2)
})

it('getSurveys returns empty array if surveys are undefined', () => {
given('surveysResponse', () => ({ status: 0 }))
given.surveys.getSurveys((data) => {
expect(data).toEqual([])
})
})

describe('getActiveMatchingSurveys', () => {
const draftSurvey = {
name: 'draft survey',
Expand Down
2 changes: 1 addition & 1 deletion src/posthog-surveys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class PostHogSurveys {
{},
{ method: 'GET' },
(response) => {
const surveys = response.surveys
const surveys = response.surveys || []
this.instance.persistence?.register({ [SURVEYS]: surveys })
return callback(surveys)
}
Expand Down

0 comments on commit 93adf1a

Please sign in to comment.